From d667b3c43144cd50afb1e6a769c7c2ca360edf0a Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Thu, 15 Feb 2024 20:51:52 +0100 Subject: [PATCH] chore: working lefthook dotfile example --- examples/dotfiles/.lefthook.yml | 75 ++++++++++++++++++++------------- knowledge base/lefthook.md | 1 + 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/examples/dotfiles/.lefthook.yml b/examples/dotfiles/.lefthook.yml index f58cbd8..a42f273 100644 --- a/examples/dotfiles/.lefthook.yml +++ b/examples/dotfiles/.lefthook.yml @@ -3,32 +3,49 @@ assert_lefthook_installed: true no_tty: true -# pre-commit: -# parallel: true -# commands: -# eslint: -# glob: "*.{js,ts,jsx,tsx}" -# run: yarn eslint {staged_files} -# rubocop: -# tags: backend style -# glob: "*.rb" -# exclude: '(^|/)(application|routes)\.rb$' -# run: bundle exec rubocop --force-exclusion {all_files} -# govet: -# tags: backend style -# files: git ls-files -m -# glob: "*.go" -# run: go vet {files} -# scripts: -# "hello.js": -# runner: node -# "any.go": -# runner: go run -# pre-push: -# commands: -# packages-audit: -# tags: frontend security -# run: yarn audit -# gems-audit: -# tags: backend security -# run: bundle audit +lint: # name of a (custom in this case) hook + parallel: true # unleash the powaaaaaa!! + commands: + markdownlint: &markdownlint # command id, using some yaml shenanigans here + glob: "*.md" # limit the command to markdown files + run: docker run --rm -v "$PWD:/workdir" 'ghcr.io/igorshubovych/markdownlint-cli:latest' "*.md" + tslint: + files: find $PWD -type f -name "*.ts" + run: >- + docker run --rm -v "$PWD:/code" 'pipelinecomponents/eslint:latest' + eslint $( [[ -e .eslintrc ]] || echo '--no-eslintrc' ) --color {files} + +pre-commit: + parallel: true + commands: + eslint: + glob: "*.{js,ts,jsx,tsx}" + run: yarn eslint {staged_files} + rubocop: + tags: backend style + glob: "*.rb" + exclude: '(^|/)(application|routes)\.rb$' + run: bundle exec rubocop --force-exclusion {all_files} + govet: + tags: backend style + files: git ls-files -m + glob: "*.go" + run: go vet {files} + markdownlint: + <<: *markdownlint # reuse the bits from above … + run: >- # … but change the command to limit the files to work with + docker run --rm -v "$PWD:/workdir" 'ghcr.io/igorshubovych/markdownlint-cli:latest' + {push_files} + scripts: + "hello.js": + runner: node + "any.go": + runner: go run +pre-push: + commands: + packages-audit: + tags: frontend security + run: yarn audit + gems-audit: + tags: backend security + run: bundle audit diff --git a/knowledge base/lefthook.md b/knowledge base/lefthook.md index 2a4fec0..0558b2e 100644 --- a/knowledge base/lefthook.md +++ b/knowledge base/lefthook.md @@ -36,6 +36,7 @@ lefthook add -dv 'commit-msg' # Execute groups of hooks. lefthook run 'pre-push' +lefthook run -v 'lint' --all-files lefthook run 'pre-commit' -n --commands 'lint' --files 'lefthook.yml' # Remove configured hooks from the current git repository.