From 98fcd4fbdf3aac145e3c83bff6b04a2ae8493815 Mon Sep 17 00:00:00 2001 From: Yousif Akbar <11247449+yhakbar@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:54:52 -0400 Subject: [PATCH] feat: Adding strict lint (#3348) * feat: Adding strict lint * fix: Bumping up to a medium instance --- .circleci/config.yml | 21 +++++++++ .golangci.yml | 3 ++ .strict.golangci.yml | 105 +++++++++++++++++++++++++++++++++++++++++++ Makefile | 5 ++- 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 .strict.golangci.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 5c3d05d8c..e3dfa3c1b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -372,6 +372,19 @@ jobs: - store_test_results: path: logs + strict_lint: + resource_class: medium + <<: *defaults + steps: + - checkout + # The `run-strict-lint` target requires the `master` ref for comparison. + - run: git fetch + - run: + name: Run strict lint + command: | + make install-lint + make run-strict-lint + # Run TFLint tests separately as tflint during execution change working directory. integration_test_tflint: resource_class: large @@ -567,6 +580,14 @@ workflows: - AWS__PHXDEVOPS__circle-ci-test - GCP__automated-tests - GITHUB__PAT__gruntwork-ci + - strict_lint: + filters: + tags: + only: /^v.*/ + context: + - AWS__PHXDEVOPS__circle-ci-test + - GCP__automated-tests + - GITHUB__PAT__gruntwork-ci - integration_test_tofu_engine: filters: tags: diff --git a/.golangci.yml b/.golangci.yml index 1f5dabd10..f6dd182f3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -80,6 +80,9 @@ linters: - performance - unused - test + # NOTE: These two are only in the strict lint right now + # - style + # - complexity issues: exclude-dirs: diff --git a/.strict.golangci.yml b/.strict.golangci.yml new file mode 100644 index 000000000..56403bf07 --- /dev/null +++ b/.strict.golangci.yml @@ -0,0 +1,105 @@ +run: + timeout: 2m + issues-exit-code: 1 + tests: true + go: "1.22" +output: + formats: + - format: colored-line-number + print-issued-lines: true + print-linter-name: true + +linters-settings: + staticcheck: + checks: + - all + - '-SA9005' + errcheck: + check-type-assertions: false + check-blank: false + exclude-functions: + - (*os.File).Close + errorlint: + errorf: true + asserts: true + comparison: true + gofmt: + simplify: true + dupl: + threshold: 120 + goconst: + min-len: 3 + min-occurrences: 5 + revive: + min-confidence: 0.8 + unused: + check-exported: false + unparam: + check-exported: false + nakedret: + max-func-lines: 20 + gocritic: + disabled-checks: + - regexpMust + - rangeValCopy + - appendAssign + - hugeParam + enabled-tags: + - performance + disabled-tags: + - experimental + +linters: + enable: + - dupl + - errcheck + - goconst + - gocritic + - goimports + - mnd + - gosimple + - govet + - ineffassign + - staticcheck + - misspell + - unconvert + - unused + - unparam + enable-all: false + disable: + - depguard + - gosec + - gocyclo + - exhaustruct + fast: false + mnd: + ignored-functions: strconv.Format*,os.*,strconv.Parse*,strings.SplitN,bytes.SplitN + presets: + - bugs + - performance + - unused + - test + # These two are only in the strict lint right now + - style + - complexity + +issues: + exclude-dirs: + - docs + - _ci + - .github + - .circleci + exclude-rules: + - path: _test\.go + linters: + - dupl + - gocyclo + - lll + - errcheck + - wsl + - mnd + - unparam + + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/Makefile b/Makefile index 01c146639..5fc54ff18 100644 --- a/Makefile +++ b/Makefile @@ -44,10 +44,13 @@ install-lint: run-lint: golangci-lint run -v --timeout=5m ./... +run-strict-lint: + golangci-lint run -v --timeout=5m -c .strict.golangci.yml --new-from-rev origin/master ./... + install-mockery: go install github.com/vektra/mockery/v2@v2.44.1 generate-mocks: go generate ./... -.PHONY: help fmtcheck fmt install-fmt-hook clean install-lint run-lint +.PHONY: help fmtcheck fmt install-fmt-hook clean install-lint run-lint run-strict-lint