Skip to content

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

Merged
merged 8 commits into from
Dec 30, 2024

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Dec 29, 2024

An unfortunate branch name resulted in failures when running make fmt/go and consequently make 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 of make fmt/go.

@SasSwart SasSwart requested a review from Emyrk December 30, 2024 09:26
@SasSwart SasSwart marked this pull request as ready for review December 30, 2024 09:27
@SasSwart SasSwart requested a review from mafredri December 30, 2024 09:41
Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

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

LGTM

@SasSwart SasSwart merged commit 6434199 into main Dec 30, 2024
39 checks passed
@SasSwart SasSwart deleted the jjs/fmt-go branch December 30, 2024 09:45
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2024
@@ -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' \;)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member

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 😄.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants