-
Notifications
You must be signed in to change notification settings - Fork 904
chore(Makefile): ensure that make fmt/go only formats go source files #15971
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
Conversation
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.
LGTM
@@ -417,12 +417,14 @@ RESET := $(shell tput sgr0 2>/dev/null) | |||
fmt: fmt/ts fmt/go fmt/terraform fmt/shfmt fmt/prettier | |||
.PHONY: fmt | |||
|
|||
GO_FMT_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go' -exec sh -c 'grep -L "DO NOT EDIT" "{}" 2>/dev/null || true' \;) |
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.
GO_FMT_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go' -exec sh -c 'grep -L "DO NOT EDIT" "{}" 2>/dev/null || true' \;) | |
GO_FMT_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go' -exec sh -c 'grep -L "DO NOT EDIT" {} 2>/dev/null || true' \;) |
{}
is a shell-safe replacement, not supposed to be quoted:
❯ touch 'foo"bar"'
❯ find . -type f -exec sh -c 'grep foo "{}"' \;
grep: ./foobar: No such file or directory
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.
Actually, calling sh
here is the main problem, but quoting {}
should also be avoided 😄.
An unfortunate branch name resulted in failures when running
make fmt/go
and consequentlymake fmt
. fmt should not be run on the .git directory. This PR excludes.git
and anything else that's not a go source file in the currently checked out branch from the consideration ofmake fmt/go
.