diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 00000000000..72f5b7a580e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,4 @@ +* [ ] I have followed the [contributing changes + section](https://github.com/twpayne/chezmoi/blob/master/docs/CONTRIBUTING.md#contributing-changes) + in the [contributing + guide](https://github.com/twpayne/chezmoi/blob/master/docs/CONTRIBUTING.md). \ No newline at end of file diff --git a/.gitignore b/.gitignore index a22de4e4ce0..36bdec3de15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -/*coverage.out -/bin +/bin/gofumports +/bin/golangci-lint /chezmoi /chezmoi.exe /dist \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 3c10ab7d333..75d5c0d5459 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,37 @@ linters: - enable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - gocritic + - godot + - gofmt + - goimports + - golint + - gomodguard + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - misspell + - nakedret + - prealloc + - rowserrcheck + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace disable: - funlen - gochecknoglobals diff --git a/Makefile b/Makefile index 47b03fc6525..79d09c47088 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,44 @@ -.PHONY: smoketest -smoketest: - go run . --version - go test ./... - ./bin/golangci-lint run +GOLANGCI_LINT_VERSION=1.25.0 -all: generate +.PHONY: default +default: generate run test lint format -.PHONY: format -format: - find . -name \*.go | xargs $$(go env GOPATH)/bin/gofumports -w - -.PHONY: generate +.PHONT: generate generate: go generate -.PHONY: install-tools -install-tools: - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- v1.25.0 - ( cd $$(mktemp -d) && go mod init tmp && go get mvdan.cc/gofumpt/gofumports ) +.PHONY: run +run: + go run . --version + +.PHONY: test +test: + go test -race ./... .PHONY: lint -lint: +lint: ensure-golangci-lint ./bin/golangci-lint run +.PHONY: format +format: ensure-gofumports + find . -name \*.go | xargs ./bin/gofumports -w + +.PHONY: ensure-tools +ensure-tools: ensure-gofumports ensure-golangci-lint + +.PHONY: ensure-gofumports +ensure-gofumports: + if [[ ! -x bin/gofumports ]] ; then \ + mkdir -p bin ; \ + ( cd $$(mktemp -d) && go mod init tmp && GOBIN=${PWD}/bin go get mvdan.cc/gofumpt/gofumports ) ; \ + fi + +.PHONY: ensure-golangci-lint +ensure-golangci-lint: + if [[ ! -x bin/golangci-lint ]] || ( ./bin/golangci-lint --version | grep -Fqv "version ${GOLANGCI_LINT_VERSION}" ) ; then \ + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- v${GOLANGCI_LINT_VERSION} ; \ + fi + .PHONY: release release: goreleaser release \ @@ -37,10 +53,6 @@ test-release: --snapshot \ ${GORELEASER_FLAGS} -.PHONY: test -test: - go test -race ./... - .PHONY: update-install.sh update-install.sh: # FIXME install.sh is generated by godownloader, but godownloader is diff --git a/cmd/docs.gen.go b/cmd/docs.gen.go index 3cab3d5b54d..03dd7516899 100644 --- a/cmd/docs.gen.go +++ b/cmd/docs.gen.go @@ -57,9 +57,9 @@ func init() { "setting the environment variable `GO111MODULE=on`.\n" + "\n" + "chezmoi is a standard Go project, using standard Go tooling, with a few extra\n" + - "tools. Install these extra tools with:\n" + + "tools. Ensure that these extra tools are installed with:\n" + "\n" + - " make install-tools\n" + + " make ensure-tools\n" + "\n" + "Build chezmoi:\n" + "\n" + @@ -123,9 +123,8 @@ func init() { " [`gofumports`](https://mvdan.cc/gofumpt/gofumports). You can ensure this by\n" + " running `make format`.\n" + "\n" + - "* The code passes [`go vet`](https://golang.org/cmd/vet/) and\n" + - " [`golangci-lint`](https://github.com/golangci/golangci-lint). You can ensure\n" + - " this by running `make lint`.\n" + + "* The code passes [`golangci-lint`](https://github.com/golangci/golangci-lint).\n" + + " You can ensure this by running `make lint`.\n" + "\n" + "* The commit messages match chezmoi's convention, specifically that they begin\n" + " with a capitalized verb in the imperative and give a short description of what\n" + diff --git a/cmd/root.go b/cmd/root.go index 0b263f1795c..247b53a8403 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -138,7 +138,6 @@ func Execute() { } } -//nolint:interfacer func (c *Config) persistentPreRunRootE(cmd *cobra.Command, args []string) error { if colored, err := strconv.ParseBool(c.Color); err == nil { c.colored = colored diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 9658f867db7..7e33fd699ab 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -21,9 +21,9 @@ chezmoi requires Go 1.13 or later and Go modules enabled. Enable Go modules by setting the environment variable `GO111MODULE=on`. chezmoi is a standard Go project, using standard Go tooling, with a few extra -tools. Install these extra tools with: +tools. Ensure that these extra tools are installed with: - make install-tools + make ensure-tools Build chezmoi: @@ -87,9 +87,8 @@ that: [`gofumports`](https://mvdan.cc/gofumpt/gofumports). You can ensure this by running `make format`. -* The code passes [`go vet`](https://golang.org/cmd/vet/) and - [`golangci-lint`](https://github.com/golangci/golangci-lint). You can ensure - this by running `make lint`. +* The code passes [`golangci-lint`](https://github.com/golangci/golangci-lint). + You can ensure this by running `make lint`. * The commit messages match chezmoi's convention, specifically that they begin with a capitalized verb in the imperative and give a short description of what diff --git a/internal/git/status.go b/internal/git/status.go index 8b9c4e38b4f..f1f989c5b9a 100644 --- a/internal/git/status.go +++ b/internal/git/status.go @@ -74,7 +74,6 @@ type Status struct { Ignored []IgnoredStatus } -//nolint:gochecknoglobals var ( statusPorcelainV2ZOrdinaryRegexp = regexp.MustCompile(`` + `^1 ` +