diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a170f27..d50310b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +default_stages: [push, manual] repos: # ========================================================================== # Golang Pre-Commit Hooks | https://github.com/tekwizely/pre-commit-golang @@ -60,8 +61,11 @@ repos: # Aliases: # Consider adding aliases to longer-named hooks for easier CLI usage. # ========================================================================== - - repo: https://github.com/tekwizely/pre-commit-golang - rev: master + + # - repo: https://github.com/tekwizely/pre-commit-golang + # rev: v0.8.0 + - repo: https://github.com/blaggacao/pre-commit-golang + rev: fix-vendor hooks: # # Go Build @@ -74,6 +78,10 @@ repos: # Go Test # - id: go-test-mod + - id: go-test-repo-mod + alias: go-test-repo-mod-all + always_run: true + stages: [manual] # - id: go-test-pkg # - id: go-test-repo-mod # - id: go-test-repo-pkg @@ -82,6 +90,7 @@ repos: # # - id: go-vet - id: go-vet-mod + alias: go-vet-mod-changed # - id: go-vet-pkg # - id: go-vet-repo-mod # - id: go-vet-repo-pkg @@ -91,10 +100,15 @@ repos: # - id: go-fmt # - id: go-imports # Replaces go-fmt - id: go-returns # Replaces go-imports & go-fmt + - id: go-returns + alias: go-returns-write + stages: [manual] + args: [-w] # # Style Checkers # - id: go-lint + alias: go-lint-changed # - id: go-critic # # GolangCI-Lint @@ -105,11 +119,16 @@ repos: # # - id: golangci-lint - id: golangci-lint-mod + alias: golangci-lint-mod-changed + - id: golangci-lint-repo-mod + alias: golangci-lint-repo-mod-all + always_run: true + stages: [manual] # - id: golangci-lint-pkg # - id: golangci-lint-repo-mod # - id: golangci-lint-repo-pkg - repo: https://github.com/prettier/prettier - rev: "master" + rev: "2.0.5" hooks: - id: prettier diff --git a/justfile b/justfile index 143920f..ad0cc0b 100644 --- a/justfile +++ b/justfile @@ -1,40 +1,42 @@ # use with https://github.com/casey/just +# use pre-commit manual stage +pre-commit-manual := "pre-commit run --hook-stage manual" + # fix auto-fixable lint issues in staged files fix: - FORMAT= pre-commit run go-returns # fixes all Go lint issues - pre-commit run prettier # fixes all Markdown (& other) lint issues + {{ pre-commit-manual }} go-returns-write # fixes all Go lint issues + {{ pre-commit-manual }} prettier # fixes all Markdown (& other) lint issues -# lint most common issues in - or due - to staged files +# lint issues in - or due - to staged files lint: - pre-commit run go-vet-mod || true # runs go vet - pre-commit run go-lint || true # runs golint + {{ pre-commit-manual }} go-vet-mod-changed # first run go vet + {{ pre-commit-manual }} go-lint-changed # then run golint + {{ pre-commit-manual }} golangci-lint-mod-changed # last run golangci-lint -# lint all issues in - or due - to staged files +# lint all issues lint-all: - pre-commit run golangci-lint-mod || true # runs golangci-lint + {{ pre-commit-manual }} golangci-lint-repo-mod-all || true # runs golangci-lint # run tests in - or due - to staged files test: - pre-commit run go-test-mod || true # runs go test + {{ pre-commit-manual }} go-test-repo-mod-all || true # runs go test -# commit skipping pre-commit hooks -commit m: - git commit --no-verify -m "{{m}}" +# push skipping pre-push hooks +push: + git push --no-verify -# amend skipping pre-commit hooks -amend: - git commit --amend --no-verify - -# install/update code automation (prettier, pre-commit, goreturns, lintpack, gocritic, golangci-lint) +# install/update code automation install: - npm i -g prettier curl https://pre-commit.com/install-local.py | python3 - + pre-commit install-hooks + # are NOT (yet) automatically installed + # through https://github.com/tekwizely/pre-commit-golang go get github.com/sqs/goreturns go get github.com/go-lintpack/lintpack/... go get github.com/go-critic/go-critic/... curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.27.0 -# setup/update pre-commit hooks (optional) -setup: - pre-commit install --install-hooks # uninstall: `pre-commit uninstall` +# setup hooks for stage (optional) +setup stage="pre-push": + pre-commit install --hook-type {{ stage }} # uninstall: `pre-commit uninstall`