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

Add lint.sh to run golanci-lint in 2 stages #2051

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default: build

lint: vendor
@echo "✓ Linting source code with https://golangci-lint.run/ (with --fix)..."
@golangci-lint run --fix ./...
@./lint.sh ./...

lintcheck: vendor
@echo "✓ Linting source code with https://golangci-lint.run/ ..."
Expand Down
9 changes: 9 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
# With golangci-lint, if there are any compliation issues, then formatters' autofix won't be applied.
# https://github.com/golangci/golangci-lint/issues/5257
# However, running goimports first alone will actually fix some of the compilation issues.
# Fixing formatting is also reasonable thing to do.
# For this reason, this script runs golangci-lint in two stages:
golangci-lint run --fix --no-config --disable-all --enable gofumpt,goimports $@
Copy link

@ldez ldez Dec 30, 2024

Choose a reason for hiding this comment

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

@denik I would recommend this:

golangci-lint run --enable-only="gofmt,gofumpt,goimports" --fix

Because this will read the configuration of the formatters but ignore the rest.

Those 3 linters just read the syntax, not the types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Yes, that makes sense. #2056

exec golangci-lint run --fix $@
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work on CI? We don't actually commit anything back, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither lint.sh not "make lint" are called on CI. It uses golangci's github action instead: https://github.com/databricks/cli/blob/main/.github/workflows/push.yml#L75

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we're not even going to modify anything in the worktree, because we don't pass --fix there. If there are any mismatches, they won't be corrected, the check will fail.

Loading