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

Allow use of nolint comments if linter configured #133

Merged
merged 7 commits into from Mar 21, 2024

Conversation

pkwarren
Copy link
Member

@pkwarren pkwarren commented Mar 21, 2024

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 alongside 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.

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
Copy link
Member Author

@pkwarren pkwarren Mar 21, 2024

Choose a reason for hiding this comment

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

@bufdev - Confirmed with @rodaine that these were the agreed upon standards for projects that wish to use //nolint comments.

make/go/go.mk Outdated Show resolved Hide resolved
make/go/scripts/checknolintlint.bash Outdated Show resolved Hide resolved
make/go/scripts/checknolintlint.bash Outdated Show resolved Hide resolved
make/go/scripts/checknolintlint.bash Outdated Show resolved Hide resolved
set -euo pipefail

if [[ ! -f .golangci.yml ]]; then
echo "nolintlint not enabled in .golangci.yml" >&2
Copy link
Member

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; \
Copy link
Member

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.

Copy link
Member

@bufdev bufdev left a 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

@pkwarren pkwarren merged commit 1b2d34a into main Mar 21, 2024
3 checks passed
@pkwarren pkwarren deleted the pkw/verify-nolintlint branch March 21, 2024 20:03
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.

None yet

3 participants