Skip to content

Add nolintlint linter #740

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

Closed
wants to merge 8 commits into from
Closed

Conversation

ashanbrown
Copy link
Contributor

@ashanbrown ashanbrown commented Sep 25, 2019

This PR adds a linter for nolint directives. The purpose of this linter to enforce an optional rule that nolint directives have a specific linter mentioned and an explanation, which is a requirement at my workplace. It also reports nolint directives that don't match the prescribed format.

I realize this is not an existing, proven linter and not a linter that makes much sense outside of golangci-lint. There is a library at https://github.com/ashanbrown/nolintlint that implements this although it might make sense to roll this into golangci-lint itself if you think it's interesting. Would be happy to chat more about this.

FWIW, the nolintlint linter cannot be skipped with nolint.

@CLAassistant
Copy link

CLAassistant commented Sep 25, 2019

CLA assistant check
All committers have signed the CLA.

@ashanbrown ashanbrown changed the title Add nolintlint directive Add nolintlint linter Sep 25, 2019
@tpounds tpounds added the linter: new Support new linter label Sep 25, 2019
go.mod Outdated
@@ -38,7 +39,9 @@ require (
github.com/ultraware/funlen v0.0.2
github.com/ultraware/whitespace v0.0.3
github.com/valyala/quicktemplate v1.2.0
golang.org/x/tools v0.0.0-20190912215617-3720d1ec3678
golang.org/x/net v0.0.0-20190918130420-a8b05e9114ab // indirect
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these be tidied?

@@ -213,6 +213,7 @@ lll: Reports long lines [fast: true, auto-fix: false]
maligned: Tool to detect Go structs that would take less memory if their fields were sorted [fast: true, auto-fix: false]
misspell: Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
nakedret: Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
nolintlint: Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make these changes to README.tmpl.md and regenerate the README.md from that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that this is automatically generated already from somewhere else. I just ran make README.md to create it, so I think this is right but please let me know if there is some other file I should be changing.

Copy link
Member

Choose a reason for hiding this comment

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

You are right, @ashanbrown, it is expected for README.md to be re-generated after the README.tmpl.md change. The CI checks specifically for that, forbidding outdated README.md.

So it should be OK.

@tpounds
Copy link
Contributor

tpounds commented Sep 25, 2019

@ashanbrown Thanks for the contribution! It looks like the CI build is failing due to a vendor discrepancy. I've also provided a few comments on the change.

@ashanbrown ashanbrown marked this pull request as ready for review September 25, 2019 15:14
@ashanbrown
Copy link
Contributor Author

ashanbrown commented Sep 25, 2019

@tpounds I think I've addressed your concerns. I'm a bit of newb wrt to go.mod so I'm not quite sure what the implications of removing indirect dependencies from go.mod might be. I may be misunderstanding what happened but I think I also had to run go mod vendor in go1.13 to remove the extra vendor files that go mod vendor in go1.12 wanted to add. I also added a few more comments to explain what the nolintlint options do and why we need to skip the nolint check for the nolintlint linter.

Thanks for considering this change. If you're interested, I'd be happy to put up a PR to start enforcing nolintlint on golangci-lint itself, probably starting with requiring a specific linter wherever //nolint is used.

@jirfag
Copy link
Contributor

jirfag commented Sep 30, 2019

Hi, sorry for writing this but I think it should be implemented inside nolint processor. Why:

  1. Only this processor can report about cases when //nolint is set but no issues for this line or function are found
  2. our and your implementations of parsing //nolint can differ

@jirfag jirfag closed this Sep 30, 2019
@ashanbrown
Copy link
Contributor Author

@jirfag That definitely makes sense and was something I was anticipating. I'd be happy to create a PR to move this into golangci-lint itself if you'd welcome that.

@jirfag
Copy link
Contributor

jirfag commented Sep 30, 2019

I'd be happy to merge such improvement, thank you!

@jirfag
Copy link
Contributor

jirfag commented Sep 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter: new Support new linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants