Commit 08c36c6
test: complete Phase 1b linter test coverage - achieve 98.1% coverage (#114)
Add comprehensive test suite for SQL linter functionality with 5 new test files
totaling ~3,850 lines and 220+ test cases. Achieves 98.1% coverage for linter
package, significantly exceeding 70% target (28% over target).
## Test Files Created
### Rule Tests (100% coverage each)
- pkg/linter/rules/whitespace/mixed_indentation_test.go (523 lines, 47 cases)
* Tests L002 rule: mixed tabs/spaces detection and auto-fix
* Covers single-line and file-wide inconsistency detection
* Validates auto-fix converts tabs to 4 spaces
- pkg/linter/rules/whitespace/long_lines_test.go (541 lines, 40+ cases)
* Tests L005 rule: line length enforcement
* Validates comment detection logic (-- and /*)
* Tests custom max-length configuration
* Confirms no auto-fix support (manual refactoring required)
### Core Framework Tests (92.3% coverage)
- pkg/linter/linter_test.go (1,204 lines, 65+ cases)
* Tests New(), Rules(), LintFile(), LintString(), LintFiles(), LintDirectory()
* Tests FormatViolation() and FormatResult() output formatting
* Tests BaseRule implementation and all metadata methods
* Includes mock rules to avoid import cycles
* Comprehensive edge cases: empty files, Unicode, Windows line endings
### Context Tests (100% coverage)
- pkg/linter/context_test.go (549 lines, 35 cases)
* Tests NewContext(), WithTokens(), WithAST()
* Tests GetLine() and GetLineCount() helper methods
* Validates method chaining and fluent API
* Tests cross-platform line ending handling
### CLI Integration Tests (84.5% coverage for lintRun)
- cmd/gosqlx/cmd/lint_test.go (1,025 lines, 40+ cases)
* Tests lint command with all flags: --recursive, --pattern, --auto-fix, --max-length
* Tests stdin input handling and pipe detection
* Tests output formatting and exit code behavior
* Tests auto-fix file permission preservation
* Note: Lower coverage for lintFromStdin (30.3%) due to os.Exit() calls being untestable
## Coverage Results
### Overall Linter Package: 98.1%
- context.go: 100%
- linter.go: 89.5% - 100% (LintString 89.5%, all others 100%)
- rule.go: 100%
- rules/whitespace/trailing_whitespace.go: 100%
- rules/whitespace/mixed_indentation.go: 100%
- rules/whitespace/long_lines.go: 100%
### CLI Coverage: 84.5% (lintRun function)
- createLinter: 100%
- lintRun: 84.5%
- lintFromStdin: 30.3% (limited by os.Exit paths)
## Test Quality Features
✅ All tests use table-driven design with t.Run()
✅ All tests pass with race detection (-race flag)
✅ Comprehensive edge case coverage (empty input, Unicode, cross-platform)
✅ Proper use of t.TempDir() for file I/O tests
✅ Multi-rule integration testing (L001, L002, L005 together)
✅ Realistic SQL examples across all scenarios
✅ Complete validation of violation properties (rule ID, severity, line/column)
## Performance Validation
All tests execute efficiently with race detection:
- pkg/linter/rules/whitespace: 2.632s
- pkg/linter: 1.210s
- cmd/gosqlx/cmd: 1.339s
Total execution time: ~5.2 seconds for 220+ test cases with race detection
Resolves Phase 1b linter test coverage requirement.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Ajit Pratap Singh <ajitpratapsingh@Ajits-Mac-mini.local>
Co-authored-by: Claude <noreply@anthropic.com>1 parent 31b6d2b commit 08c36c6
5 files changed
Lines changed: 3842 additions & 0 deletions
File tree
- cmd/gosqlx/cmd
- pkg/linter
- rules/whitespace
0 commit comments