From cc993c9bd3a98da9771fdd70cc9061a66fb24914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sedl=C3=A1=C4=8Dek?= Date: Wed, 23 Oct 2024 11:14:33 +0200 Subject: [PATCH] makefile, lint --- .gitignore | 1 + .golangci.yml | 87 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 29 ++++++++++++++++ middleware_test.go | 5 ++- 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d83068 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage.out diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..6544da3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,87 @@ +linters: + # Disable all linters. + disable-all: true + # Enable specific linter + enable: + - errcheck + - gci + - wrapcheck + - ineffassign + - unused + +run: + # Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously. + # If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota. + # Default: the number of logical CPUs in the machine + concurrency: 8 + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 5m + go: '1.22.0' + +output: + # Show statistics per linter. + show-stats: true + # Sort results by the order defined in `sort-order`. + sort-results: true + # Order to use when sorting results. + # Require `sort-results` to `true`. + # Possible values: `file`, `linter`, and `severity`. + # + # If the severity values are inside the following list, they are ordered in this order: + # 1. error + # 2. warning + # 3. high + # 4. medium + # 5. low + # Either they are sorted alphabetically. + sort-order: + - linter + - file + - severity + +issues: + # Maximum issues count per one linter. + # Set to 0 to disable. + # Default: 50 + max-issues-per-linter: 0 + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 0 + exclude-rules: + - linters: + - lll + source: "^//go:generate " + exclude-dirs: + - "tools" + exclude-files: + - ".*\\.gen\\.go$" + - ".*\\.ridl$" + +linters-settings: + errcheck: + # List of functions to exclude from checking, where each entry is a single function to exclude. + # See https://github.com/kisielk/errcheck#excluding-functions for details. + exclude-functions: + - (net/http.ResponseWriter).Write + + gci: + # Section configuration to compare against. + # Section names are case-insensitive and may contain parameters in (). + # The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`, + # If `custom-order` is `true`, it follows the order of `sections` option. + # Default: ["standard", "default"] + sections: + - standard # Standard section: captures all standard packages. + - default # Default section: contains all imports that could not be matched to another section type. + # Skip generated files. + # Default: true + skip-generated: true + # Enable custom order of sections. + # If `true`, make the section order the same as the order of `sections`. + # Default: false + custom-order: true + # Drops lexical ordering for custom sections. + # Default: false + no-lex-order: false diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6e4d567 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +TEST_FLAGS ?= -p 8 -failfast -race -shuffle on + +all: + @echo "make :" + @echo "" + @echo "commands:" + @awk -F'[ :]' '/^#+/ {comment=$$0; gsub(/^#+[ ]*/, "", comment)} !/^(_|all:)/ && /^([A-Za-z_-]+):/ && !seen[$$1]++ {printf " %-24s %s\n", $$1, (comment ? "- " comment : ""); comment=""} !/^#+/ {comment=""}' Makefile + +test-clean: + go clean -testcache + +test: test-clean + go test -run=$(TEST) $(TEST_FLAGS) -json ./... | tparse --all --follow + +test-rerun: test-clean + go run github.com/goware/rerun/cmd/rerun -watch ./ -run 'make test' + +test-coverage: + go test -run=$(TEST) $(TEST_FLAGS) -cover -coverprofile=coverage.out -json ./... | tparse --all --follow + +test-coverage-inspect: test-coverage + go tool cover -html=coverage.out + +generate: + go generate -x ./... + +lint: + golangci-lint run ./... --fix -c .golangci.yml + diff --git a/middleware_test.go b/middleware_test.go index 0a64167..7f465c7 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -8,12 +8,11 @@ import ( "strings" "testing" + "github.com/0xsequence/authcontrol" + "github.com/0xsequence/authcontrol/proto" "github.com/go-chi/chi/v5" "github.com/go-chi/jwtauth/v5" "github.com/stretchr/testify/assert" - - "github.com/0xsequence/authcontrol" - "github.com/0xsequence/authcontrol/proto" ) type mockStore map[string]bool