From e134faef541431ed49f77bbcdd68448f51dcff9f Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 1 Sep 2023 17:03:30 +0330 Subject: [PATCH] feat: golangci-linter config file (#28) --- .github/workflows/linting.yml | 4 +- .golangci.yml | 82 +++++++++++++++++++++++++++++++++++ Makefile | 28 ++++-------- config/config.go | 4 +- core/database/subSets.go | 6 ++- 5 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index b04fe03..122006c 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -17,13 +17,13 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: '1.21.0' - name: Checkout code uses: actions/checkout@v3 - name: Installing golangci-lint - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1 - name: Formatting and linting the project run: make check \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..5b7584d --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,82 @@ +linters: + enable-all: true + disable: + - scopelint # deprecated + - maligned # deprecated + - nosnakecase # deprecated + - interfacer # deprecated + - deadcode # deprecated + - ifshort # deprecated + - golint # deprecated + - structcheck # deprecated + - varcheck # deprecated + - exhaustivestruct # deprecated + - varnamelen + - wrapcheck + - paralleltest + - interfacebloat + - depguard + - gochecknoglobals + - gomnd + - cyclop + - nestif + - gochecknoinits + - dupl + - goconst + - gocognit # Consider to enable it + - funlen # Consider to enable it + - forbidigo # Consider to enable it + - gci # Consider to enable it (add it to make fmt) + - godox # Consider to enable it (only show warning) + - gocritic # Consider to enable it + - wsl # Consider to enable it + - testpackage # Consider to enable it (??) + - containedctx # Consider to enable it + - contextcheck # Consider to enable it + - exhaustive # Consider to enable it + - exhaustruct # Consider to enable it + - goerr113 # Consider to enable it + - wastedassign # Consider to enable it + - nonamedreturns # Consider to enable it + - nlreturn # Consider to enable it + - ireturn # Consider to enable it (??) + +linters-settings: + gosimple: + checks: ["all"] + + govet: + enable-all: true + disable: fieldalignment + shadow: + strict: true + + godox: + severity: warning + + predeclared: + # Comma-separated list of predeclared identifiers to not report on. + # Default: "" + ignore: "len" + # Include method names and field names (i.e., qualified names) in checks. + # Default: false + q: true + + tagliatelle: + # Check the struct tag name case. + case: + use-field-name: false + rules: + json: snake + yaml: snake + +issues: + exclude-rules: + # disable funlen for all _test.go files + - path: _test.go + linters: + - funlen + + - linters: + - govet + text: "shadow: declaration of \"err\" shadows" \ No newline at end of file diff --git a/Makefile b/Makefile index f2f5fe1..90aaf0e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,11 @@ PACKAGES=$(shell go list ./... | grep -v 'tests') +### Tools needed for development +devtools: + @echo "Installing devtools" + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1 + go install mvdan.cc/gofumpt@latest + ### Testing unit_test: go test $(PACKAGES) @@ -9,26 +15,8 @@ test: ### Formatting, linting, and vetting fmt: - gofmt -s -w . + gofumpt -l -w . go mod tidy check: - golangci-lint run \ - --build-tags "${BUILD_TAG}" \ - --timeout=20m0s \ - --enable=gofmt \ - --enable=unconvert \ - --enable=unparam \ - --enable=asciicheck \ - --enable=misspell \ - --enable=revive \ - --enable=decorder \ - --enable=reassign \ - --enable=usestdlibvars \ - --enable=nilerr \ - --enable=gosec \ - --enable=exportloopref \ - --enable=whitespace \ - --enable=goimports \ - --enable=gocyclo \ - --enable=lll \ No newline at end of file + golangci-lint run --build-tags "${BUILD_TAG}" --timeout=20m0s \ No newline at end of file diff --git a/config/config.go b/config/config.go index 10c11f5..358741f 100644 --- a/config/config.go +++ b/config/config.go @@ -58,7 +58,7 @@ func LoadFromFile(path string) *Config { if err != nil { log.Error("Can not decode the Config Yaml file", "error: ", err) } - //TODO: validate config - //TODO: Log + // TODO: validate config + // TODO: Log return config } diff --git a/core/database/subSets.go b/core/database/subSets.go index d55d187..ba2f2f0 100644 --- a/core/database/subSets.go +++ b/core/database/subSets.go @@ -1,7 +1,9 @@ package database -type SubSets map[string]SubSet -type SubSet []Element +type ( + SubSets map[string]SubSet + SubSet []Element +) func NewSubSets() SubSets { return SubSets{}