From 3ec04f385adb35404bfa3a8fe95e2704d9ea9aa8 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Tue, 9 Jun 2020 23:47:42 -0500 Subject: [PATCH] Add example justfile (#639) Add a `examples` directory, for holding example justfiles, along with an example justfile, `examples/pre-commit.just`, that shows ideas for using just with `pre-commit`. --- examples/pre-commit.just | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 examples/pre-commit.just diff --git a/examples/pre-commit.just b/examples/pre-commit.just new file mode 100644 index 0000000..f343dcd --- /dev/null +++ b/examples/pre-commit.just @@ -0,0 +1,59 @@ +# use with https://github.com/casey/just + +# Example combining just + pre-commit +# pre-commit: https://pre-commit.com/ +# > A framework for managing and maintaining +# > multi-language pre-commit hooks. + +# pre-commit brings about encapsulation of your +# most common repo scripting tasks. It is perfectly +# usable without actually setting up precommit hooks. +# If you chose to, this justfiles includes shorthands +# for git commit and amend to keep pre-commit out of +# the way when in flow on a feature branch. + +# uses: https://github.com/tekwizely/pre-commit-golang +# uses: https://github.com/prettier/prettier (pre-commit hook) +# configures: https://www.git-town.com/ (setup receipt) + +# fix auto-fixable lint issues in staged files +fix: + pre-commit run go-returns # fixes all Go lint issues + pre-commit run prettier # fixes all Markdown (& other) lint issues + +# lint most common 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 run go-critic || true # runs gocritic + +# lint all issues in - or due - to staged files: +lint-all: + pre-commit run golangci-lint-mod || true # runs golangci-lint + +# run tests in - or due - to staged files +test: + pre-commit run go-test-mod || true # runs go test + +# commit skipping pre-commit hooks +commit m: + git commit --no-verify -m "{{m}}" + +# amend skipping pre-commit hooks +amend: + git commit --amend --no-verify + +# install/update code automation (prettier, pre-commit, goreturns, lintpack, gocritic, golangci-lint) +install: + npm i -g prettier + curl https://pre-commit.com/install-local.py | python3 - + 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` + git config git-town.code-hosting-driver gitea # setup git-town with gitea + git config git-town.code-hosting-origin-hostname gitea.example.org # setup git-town origin hostname