@@ -16,10 +16,15 @@ SHELL := bash
1616TOPDIR := $(shell git rev-parse --show-toplevel)
1717TMPDIR := $(TOPDIR ) /tmp
1818HUGO_BIN := $(TMPDIR ) /hugo/hugo
19- PY_FILES := $(shell find . -type f -name "* .py" -not -path "./worktrees/* " -not -path "* /.venv/* " -print)
20- SH_FILES := $(shell find hack/ -type f -name "* .sh" -not -path "./worktrees/* " -not -path "* /.venv/* " -print)
21- YAML_FILES := $(shell find . -type f \( -name "* .yml" -o -name "* .yaml" \) -not -path "./.vale/*" -not -path "./docs/themes/hugo-book/.github/*" -not -path "./worktrees/*" -not -path "./vendor/*" -print)
22- MD_FILES := $(shell find . -type f -name "* .md" -not -path "./tmp/* " -not -path "./vendor/* " -not -path "* /.venv/* " -not -path "./.vale/* " -not -path "./docs/themes/* " -not -path "./.git/* " -not -path "./worktrees/* " -print)
19+
20+ # Safe file list helpers using null-delimited output
21+ # Usage: $(call GIT_LS_FILES,<patterns>,<command>)
22+ GIT_LS_FILES = git ls-files -z -- $(1 ) | xargs -0 -r $(2 )
23+ PY_PATTERNS := '*.py' ':!vendor/*'
24+ SH_PATTERNS := 'hack/*.sh' ':!vendor/*'
25+ YAML_PATTERNS := '*.yml' '*.yaml' ':!.vale/*' ':!docs/themes/*' ':!vendor/*'
26+ MD_PATTERNS := '*.md' ':!docs/themes/*' ':!.vale/*' ':!vendor/*'
27+ MD_YAML_PATTERNS := '*.md' '*.yml' '*.yaml' ':!docs/themes/*' ':!.vale/*' ':!vendor/*' ':!tmp/*'
2328
2429ifeq ($(PAC_VERSION ) ,)
2530 PAC_VERSION="$(shell git describe --tags --exact-match 2>/dev/null || echo nightly-`date +'%Y%m%d'`-`git rev-parse --short HEAD`)"
@@ -89,30 +94,30 @@ lint-go: ## runs go linter on all go files
8994 --timeout $(TIMEOUT_UNIT )
9095
9196.PHONY : lint-yaml
92- lint-yaml : ${YAML_FILES} # # runs yamllint on all yaml files
97+ lint-yaml : # # runs yamllint on all yaml files
9398 @echo " Linting yaml files..."
94- @yamllint -c .yamllint $( YAML_FILES )
99+ @$( call GIT_LS_FILES, $( YAML_PATTERNS ) , yamllint -c .yamllint) || true
95100
96101
97102.PHONY : lint-md
98103lint-md : # # runs markdownlint and vale on all markdown files
99104 @echo " Linting markdown files..."
100- @markdownlint $( MD_FILES )
105+ @$( call GIT_LS_FILES, $( MD_PATTERNS ) ,markdownlint) || true
101106 @echo " Grammar check with vale of documentation..."
102107 @vale docs/content --output=line --glob=' *.md'
103108 @echo " CodeSpell on docs content"
104109 @codespell docs/content
105110
106111.PHONY : lint-python
107- lint-python : ${PY_FILES} # # runs pylint on all python files
112+ lint-python : # # runs pylint on all python files
108113 @echo " Linting python files..."
109- @ruff check $( PY_FILES )
110- @ruff format --check $( PY_FILES )
114+ @$( call GIT_LS_FILES, $( PY_PATTERNS ) ,ruff check) || true
115+ @$( call GIT_LS_FILES, $( PY_PATTERNS ) , ruff format --check) || true
111116
112117.PHONY : lint-shell
113- lint-shell : ${SH_FILES} # # runs shellcheck on all python files
118+ lint-shell : # # runs shellcheck on all shell files
114119 @echo " Linting shell script files..."
115- @shellcheck $( SH_FILES )
120+ @$( call GIT_LS_FILES, $( SH_PATTERNS ) ,shellcheck) || true
116121
117122.PHONY : gitlint
118123gitlint : # # Run gitlint
@@ -129,19 +134,21 @@ fix-linters: fix-golangci-lint fix-python-errors fix-markdownlint fix-trailing-s
129134.PHONY : fix-markdownlint
130135fix-markdownlint : # # run markdownlint and fix on all markdown file
131136 @echo " Fixing markdown files..."
132- @markdownlint --fix $( MD_FILES )
137+ @$( call GIT_LS_FILES, $( MD_PATTERNS ) , markdownlint --fix) || true
133138
134139.PHONY : fix-trailing-spaces
135140fix-trailing-spaces : # # remove trailing spaces on all markdown and yaml file
136- @sed --in-place ' s/[[:space:]]\+$$//' $(MD_FILES ) $(YAML_FILES )
137- @[[ -n ` git status --porcelain $( MD_FILES) $( YAML_FILES) ` ]] && { echo " Markdowns and Yaml files has been cleaned 🧹. Cleaned Files: " ; git status --porcelain $( MD_FILES) $( YAML_FILES) ; } || echo " Markdown and YAML are clean ✨"
141+ @$(call GIT_LS_FILES,$(MD_YAML_PATTERNS ) ,sed --in-place 's/[[:space:]]\+$$//' --) || true
142+ @STATUS=$$(git status --porcelain -- $$(git ls-files -- $(MD_YAML_PATTERNS ) ) ) && \
143+ [[ -n " $$ STATUS" ]] && { echo " Markdowns and Yaml files has been cleaned 🧹. Cleaned Files: " ; echo " $$ STATUS" ; } || echo " Markdown and YAML are clean ✨"
138144
139- .PHONE : fix-python-errors
145+ .PHONY : fix-python-errors
140146fix-python-errors : # # fix all python errors generated by ruff
141147 @echo " Fixing python files..."
142- @ruff check --fix $(PY_FILES )
143- @ruff format $(PY_FILES )
144- @[[ -n ` git status --porcelain $( PY_FILES) ` ]] && { echo " Python files has been cleaned 🧹. Cleaned Files: " ; git status --porcelain $( PY_FILES) ; } || echo " Python files are clean ✨"
148+ @$(call GIT_LS_FILES,$(PY_PATTERNS ) ,ruff check --fix) || true
149+ @$(call GIT_LS_FILES,$(PY_PATTERNS ) ,ruff format) || true
150+ @STATUS=$$(git status --porcelain -- $$(git ls-files -- $(PY_PATTERNS ) ) ) && \
151+ [[ -n " $$ STATUS" ]] && { echo " Python files has been cleaned 🧹. Cleaned Files: " ; echo " $$ STATUS" ; } || echo " Python files are clean ✨"
145152
146153.PHONY : fix-golangci-lint
147154fix-golangci-lint : # # run golangci-lint and fix on all go files
@@ -201,5 +208,3 @@ dev-docs: download-hugo ## preview live your docs with hugo
201208.PHONY : clean
202209clean : # # clean build artifacts
203210 rm -fR bin
204-
205-
0 commit comments