fix: linter

This commit is contained in:
2023-04-21 12:05:30 +08:00
parent 53ab00c196
commit 96f4181e5f
2 changed files with 300 additions and 341 deletions
+296 -340
View File
@@ -5,352 +5,308 @@ linters:
enable: enable:
- govet - govet
- staticcheck - staticcheck
- unused
- ineffassign - ineffassign
- typecheck - typecheck
- exportloopref - exportloopref
- bodyclose - bodyclose
- gofmt - gofmt
- gosimple
- stylecheck - stylecheck
- revive - revive
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
disable-all: true disable-all: true
linters-settings: linters-settings:
staticcheck: staticcheck:
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks # SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
checks: ["all"] checks: ["all"]
revive: stylecheck:
# Maximum number of open files at the same time. checks:
# See https://github.com/mgechev/revive#command-line-flags [
# Defaults to unlimited. "all",
max-open-files: 2048 "-ST1000",
# When set to false, ignores files with "GENERATED" header, similar to golint. "-ST1001",
# See https://github.com/mgechev/revive#available-rules for details. "-ST1003",
# Default: false "-ST1016",
ignore-generated-header: true "-ST1020",
# Sets the default severity. "-ST1021",
# See https://github.com/mgechev/revive#configuration "-ST1022",
# Default: warning ]
severity: error revive:
# Enable all available rules. # Maximum number of open files at the same time.
# Default: false # See https://github.com/mgechev/revive#command-line-flags
enable-all-rules: false # Defaults to unlimited.
# Sets the default failure confidence. max-open-files: 2048
# This means that linting errors with less than 0.8 confidence will be ignored. # When set to false, ignores files with "GENERATED" header, similar to golint.
# Default: 0.8 # See https://github.com/mgechev/revive#available-rules for details.
confidence: 0.1 # Default: false
rules: ignore-generated-header: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant # Sets the default severity.
- name: add-constant # See https://github.com/mgechev/revive#configuration
severity: warning # Default: warning
disabled: false severity: error
arguments: # Enable all available rules.
- maxLitCount: "3" # Default: false
allowStrs: '""' enable-all-rules: false
allowInts: "0,1,2" # Sets the default failure confidence.
allowFloats: "0.0,0.,1.0,1.,2.0,2." # This means that linting errors with less than 0.8 confidence will be ignored.
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#argument-limit # Default: 0.8
- name: argument-limit confidence: 0.1
severity: warning rules:
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#argument-limit
arguments: [4] - name: argument-limit
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic severity: warning
- name: atomic disabled: false
severity: warning arguments: [4]
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#banned-characters - name: atomic
- name: banned-characters severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#banned-characters
arguments: ["Ω", "Σ", "σ", "7"] - name: banned-characters
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return severity: warning
- name: bare-return disabled: false
severity: warning arguments: ["Ω", "Σ", "σ", "7"]
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#blank-imports - name: bool-literal-in-expr
- name: blank-imports severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#call-to-gc
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr - name: call-to-gc
- name: bool-literal-in-expr severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cognitive-complexity
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#call-to-gc - name: cognitive-complexity
- name: call-to-gc severity: warning
severity: warning disabled: false
disabled: false arguments: [7]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cognitive-complexity # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-naming
- name: cognitive-complexity - name: confusing-naming
severity: warning severity: warning
disabled: false disabled: false
arguments: [7] # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-results
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-naming - name: confusing-results
- name: confusing-naming severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-results - name: constant-logical-expr
- name: confusing-results severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr - name: context-as-argument
- name: constant-logical-expr severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument - name: context-keys-type
- name: context-as-argument severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cyclomatic
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type - name: cyclomatic
- name: context-keys-type severity: warning
severity: warning disabled: false
disabled: false arguments: [5]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cyclomatic # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#datarace
- name: cyclomatic - name: datarace
severity: warning severity: warning
disabled: false disabled: false
arguments: [3] # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#datarace - name: deep-exit
- name: datarace severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#defer
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit - name: defer
- name: deep-exit severity: warning
severity: warning disabled: false
disabled: false arguments:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#defer - ["call-chain", "loop"]
- name: defer # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#duplicated-imports
severity: warning - name: duplicated-imports
disabled: false severity: warning
arguments: disabled: false
- ["call-chain", "loop"] # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports - name: early-return
- name: dot-imports severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-naming
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#duplicated-imports - name: error-naming
- name: duplicated-imports severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-return
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return - name: error-return
- name: early-return severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block - name: error-strings
- name: empty-block severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines - name: errorf
- name: empty-lines severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-naming - name: exported
- name: error-naming severity: warning
severity: warning disabled: false
disabled: false arguments:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-return - "checkPrivateReceivers"
- name: error-return - "sayRepetitiveInsteadOfStutters"
severity: warning # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#flag-parameter
disabled: false - name: flag-parameter
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings severity: warning
- name: error-strings disabled: false
severity: warning # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-result-limit
disabled: false - name: function-result-limit
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf severity: warning
- name: errorf disabled: false
severity: warning arguments: [2]
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-length
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported - name: function-length
- name: exported severity: warning
severity: warning disabled: false
disabled: false arguments: [100, 0]
arguments: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#get-return
- "checkPrivateReceivers" - name: get-return
- "sayRepetitiveInsteadOfStutters" severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header disabled: false
- name: file-header # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches
severity: warning - name: identical-branches
disabled: false severity: warning
arguments: disabled: false
- This is the text that must appear at the top of source files. # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#flag-parameter - name: if-return
- name: flag-parameter severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#increment-decrement
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-result-limit - name: increment-decrement
- name: function-result-limit severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow
arguments: [2] - name: indent-error-flow
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-length severity: warning
- name: function-length disabled: false
severity: warning # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#imports-blacklist
disabled: false - name: imports-blacklist
arguments: [10, 0] severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#get-return disabled: false
- name: get-return arguments:
severity: warning - "crypto/md5"
disabled: false - "crypto/sha1"
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-parameter
- name: identical-branches - name: modifies-parameter
severity: warning severity: warning
disabled: false disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-value-receiver
- name: if-return - name: modifies-value-receiver
severity: warning severity: warning
disabled: false disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#increment-decrement # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#nested-structs
- name: increment-decrement - name: nested-structs
severity: warning severity: warning
disabled: false disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#optimize-operands-order
- name: indent-error-flow - name: optimize-operands-order
severity: warning severity: warning
disabled: false disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#imports-blacklist # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments
- name: imports-blacklist - name: package-comments
severity: warning severity: warning
disabled: false disabled: false
arguments: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range
- "crypto/md5" - name: range
- "crypto/sha1" severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing disabled: false
- name: import-shadowing # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-in-closure
severity: warning - name: range-val-in-closure
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit disabled: false
- name: line-length-limit # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-address
severity: warning - name: range-val-address
disabled: false severity: warning
arguments: [80] disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#max-public-structs # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming
- name: max-public-structs - name: receiver-naming
severity: warning severity: warning
disabled: false disabled: false
arguments: [3] # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redefines-builtin-id
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-parameter - name: redefines-builtin-id
- name: modifies-parameter severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-of-int
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-value-receiver - name: string-of-int
- name: modifies-value-receiver severity: warning
severity: warning disabled: false
disabled: false # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#nested-structs - name: string-format
- name: nested-structs severity: warning
severity: warning disabled: false
disabled: false arguments:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#optimize-operands-order - - "core.WriteError[1].Message"
- name: optimize-operands-order - "/^([^A-Z]|$)/"
severity: warning - must not start with a capital letter
disabled: false - - "fmt.Errorf[0]"
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments - '/(^|[^\.!?])$/'
- name: package-comments - must not end in punctuation
severity: warning - - panic
disabled: false - '/^[^\n]*$/'
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range - must not contain line breaks
- name: range # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
severity: warning - name: struct-tag
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-in-closure disabled: false
- name: range-val-in-closure # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else
severity: warning - name: superfluous-else
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-address disabled: false
- name: range-val-address # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-equal
severity: warning - name: time-equal
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming disabled: false
- name: receiver-naming # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-naming
severity: warning - name: time-naming
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redefines-builtin-id disabled: false
- name: redefines-builtin-id # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming
severity: warning - name: var-naming
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-of-int disabled: true
- name: string-of-int arguments:
severity: warning - ["ID"] # AllowList
disabled: false - ["VM"] # DenyList
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration
- name: string-format - name: var-declaration
severity: warning severity: warning
disabled: false disabled: false
arguments: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unconditional-recursion
- - 'core.WriteError[1].Message' - name: unconditional-recursion
- '/^([^A-Z]|$)/' severity: warning
- must not start with a capital letter disabled: false
- - 'fmt.Errorf[0]' # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming
- '/(^|[^\.!?])$/' - name: unexported-naming
- must not end in punctuation severity: warning
- - panic disabled: false
- '/^[^\n]*$/' # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return
- must not contain line breaks - name: unexported-return
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag disabled: true
- name: struct-tag # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
severity: warning - name: unhandled-error
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else disabled: false
- name: superfluous-else arguments:
severity: warning - "fmt.Printf"
disabled: false - "os.(Create|WriteFile|Chmod)"
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-equal - "net.*"
- name: time-equal # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt
severity: warning - name: unnecessary-stmt
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-naming disabled: false
- name: time-naming # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unreachable-code
severity: warning - name: unreachable-code
disabled: false severity: warning
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming disabled: false
- name: var-naming # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
severity: warning - name: useless-break
disabled: true severity: warning
arguments: disabled: false
- ["ID"] # AllowList # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value
- ["VM"] # DenyList - name: waitgroup-by-value
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration severity: warning
- name: var-declaration disabled: false
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unconditional-recursion
- name: unconditional-recursion
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming
- name: unexported-naming
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return
- name: unexported-return
disabled: true
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
- name: unhandled-error
severity: warning
disabled: false
arguments:
- "fmt.Printf"
- "myFunction"
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt
- name: unnecessary-stmt
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unreachable-code
- name: unreachable-code
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
- name: unused-receiver
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
- name: useless-break
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value
- name: waitgroup-by-value
severity: warning
disabled: false
+4 -1
View File
@@ -145,6 +145,9 @@ alias gitb="git branch --show-current | tr -d '\n' | pbcopy"
alias gci="golangci-lint run -c=~/.dotfile/.golangci.yml ./..." alias gci="golangci-lint run -c=~/.dotfile/.golangci.yml ./..."
alias gmt="go mod tidy" alias gmt="go mod tidy"
alias gtc="go test -gcflags=all=-l -cover ./..." alias gtc="go test -gcflags=all=-l -cover ./..."
alias gtr="(){go test -gcflags=all=-l -v -run $1. ;}"
alias swg="swag init -o docs -g " alias swg="swag init -o docs -g "
alias sws="swagger serve -F=swagger" alias sws="swagger serve -F=swagger"
function gtr(){
go test -gcflags=all=-l -v -run="$1"
}