diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1190fe1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# https://editorconfig.org +root = true + +[*] +indent_style = tab +tab_width = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3a5fea2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +name: Lint +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +jobs: + golangci-lint: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + - run: echo "GOLANGCI_LINT_VERSION=$(cat .golangci.version)" >> $GITHUB_ENV + - uses: golangci/golangci-lint-action@v6 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + shellcheck: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - run: scripts/shellcheck.sh diff --git a/.golangci.version b/.golangci.version new file mode 100644 index 0000000..be33d89 --- /dev/null +++ b/.golangci.version @@ -0,0 +1 @@ +v1.59.1 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c474367 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,99 @@ +linters: + enable: + - copyloopvar + - intrange + - asasalint + - asciicheck + - bidichk + - bodyclose + - containedctx + - contextcheck + - cyclop + - decorder + - dogsled + - dupl + - dupword + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exportloopref + - forcetypeassert + - funlen + - gci + - ginkgolinter + - gocheckcompilerdirectives + - gochecksumtype + - gocognit + - goconst + - gocritic + - gocyclo + - goheader + - gomodguard + - goprintffuncname + - gosec + - gosimple + - gosmopolitan + - govet + - grouper + - importas + - inamedparam + - ineffassign + - interfacebloat + - ireturn + - lll + - loggercheck + - maintidx + - makezero + - mirror + - musttag + - nakedret + - nestif + - nilerr + - nilnil + - nlreturn + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - paralleltest + - perfsprint + - prealloc + - predeclared + - promlinter + - reassign + - revive + - rowserrcheck + - sloglint + - spancheck + - sqlclosecheck + - staticcheck + - stylecheck + - tagliatelle + - tenv + - testableexamples + - testifylint + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - varnamelen + - wastedassign + - wrapcheck + - wsl + - zerologlint + # https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html + - gochecknoglobals + - gochecknoinits + # use make lint-fix + - gofmt + - gofumpt + - goimports + - misspell + - protogetter + - whitespace diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a128d98 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +SHELL := bash +.ONESHELL: +.SHELLFLAGS := -eu -o pipefail -c +MAKEFLAGS += --warn-undefined-variables + +GOLANGCI_LINT_VERSION=$(shell cat .golangci.version) +GOLANGCI_LINT_INSTALL_DIR=$(shell go env GOPATH)/bin + +.PHONY: install-pre-commit-hook +install-pre-commit-hook: + rm -f .git/hooks/pre-commit + cp scripts/pre-commit.sh .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + +.PHONY: install-lint +install-lint: + VERSION=$(GOLANGCI_LINT_VERSION) INSTALL_DIR=$(GOLANGCI_LINT_INSTALL_DIR) scripts/install-lint.sh + +.PHONY: lint +lint: + $(GOLANGCI_LINT_INSTALL_DIR)/golangci-lint run + +.PHONY: lint-fix +lint-fix: + $(GOLANGCI_LINT_INSTALL_DIR)/golangci-lint run --fix + +.PHONY: shellcheck +shellcheck: + scripts/shellcheck.sh + +.PHONY: ci +ci: lint shellcheck diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..70a7fe5 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world!") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0d32ad0 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/anttiharju/golangci-lint-updater + +go 1.22.5 diff --git a/scripts/install-lint.sh b/scripts/install-lint.sh new file mode 100755 index 0000000..f3b7dd7 --- /dev/null +++ b/scripts/install-lint.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +mkdir -p "$INSTALL_DIR" +cd "$INSTALL_DIR" || exit +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . "$VERSION" diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 0000000..41158e7 --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# +# To not be surprised by CI failures. + +make ci diff --git a/scripts/shellcheck.sh b/scripts/shellcheck.sh new file mode 100755 index 0000000..01b9d02 --- /dev/null +++ b/scripts/shellcheck.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +find . -iname "*.sh" -exec shellcheck {} +