-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: new linter exclusions system #5339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f206cfc
chore: fix typos
ldez aa5b944
feat: relative path mode
ldez 155eded
feat: relative path processor
ldez f240662
feat: go plugins path
ldez f7a4448
feat: linter placeholder
ldez 5b89dd4
docs: configuration and JSONSchema
ldez 547e6d2
chore: cleanup SkipFiles and SkipDirs
ldez 11e33d2
chore: merge PathPrefixer into PathPrettifier
ldez 4eaaf86
chore: rename AutogeneratedExclude to GeneratedFileFilter
ldez 815fa1f
chore: rename Nolint to NolintFilter
ldez 243307a
tests: isolate exclusions_generated_file_filter files
ldez 494b94f
tests: isolate nolint_filter files
ldez 1b10ce8
tests: isolate severity files
ldez 22a6282
tests: isolate exclude_rules files
ldez effb675
chore: fix typo
ldez 4d8ac35
refactor: restrict config scope
ldez becbabd
feat: new exclusion configuration
ldez 6f68b64
refactor: new exclusion rules
ldez c31d2e7
refactor: use new option Generated
ldez 3f5b0a3
chore: add v2 TODO
ldez 99da68e
feat: new exclusion paths processor
ldez 9420026
chore: remove unused exclusions
ldez 2236d3d
refactor: replace Exclude processor by ExclusionRules processor
ldez fb63541
tests: neutral file paths for Windows
ldez 5e65d35
refactor: use constants for default exclusions
ldez 5bd5b9b
chore: validate LinterExclusions configuration
ldez 612cbfb
review: fix typo
ldez e375825
feat: add inters.exclusions.paths-except
ldez bd4774b
chore: move comment
ldez a6d1ed7
feat: warning on unused path-except
ldez 28bfdb4
refactor: improve GetBasePath to be more v2 ready
ldez c2f23d6
review
ldez f85fdaf
review
ldez 3faf3af
review
ldez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
type BaseRule struct { | ||
Linters []string | ||
Path string | ||
PathExcept string `mapstructure:"path-except"` | ||
Text string | ||
Source string | ||
|
||
// For compatibility with exclude-use-default/include. | ||
InternalReference string `mapstructure:"-"` | ||
} | ||
|
||
func (b *BaseRule) Validate(minConditionsCount int) error { | ||
if err := validateOptionalRegex(b.Path); err != nil { | ||
return fmt.Errorf("invalid path regex: %w", err) | ||
} | ||
|
||
if err := validateOptionalRegex(b.PathExcept); err != nil { | ||
return fmt.Errorf("invalid path-except regex: %w", err) | ||
} | ||
|
||
if err := validateOptionalRegex(b.Text); err != nil { | ||
return fmt.Errorf("invalid text regex: %w", err) | ||
} | ||
|
||
if err := validateOptionalRegex(b.Source); err != nil { | ||
return fmt.Errorf("invalid source regex: %w", err) | ||
} | ||
|
||
if b.Path != "" && b.PathExcept != "" { | ||
return errors.New("path and path-except should not be set at the same time") | ||
} | ||
|
||
nonBlank := 0 | ||
if len(b.Linters) > 0 { | ||
nonBlank++ | ||
} | ||
|
||
// Filtering by path counts as one condition, regardless how it is done (one or both). | ||
// Otherwise, a rule with Path and PathExcept set would pass validation | ||
// whereas before the introduction of path-except that wouldn't have been precise enough. | ||
if b.Path != "" || b.PathExcept != "" { | ||
nonBlank++ | ||
} | ||
|
||
if b.Text != "" { | ||
nonBlank++ | ||
} | ||
|
||
if b.Source != "" { | ||
nonBlank++ | ||
} | ||
|
||
if nonBlank < minConditionsCount { | ||
return fmt.Errorf("at least %d of (text, source, path[-except], linters) should be set", minConditionsCount) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateOptionalRegex(value string) error { | ||
if value == "" { | ||
return nil | ||
} | ||
|
||
_, err := regexp.Compile(value) | ||
return err | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.