Skip to content
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

Ignore comments and empty lines in excludes files #181

Merged
merged 1 commit into from
Jul 14, 2020

Conversation

mbyio
Copy link
Contributor

@mbyio mbyio commented Jun 30, 2020

I held off integrating errcheck into some projects for a while, because I really didn't want to add more false positives to my linters. The -exclude flag gives me a clean way to run errcheck and have everyone on the team easily use the same ignore settings.

However, if we just add patterns to a file, over time it becomes very difficult to maintain. It isn't always obvious why we want to exclude a certain pattern. Comments and whitespace make it easier to organize the file in large projects.

Comments are also handy when debugging something, because you can temporarily comment something out and see if anything changes.

Note

I wrote this to ignore lines prefixed with //. I'm not certain that's better than # because maybe it could conflict with future pattern recognition features you might add. But, I chose // anyway since that's what Go uses. I think it would make sense to change it, if someone thinks it might be a problem.

@mbyio
Copy link
Contributor Author

mbyio commented Jun 30, 2020

Another feature that would be helpful is if errcheck could let us know if something in the exclude file is never used, so we can automatically remove old patterns. But, I didn't implement that here.

@kisielk
Copy link
Owner

kisielk commented Jun 30, 2020

Looks good at initial glance. I will have a more thorough look soon

The unmatched pattern reporting is a good idea too, I would probably want to put that behind a flag that can be used to audit the pattern file.

Copy link
Collaborator

@echlebek echlebek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a small discrepancy in a test, but LGTM! I tested the change and it appears to work as advertised.

main_test.go Outdated
func TestReadExcludesFailure(t *testing.T) {
_, err := readExcludes("testdata/notafile")
if err == nil {
t.Fatal("expected nil err, got:", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test actually expects non-nil error?

This change gives uses a way to organize and document exclude entries.
This is helpful for large codebases where it isn't obvious why a certain
pattern isn't excluded.
@mbyio
Copy link
Contributor Author

mbyio commented Jul 13, 2020

I pushed a new commit that a) fixed the buggy test and b) eliminates an errcheck error I accidentally introduced.

@echlebek
Copy link
Collaborator

@kisielk did you want hold off on merging this until you have a look?

@kisielk
Copy link
Owner

kisielk commented Jul 14, 2020

Looks good to me.

@kisielk kisielk merged commit 082960c into kisielk:master Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants