Skip to content

Commit

Permalink
Adding scripts to run linting on only modified files (#3192)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored Feb 23, 2023
1 parent e93a467 commit eeaa783
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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

0 comments on commit eeaa783

Please sign in to comment.