From 5fd0857b0ef8731aa8fc6752ef5e3943a92abe5c Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Tue, 11 May 2021 20:05:54 +0000 Subject: [PATCH 1/3] chore: update golangci-lint configuration --- .golangci.yml | 160 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 113 insertions(+), 47 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4bde9808..00011048 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,64 +1,81 @@ # See https://golangci-lint.run/usage/configuration/ linters-settings: - goconst: - min-len: 4 - min-occurrences: 3 gocognit: # tunnel.go has a 150 line function. Someone should fix it and # decrement this back down to a rational number. min-complexity: 52 + goconst: + min-len: 4 + min-occurrences: 3 nestif: min-complexity: 10 - govet: - settings: - printf: - funcs: # Run `go tool vet help printf` to see available settings for `printf` analyzer. - - (cdr.dev/coder-cli/pkg/clog).Tipf - - (cdr.dev/coder-cli/pkg/clog).Hintf - - (cdr.dev/coder-cli/pkg/clog).Causef -linters: - disable-all: true - exclude-use-default: false - enable: - - megacheck - - govet - - golint - - goconst - - gocognit - - nestif - - misspell - - unparam - - unused - - bodyclose - - deadcode - - depguard - - dogsled - - errcheck - - unconvert - - unparam - - varcheck - - whitespace - - structcheck - - stylecheck - - typecheck - - nolintlint - - rowserrcheck - - scopelint - - goprintffuncname - - gofmt - - godot - - ineffassign - - gocritic + revive: + # see https://github.com/mgechev/revive#available-rules for details. + ignore-generated-header: true + severity: warning + rules: + - name: atomic + # - name: bare-return + - name: blank-imports + - name: bool-literal-in-expr + - name: call-to-gc + - name: confusing-naming + - name: confusing-results + - name: constant-logical-expr + - name: context-as-argument + - name: context-keys-type + # - name: deep-exit + - name: defer + - name: dot-imports + - name: duplicated-imports + # - name: early-return + # - name: empty-block + - name: empty-lines + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + # - name: flag-parameter + - name: get-return + - name: identical-branches + # - name: if-return + # - name: import-shadowing + - name: increment-decrement + - name: indent-error-flow + - name: modifies-parameter + - name: modifies-value-receiver + - name: package-comments + - name: range + - name: range-val-address + - name: range-val-in-closure + - name: receiver-naming + - name: redefines-builtin-id + - name: string-of-int + - name: struct-tag + - name: superfluous-else + - name: time-naming + - name: unconditional-recursion + - name: unexported-naming + - name: unexported-return + # - name: unhandled-error + - name: unnecessary-stmt + - name: unreachable-code + # - name: unused-parameter + # - name: unused-receiver + # - name: var-declaration + - name: var-naming + - name: waitgroup-by-value issues: - exclude-use-default: false exclude: # errcheck: Almost all programs ignore errors on these functions and in most cases it's ok - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked # golint: False positive when tests are defined in package 'test' - func name will be used as test\.Test.* by other packages, and that stutters; consider calling this # govet: Common false positives - - (possible misuse of unsafe.Pointer|should have signature) + - possible misuse of unsafe.Pointer|should have signature + - should have signature # staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore - ineffective break statement. Did you mean to break out of the outer loop # gosec: Too many false-positives on 'unsafe' usage @@ -67,7 +84,56 @@ issues: - Subprocess launch(ed with variable|ing should be audited) # gosec: Duplicated errcheck checks - G104 - # gosec: Too many issues in popular repos - - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) # gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' - Potential file inclusion via variable + + fix: true + max-issues-per-linter: 0 + max-same-issues: 0 + +run: + timeout: 5m + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - dogsled + - errcheck + # - errorlint + - exportloopref + # - forcetypeassert + - gocognit + - goconst + - gocritic + - gocyclo + - godot + - gofmt + - goimports + - golint + - gomodguard + - goprintffuncname + # - gosec + - gosimple + - govet + - ineffassign + - makezero + - megacheck + - misspell + - nestif + - noctx + - nolintlint + - revive + - rowserrcheck + - sqlclosecheck + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - wastedassign + - whitespace From 5d023a8dd838a06916b17ecc4a540dffd9b8a882 Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Tue, 11 May 2021 20:08:43 +0000 Subject: [PATCH 2/3] update --- .golangci.yml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 00011048..df85d74b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -68,25 +68,6 @@ linters-settings: - name: waitgroup-by-value issues: - exclude: - # errcheck: Almost all programs ignore errors on these functions and in most cases it's ok - - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked - # golint: False positive when tests are defined in package 'test' - - func name will be used as test\.Test.* by other packages, and that stutters; consider calling this - # govet: Common false positives - - possible misuse of unsafe.Pointer|should have signature - - should have signature - # staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore - - ineffective break statement. Did you mean to break out of the outer loop - # gosec: Too many false-positives on 'unsafe' usage - - Use of unsafe calls should be audited - # gosec: Too many false-positives for parametrized shell calls - - Subprocess launch(ed with variable|ing should be audited) - # gosec: Duplicated errcheck checks - - G104 - # gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' - - Potential file inclusion via variable - fix: true max-issues-per-linter: 0 max-same-issues: 0 From c648eec198ecf89798c996a4e95764695b8b3aad Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Tue, 11 May 2021 20:11:43 +0000 Subject: [PATCH 3/3] bump golangci-lint version --- .github/workflows/test.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a3cf3c60..79a324a9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,36 +6,44 @@ jobs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- + - name: fmt uses: ./ci/image with: args: make -j fmt + - run: ./ci/scripts/files_changed.sh + lint: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 + - name: golangci-lint uses: golangci/golangci-lint-action@v2.5.2 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.36 + version: v1.39 + test: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- + - name: test uses: ./ci/image env: @@ -45,18 +53,22 @@ jobs: CODER_PASSWORD: ${{ secrets.CODER_PASSWORD }} with: args: make -j test/coverage + gendocs: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 + - uses: actions/cache@v2 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- + - name: generate-docs uses: ./ci/image with: args: make -j gendocs + - run: ./ci/scripts/files_changed.sh