From b84fffbd9400223dac58852def5cc8ec9c5456e7 Mon Sep 17 00:00:00 2001 From: yuluo-yx Date: Sat, 8 Nov 2025 22:05:03 +0800 Subject: [PATCH] feat: add makefile linter Signed-off-by: yuluo-yx --- .github/workflows/pre-commit.yml | 1 + .pre-commit-config.yaml | 9 +++++++++ Dockerfile.precommit | 3 +++ tools/linter/makefile/checkmake.ini | 2 ++ tools/make/linter.mk | 6 +++++- tools/make/pre-commit.mk | 4 ++-- 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tools/linter/makefile/checkmake.ini diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index e7875cba3..fb134960a 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -50,6 +50,7 @@ jobs: npm install -g markdownlint-cli pip install --user yamllint codespell curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0 + go install github.com/checkmake/checkmake/cmd/checkmake@latest - name: Cache Rust dependencies uses: actions/cache@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b51af0a2..d878685a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,6 +39,15 @@ repos: files: \.go$ pass_filenames: false + - repo: local + hooks: + - id: makefile-lint + name: makefile lint + entry: make mkcheck + language: system + files: \.mk$ + pass_filenames: false + # Markdown specific hooks - repo: local hooks: diff --git a/Dockerfile.precommit b/Dockerfile.precommit index 495378144..4a0012230 100644 --- a/Dockerfile.precommit +++ b/Dockerfile.precommit @@ -35,3 +35,6 @@ RUN pip install --break-system-packages shellcheck-py # Golangci-lint RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0 + +# Makefile Check +RUN go install github.com/checkmake/checkmake/cmd/checkmake@latest diff --git a/tools/linter/makefile/checkmake.ini b/tools/linter/makefile/checkmake.ini new file mode 100644 index 000000000..21fd8e7b9 --- /dev/null +++ b/tools/linter/makefile/checkmake.ini @@ -0,0 +1,2 @@ +[maxbodylength] +maxBodyLength = 8 diff --git a/tools/make/linter.mk b/tools/make/linter.mk index 249d54dac..a2ac6c58d 100644 --- a/tools/make/linter.mk +++ b/tools/make/linter.mk @@ -45,4 +45,8 @@ shellcheck: ## Lint all shell scripts in the project exit 1; \ fi @echo "Running shellcheck with config from tools/linter/shellcheck/.shellcheckrc" - @shellcheck -e SC2155,SC2034,SC1091 $(shell find . -type f -name "*.sh" -not -path "./node_modules/*" -not -path "./website/node_modules/*" -not -path "./dashboard/frontend/node_modules/*" -not -path "./models/*" -not -path "./.venv/*") \ No newline at end of file + @shellcheck -e SC2155,SC2034,SC1091 $(shell find . -type f -name "*.sh" -not -path "./node_modules/*" -not -path "./website/node_modules/*" -not -path "./dashboard/frontend/node_modules/*" -not -path "./models/*" -not -path "./.venv/*") + +mkcheck: ## Lint all Makefiles in the project + @$(LOG_TARGET) + checkmake --config=tools/linter/makefile/checkmake.ini tools/make/**/*.mk diff --git a/tools/make/pre-commit.mk b/tools/make/pre-commit.mk index 7e454752b..e94cc9f14 100644 --- a/tools/make/pre-commit.mk +++ b/tools/make/pre-commit.mk @@ -8,7 +8,7 @@ precommit-install: precommit-check: ## Run pre-commit checks on all relevant files precommit-check: - @FILES=$$(find . -type f \( -name "*.go" -o -name "*.rs" -o -name "*.py" -o -name "*.js" -o -name "*.sh" -o -name "*.md" -o -name "*.yaml" -o -name "*.yml" \) \ + @FILES=$$(find . -type f \( -name "*.go" -o -name "*.rs" -o -name "*.py" -o -name "*.js" -o -name "*.sh" -o -name "*.md" -o -name "*.yaml" -o -name "*.yml" -o -name "*.mk" \) \ ! -path "./target/*" \ ! -path "./candle-binding/target/*" \ ! -path "./website/node_modules/*" \ @@ -24,7 +24,7 @@ precommit-check: echo "Running pre-commit on files: $$FILES"; \ pre-commit run --files $$FILES; \ else \ - echo "No Go, Rust, JavaScript, Shell, Markdown, Yaml, or Python files found to check"; \ + echo "No Go, Rust, JavaScript, Shell, Markdown, Yaml, Makefile,or Python files found to check"; \ fi # Run pre-commit hooks in a Docker container,