Skip to content

Remove unnecessary blank lines in test files #41

@sgaunet

Description

@sgaunet

Problem

The test file internal/app/app_test.go contains unnecessary blank lines (lines 130-131) that serve no purpose and reduce code quality.

Example:

func TestFunction1(t *testing.T) {
    // ... test code ...
}


func TestFunction2(t *testing.T) {  // Two blank lines instead of one
    // ... test code ...
}

Go Code Style Conventions

According to gofmt and Go community conventions:

  • One blank line between top-level declarations (functions, types)
  • No extra blank lines within functions (unless separating logical blocks)

Impact

While trivial, excessive blank lines:

  1. Waste vertical space in code reviews
  2. Reduce code readability by spreading code out
  3. Violate Go formatting conventions
  4. Accumulate over time if not addressed

Proposed Solution

Manual Cleanup

Review and remove extra blank lines:

# Find files with excessive blank lines
grep -n "^$" internal/app/app_test.go | awk -F: '{if(NR>1 && $1==prev+1) print "Line " prev " and " $1; prev=$1}'

Automated Fix with gofmt

gofmt should already handle this, but verify:

# Format code
gofmt -w internal/app/app_test.go

# Or format entire package
gofmt -w internal/app/

Enforce with CI

Add formatting check to CI/CD pipeline:

# In .github/workflows/ci.yml or similar
- name: Check code formatting
  run: |
    if [ -n "$(gofmt -l .)" ]; then
      echo "Code is not formatted. Run 'gofmt -w .'"
      gofmt -l .
      exit 1
    fi

Locations to Check

  1. internal/app/app_test.go:130-131 (confirmed)
  2. Search entire codebase for similar issues:
# Find all Go files with multiple consecutive blank lines
find . -name "*.go" -exec awk '/^$/{blank++; if(blank==2) print FILENAME":"NR; next} {blank=0}' {} \;

Recommended Cleanup Pattern

// Good: One blank line between functions
func TestConnect(t *testing.T) {
    // test code
}

func TestListDatabases(t *testing.T) {
    // test code
}

// Bad: Two blank lines between functions
func TestConnect(t *testing.T) {
    // test code
}


func TestListDatabases(t *testing.T) {
    // test code
}

Related Code Quality Issues

While fixing this, also check for:

  • Trailing whitespace
  • Mixed tabs and spaces
  • Missing newline at end of file
  • Inconsistent indentation

All of these should be caught by gofmt and golangci-lint.

Pre-commit Hook

Consider adding a pre-commit hook to prevent this:

# .git/hooks/pre-commit
#!/bin/bash

# Run gofmt on all staged Go files
for file in $(git diff --cached --name-only --diff-filter=ACM | grep '\.go$'); do
    gofmt -w "$file"
    git add "$file"
done

Impact

  • Severity: TRIVIAL
  • Type: Code Quality
  • Location: internal/app/app_test.go:130-131
  • Benefits: Cleaner code, better adherence to Go conventions

Checklist

  • Remove extra blank lines from app_test.go
  • Run gofmt -w . on entire codebase
  • Search for other files with excessive blank lines
  • Add formatting check to CI pipeline
  • Document code formatting requirements in CONTRIBUTING.md
  • Consider adding pre-commit hook for automatic formatting
  • Configure editor to run gofmt on save

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions