fix: Fix exclude pattern matching bug in errstklint#3
Merged
Conversation
Fixed a critical bug in matchDoubleStarPattern where patterns like **/*.yo.go and **/*.pb.go incorrectly matched files that didn't have those extensions. The issue was that when the last pattern part didn't match, the function would fall through and return true instead of false. Changes: - Return false when last pattern part doesn't match - Return false instead of true at end of loop (empty parts case) - Add comprehensive unit tests for exclude pattern matching - Add regression tests for the specific bug case 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed a critical bug in
matchDoubleStarPatternwhere exclude patterns like**/*.yo.goand**/*.pb.goincorrectly matched files that didn't have those extensions (e.g.,usernotification.gowas being excluded when it shouldn't be).Problem
The linter was not detecting functions missing
defer errstk.Wrap(&err)because files were being incorrectly excluded by the pattern matching logic.Root Cause
In the
matchDoubleStarPatternfunction (analyzer.go:267-314):true(line 313)**/*.yo.goto match any.gofile, not just*.yo.gofilesExample of the Bug
This meant that normal
.gofiles were being excluded from linting when they matched the base directory pattern but not the file extension pattern.Solution
return falsewhen the last pattern part doesn't match (line 304)truetofalsefor the edge case where all parts are empty (line 316)shouldExclude()functionmatchDoubleStarPattern()functionChanges
errstklint/analyzer.go:
return falsewhen last pattern part doesn't matchtruetofalseerrstklint/analyzer_test.go:
TestShouldExcludewith 14 test cases covering various pattern scenariosTestMatchDoubleStarPatternwith 6 test cases including regression testsTesting
All tests pass:
$ go test -v ./errstklint === RUN TestAnalyzer --- PASS: TestAnalyzer (0.14s) === RUN TestShouldExclude --- PASS: TestShouldExclude (0.00s) === RUN TestMatchDoubleStarPattern --- PASS: TestMatchDoubleStarPattern (0.00s) PASSImpact
After this fix:
.gofiles are correctly analyzed*.yo.go,*.pb.go) are correctly excluded**/service/api/**/*.gowork correctly🤖 Generated with Claude Code