-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
lib/ignore: Consistent behaviour for nil *Matcher #4310
Conversation
lib/ignore/ignore.go
Outdated
@@ -125,40 +127,42 @@ func New(fs fs.Filesystem, opts ...Option) *Matcher { | |||
} | |||
|
|||
func (m *Matcher) Load(file string) error { | |||
if m == nil { | |||
return IsNil | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just return nil instead of IsNil everywhere, a nil matcher is a noop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But Load() on a nil matcher is a clear error and should (imho) panic as it's always a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well I'd panic anyway if we just removed a check with a nil pointer dereference.
So the fact that we are doing something implies we want to improve something.
Honestly, wouldn't it be simpler to just have it never check for nils and make sure that it is not nil when used from the |
I should have referenced earlier discussions on this: In a nut-shell: Audrius considers nil-Matcher a valid noop-Matcher, my opinion is/was to consider a nil |
The last commit is the other variant where no nil checks are done, making it "illegal" to use |
I split the unrelated part about .stignore line dedupliation into it's own PR #4350, such that this is now exclusively about the nil business. |
I don't have an opinion on this, so I'll leave to to @calmh |
@st-review merge it lib/ignore: Consistent behaviour for nil *Matcher |
Some exported functions on
*Matcher
check whether it is nil, others don't. This PR adds such check consistently.As the first match determines the result when ignoring, duplicate lines have no effect. Therefore these are now filtered out when parsing the file.