-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ci: add lint meta-task, fix, and pre-commit hook #16815
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| [tools] | ||
| lychee = "0.23.0" | ||
| markdownlint-cli2 = "0.22.0" | ||
| "ubi:google/google-java-format" = "1.34.1" | ||
|
|
||
| [settings] | ||
| # Only install tools explicitly defined in the [tools] section above | ||
|
|
@@ -16,3 +17,38 @@ use_file_shell_for_executable_tasks = true | |
| [tasks."lint:links"] | ||
| description = "Check for broken links in changed files + all local links" | ||
| file = "https://raw.githubusercontent.com/grafana/flint/8a39d96e17327c54974623b252eb5260d67ed68a/tasks/lint/links.sh" # v0.9.1 | ||
|
|
||
| [tasks."lint:java"] | ||
| description = "Check Java formatting and license headers (changed files only)" | ||
| run = """ | ||
| files=$(git diff --name-only --diff-filter=d origin/main...HEAD -- '*.java') | ||
| [ -z "$files" ] && exit 0 | ||
| failed=0 | ||
| for f in $files; do | ||
| if ! head -4 "$f" | grep -q "SPDX-License-Identifier: Apache-2.0"; then | ||
| echo "Missing license header: $f" | ||
| failed=1 | ||
| fi | ||
| done | ||
| google-java-format --dry-run --set-exit-if-changed $files || failed=1 | ||
| exit $failed | ||
| """ | ||
|
|
||
| [tasks.lint] | ||
| description = "Run all lints" | ||
| depends = ["lint:links", "lint:markdown", "lint:java"] | ||
|
|
||
| [tasks."lint:fix"] | ||
| description = "Auto-fix lint issues" | ||
| run = """ | ||
| files=$(git diff --name-only --diff-filter=d origin/main...HEAD -- '*.java') | ||
| [ -n "$files" ] && google-java-format -i $files | ||
| mise run lint:markdown -- --fix | ||
| """ | ||
|
|
||
| [tasks.pre-commit] | ||
| description = "Pre-commit hook: lint changed files" | ||
| depends = ["lint"] | ||
| [tasks."setup:pre-commit-hook"] | ||
| description = "Install git pre-commit hook" | ||
| run = "mise generate git-pre-commit --write --task=pre-commit" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm curious if anyone uses the pre-commit hook? I would find it annoying b/c spotless is so slow on our repo
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's why it's a fast subset - see above
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what I mean is that it doesn't use gradle at all |
||
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.
is this equivalent to running
./gradlew spotlessApply?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.
yes, but only for changed files - spotless has a feature that looks for changed files as well - but it still needs to load the gradle config, so it's not really fast
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.
and it's not doing everything that spotless does - it's a fast subset