Commenting on nolint flags #642
Labels
area: docs
area: nolint
Related to nolint directive and nolintlint
enhancement
New feature or improvement
I've found a behavior and writing style that I'd like to share and include in the project documentation.
I've found that using the
//nolint
flag can be made more useful by supplying comments on the flag itself, which is accomplished (IMO) most easily and readibly on the same line as the flag itself.Consider the following definition of a global variables within my main package:
This is a clear violation of
gochecknoglobals
, but in this case these variables act similarly to (the known exceptions)[https://github.com/leighmcculloch/gochecknoglobals#exceptions] togochecknoglobals
likeversion
. It should be allowed, so I'll flag thevar
block with a//nolint:gochecknoglobals
.I know my reasoning is sound, but will I remember in six weeks? Will the next developer understand? I've always been one to leave verbose annotation in my code. I've found that
golangci-lint
allows the comment to exist on the same line as the flag itself which is IMO the easiest thing to read, e.g.To place the same comment above or below the
//nolint
flag would read as if the comment applied to thevar
block, but being on the same line makes it more clear that it relates to the flag.I like this behavior, and if it's not in violation of the maintainers' best practices I'd like this noted in the project README as to encourage others to leave comments explaining and justifying why areas of code should not be linted.
Obligatory environment information
The text was updated successfully, but these errors were encountered: