-
Notifications
You must be signed in to change notification settings - Fork 14
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
Allow use of nolint comments if linter configured #133
Conversation
Some projects prefer using '//nolint' comments instead of configuring exclusions in the config file. These have the benefit of only disabling the selected linters at the specific place in the code and not across the entire file, they are automatically cleaned up when they no longer apply with 'allow-unused: false', and we can continue to require explanations at call sites along the code failing the lint check. Update makego to call a bash script 'checknolintlint.bash' to verify that the 'nolintlint' linter is enabled and has the standard config. If this script passes, then allow for '//nolint' comments to be used in the source code. If not, continue using the existing '//nolint' detection to fail the build if comments are used.
# allow-unused: false | ||
# allow-no-explanation: [] | ||
# require-explanation: true | ||
# require-specific: true |
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.
set -euo pipefail | ||
|
||
if [[ ! -f .golangci.yml ]]; then | ||
echo "nolintlint not enabled in .golangci.yml" >&2 |
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.
Clarifying my previous comment: my concern is if I don't have a .golangci.yml
, then this script errors. In the context of makego
, I think I should be able to not have a .golangci.yml
file. I would instead exit 0 with no message.
@if grep -r --include "*.go" '//nolint'; then \ | ||
checknonolint: $(YQ) | ||
@if bash $(MAKEGO)/scripts/checknolintlint.bash; then \ | ||
echo 'golangci-lint nolintlint configured' >&2; \ |
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.
If the below is updated, this may not be true. I would remove entirely.
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.
Nvm, this is right
Some projects prefer using
//nolint
comments instead of configuring exclusions in the config file. These have the benefit of only disabling the selected linters at the specific place in the code and not across the entire file, they are automatically cleaned up when they no longer apply withallow-unused: false
, and we can continue to require explanations at call sites alongside the code failing the lint check.Update makego to call a bash script
checknolintlint.bash
to verify that thenolintlint
linter is enabled and has the standard config. If this script passes, then allow for//nolint
comments to be used in the source code. If not, continue using the existing//nolint
detection to fail the build if comments are used.