chore: update pre-commit tooling

This commit is contained in:
David Arnold 2020-06-11 01:05:52 -05:00
parent acde5ca0d6
commit 3edbb44fa3
No known key found for this signature in database
GPG Key ID: 6D6A936E69C59D08
2 changed files with 44 additions and 23 deletions

View File

@ -1,3 +1,4 @@
default_stages: [push, manual]
repos: repos:
# ========================================================================== # ==========================================================================
# Golang Pre-Commit Hooks | https://github.com/tekwizely/pre-commit-golang # Golang Pre-Commit Hooks | https://github.com/tekwizely/pre-commit-golang
@ -60,8 +61,11 @@ repos:
# Aliases: # Aliases:
# Consider adding aliases to longer-named hooks for easier CLI usage. # 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: hooks:
# #
# Go Build # Go Build
@ -74,6 +78,10 @@ repos:
# Go Test # Go Test
# #
- id: go-test-mod - 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-pkg
# - id: go-test-repo-mod # - id: go-test-repo-mod
# - id: go-test-repo-pkg # - id: go-test-repo-pkg
@ -82,6 +90,7 @@ repos:
# #
# - id: go-vet # - id: go-vet
- id: go-vet-mod - id: go-vet-mod
alias: go-vet-mod-changed
# - id: go-vet-pkg # - id: go-vet-pkg
# - id: go-vet-repo-mod # - id: go-vet-repo-mod
# - id: go-vet-repo-pkg # - id: go-vet-repo-pkg
@ -91,10 +100,15 @@ repos:
# - id: go-fmt # - id: go-fmt
# - id: go-imports # Replaces go-fmt # - id: go-imports # Replaces go-fmt
- id: go-returns # Replaces go-imports & go-fmt - id: go-returns # Replaces go-imports & go-fmt
- id: go-returns
alias: go-returns-write
stages: [manual]
args: [-w]
# #
# Style Checkers # Style Checkers
# #
- id: go-lint - id: go-lint
alias: go-lint-changed
# - id: go-critic # - id: go-critic
# #
# GolangCI-Lint # GolangCI-Lint
@ -105,11 +119,16 @@ repos:
# #
# - id: golangci-lint # - id: golangci-lint
- id: golangci-lint-mod - 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-pkg
# - id: golangci-lint-repo-mod # - id: golangci-lint-repo-mod
# - id: golangci-lint-repo-pkg # - id: golangci-lint-repo-pkg
- repo: https://github.com/prettier/prettier - repo: https://github.com/prettier/prettier
rev: "master" rev: "2.0.5"
hooks: hooks:
- id: prettier - id: prettier

View File

@ -1,40 +1,42 @@
# use with https://github.com/casey/just # 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 auto-fixable lint issues in staged files
fix: fix:
FORMAT= pre-commit run go-returns # fixes all Go lint issues {{ pre-commit-manual }} go-returns-write # fixes all Go lint issues
pre-commit run prettier # fixes all Markdown (& other) 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: lint:
pre-commit run go-vet-mod || true # runs go vet {{ pre-commit-manual }} go-vet-mod-changed # first run go vet
pre-commit run go-lint || true # runs golint {{ 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: 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 # run tests in - or due - to staged files
test: 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 # push skipping pre-push hooks
commit m: push:
git commit --no-verify -m "{{m}}" git push --no-verify
# amend skipping pre-commit hooks # install/update code automation
amend:
git commit --amend --no-verify
# install/update code automation (prettier, pre-commit, goreturns, lintpack, gocritic, golangci-lint)
install: install:
npm i -g prettier
curl https://pre-commit.com/install-local.py | python3 - 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/sqs/goreturns
go get github.com/go-lintpack/lintpack/... go get github.com/go-lintpack/lintpack/...
go get github.com/go-critic/go-critic/... 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 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 hooks for stage (optional)
setup: setup stage="pre-push":
pre-commit install --install-hooks # uninstall: `pre-commit uninstall` pre-commit install --hook-type {{ stage }} # uninstall: `pre-commit uninstall`