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 scripts to run linting on only modified files #3192

Merged
merged 1 commit into from
Feb 23, 2023
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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ lint:

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
.PHONY: lint lint-fix

lint-fix-changed:
./scripts/linting/lint-changed-go-files.sh

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./docs/client/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' -not -name '*.pb.gw.go' | xargs gofumpt -w
Expand All @@ -305,6 +307,11 @@ format:
docs-lint:
markdownlint . --fix

docs-lint-changed:
./scripts/linting/lint-changed-md-files.sh

.PHONY: lint lint-fix lint-fix-changed docs-lint docs-lint-changed

###############################################################################
### Protobuf ###
###############################################################################
Expand Down
13 changes: 13 additions & 0 deletions scripts/linting/lint-changed-go-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

# lint_modified_go_files runs the linter only if changes have been made to any go files.
function lint_modified_go_files() {
local go_files="$(git diff --name-only | grep \.go$)"
for f in $go_files; do
golangci-lint run "${f}" --fix --out-format=tab --issues-exit-code=0
done
}

lint_modified_go_files
13 changes: 13 additions & 0 deletions scripts/linting/lint-changed-md-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -euo pipefail

# lint_modified_markdown_files runs the linter only if changes have been made to any md files.
function lint_modified_markdown_files() {
local markdown_files="$(git diff --name-only | grep \.md$)"
for f in $markdown_files; do
markdownlint "${f}" --fix
done
}

lint_modified_markdown_files