github.com/hedzr/evendeep@v0.4.8/.golangci.yaml (about)

     1  # This code is licensed under the terms of the MIT license.
     2  
     3  ## Golden config for golangci-lint v1.50.1
     4  #
     5  # This is the best config for golangci-lint based on my experience and opinion.
     6  # It is very strict, but not extremely strict.
     7  # Feel free to adopt and change it for your needs.
     8  
     9  
    10  # This file contains only configs which differ from defaults.
    11  # All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
    12  linters-settings:
    13    cyclop:
    14      # The maximal code complexity to report.
    15      # Default: 10
    16      max-complexity: 30
    17      # The maximal average package complexity.
    18      # If it's higher than 0.0 (float) the check is enabled
    19      # Default: 0.0
    20      package-average: 10.0
    21  
    22    dupl:
    23      threshold: 200
    24  
    25    errcheck:
    26      # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
    27      # Such cases aren't reported by default.
    28      # Default: false
    29      check-type-assertions: true
    30  
    31    exhaustive:
    32      # Program elements to check for exhaustiveness.
    33      # Default: [ switch ]
    34      check:
    35        - switch
    36        - map
    37  
    38    funlen:
    39      # Checks the number of lines in a function.
    40      # If lower than 0, disable the check.
    41      # Default: 60
    42      lines: 100
    43      # Checks the number of statements in a function.
    44      # If lower than 0, disable the check.
    45      # Default: 40
    46      statements: 50
    47  
    48    gocognit:
    49      # Minimal code complexity to report
    50      # Default: 30 (but we recommend 10-20)
    51      min-complexity: 20
    52  
    53    goconst:
    54      min-len: 2
    55      min-occurrences: 3
    56  
    57    gocritic:
    58      # Settings passed to gocritic.
    59      # The settings key is the name of a supported gocritic checker.
    60      # The list of supported checkers can be find in https://go-critic.github.io/overview.
    61      settings:
    62        captLocal:
    63          # Whether to restrict checker to params only.
    64          # Default: true
    65          paramsOnly: false
    66        underef:
    67          # Whether to skip (*x).method() calls where x is a pointer receiver.
    68          # Default: true
    69          skipRecvDeref: false
    70      enabled-tags:
    71        - diagnostic
    72        - experimental
    73        - opinionated
    74        - performance
    75        - style
    76      disabled-checks:
    77        - commentedOutCode
    78  
    79    gocyclo:
    80      min-complexity: 25
    81    golint:
    82      min-confidence: 0
    83  
    84    gomnd:
    85      # List of function patterns to exclude from analysis.
    86      # Values always ignored: `time.Date`,
    87      # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
    88      # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
    89      # Default: []
    90      ignored-functions:
    91        - os.Chmod
    92        - os.Mkdir
    93        - os.MkdirAll
    94        - os.OpenFile
    95        - os.WriteFile
    96        - prometheus.ExponentialBuckets
    97        - prometheus.ExponentialBucketsRange
    98        - prometheus.LinearBuckets
    99  
   100    gomodguard:
   101      blocked:
   102        # List of blocked modules.
   103        # Default: []
   104        modules:
   105          - github.com/golang/protobuf:
   106              recommendations:
   107                - google.golang.org/protobuf
   108              reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules"
   109          - github.com/satori/go.uuid:
   110              recommendations:
   111                - github.com/google/uuid
   112              reason: "satori's package is not maintained"
   113          - github.com/gofrs/uuid:
   114              recommendations:
   115                - github.com/google/uuid
   116              reason: "gofrs' package is not go module"
   117  
   118    govet:
   119      # Enable all analyzers.
   120      # Default: false
   121      enable-all: true
   122      # Disable analyzers by name.
   123      # Run `go tool vet help` to see all analyzers.
   124      # Default: []
   125      disable:
   126        - fieldalignment # too strict
   127      # Settings per analyzer.
   128      settings:
   129        shadow:
   130          # Whether to be strict about shadowing; can be noisy.
   131          # Default: false
   132          strict: true
   133  
   134    maligned:
   135      suggest-new: true
   136  
   137    nakedret:
   138      # Make an issue if func has more lines of code than this setting, and it has naked returns.
   139      # Default: 30
   140      max-func-lines: 0
   141  
   142    nolintlint:
   143      # Exclude following linters from requiring an explanation.
   144      # Default: []
   145      allow-no-explanation: [ funlen, gocognit, lll ]
   146      # Enable to require an explanation of nonzero length after each nolint directive.
   147      # Default: false
   148      require-explanation: true
   149      # Enable to require nolint directives to mention the specific linter being suppressed.
   150      # Default: false
   151      require-specific: true
   152  
   153    rowserrcheck:
   154      # database/sql is always checked
   155      # Default: []
   156      packages:
   157        - github.com/jmoiron/sqlx
   158  
   159    tenv:
   160      # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
   161      # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
   162      # Default: false
   163      all: true
   164  
   165  
   166  run:
   167    # Timeout for analysis, e.g. 30s, 5m.
   168    # Default: 1m
   169    timeout: 3m
   170    #
   171    #
   172    issues-exit-code: 1
   173    # Include test files or not.
   174    # Default: true
   175    tests: false
   176    # List of build tags, all linters use it.
   177    # Default: [].
   178    build-tags:
   179      - mytag
   180    # Which dirs to skip: issues from them won't be reported.
   181    # Can use regexp here: `generated.*`, regexp is applied on full path.
   182    # Default value is empty list,
   183    # but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
   184    # "/" will be replaced by current OS file path separator to properly work on Windows.
   185    skip-dirs:
   186      - src/external_libs
   187      - autogenerated_by_my_lib
   188      - playground
   189      - fixtures
   190      - testdata
   191      - examples
   192      - _examples
   193      - demo
   194      - ".*/ref/"
   195      - ".*/save/"
   196      - ".*/bin/"
   197      - "ci/"
   198    # Enables skipping of directories:
   199    # - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
   200    # Default: true
   201    skip-dirs-use-default: false
   202    # Which files to skip: they will be analyzed, but issues from them won't be reported.
   203    # Default value is empty list,
   204    # but there is no need to include all autogenerated files,
   205    # we confidently recognize autogenerated files.
   206    # If it's not please let us know.
   207    # "/" will be replaced by current OS file path separator to properly work on Windows.
   208    skip-files:
   209      - ".*\\.my\\.go$"
   210      - lib/bad.go
   211  
   212  linters:
   213    disable-all: true
   214    enable:
   215      ## enabled by default
   216      - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
   217      - gosimple # specializes in simplifying a code
   218      - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
   219      - ineffassign # detects when assignments to existing variables are not used
   220      - staticcheck # is a go vet on steroids, applying a ton of static analysis checks
   221      - typecheck # like the front-end of a Go compiler, parses and type-checks Go code
   222      - unused # checks for unused constants, variables, functions and types
   223      ## disabled by default
   224      - asasalint # checks for pass []any as any in variadic func(...any)
   225      - asciicheck # checks that your code does not contain non-ASCII identifiers
   226      - bidichk # checks for dangerous unicode character sequences
   227      - bodyclose # checks whether HTTP response body is closed successfully
   228      - cyclop # checks function and package cyclomatic complexity
   229      - dupl # tool for code clone detection
   230      - durationcheck # checks for two durations multiplied together
   231      - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
   232      - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
   233      - execinquery # checks query string in Query function which reads your Go src files and warning it finds
   234      - exhaustive # checks exhaustiveness of enum switch statements
   235      - exportloopref # checks for pointers to enclosing loop variables
   236      - forbidigo # forbids identifiers
   237      - funlen # tool for detection of long functions
   238      - gochecknoglobals # checks that no global variables exist
   239      - gochecknoinits # checks that no init functions are present in Go code
   240      - gocognit # computes and checks the cognitive complexity of functions
   241      - goconst # finds repeated strings that could be replaced by a constant
   242      - gocritic # provides diagnostics that check for bugs, performance and style issues
   243      - gocyclo # computes and checks the cyclomatic complexity of functions
   244      - godot # checks if comments end in a period
   245      # - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
   246      - gomnd # detects magic numbers
   247      - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
   248      - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
   249      - goprintffuncname # checks that printf-like functions are named with f at the end
   250      - gosec # inspects source code for security problems
   251      - lll # reports long lines
   252      - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap)
   253      - makezero # finds slice declarations with non-zero initial length
   254      # - nakedret # finds naked returns in functions greater than a specified function length
   255      - nestif # reports deeply nested if statements
   256      - nilerr # finds the code that returns nil even if it checks that the error is not nil
   257      - nilnil # checks that there is no simultaneous return of nil error and an invalid value
   258      - noctx # finds sending http request without context.Context
   259      - nolintlint # reports ill-formed or insufficient nolint directives
   260      # - nonamedreturns # reports all named returns
   261      - nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
   262      - predeclared # finds code that shadows one of Go's predeclared identifiers
   263      - promlinter # checks Prometheus metrics naming via promlint
   264      - reassign # checks that package variables are not reassigned
   265      - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
   266      # - rowserrcheck # checks whether Err of rows is checked successfully
   267      # - sqlclosecheck # checks that sql.Rows and sql.Stmt are closed
   268      - stylecheck # is a replacement for golint
   269      - tenv # detects using os.Setenv instead of t.Setenv since Go1.17
   270      - testableexamples # checks if examples are testable (have an expected output)
   271      - testpackage # makes you use a separate _test package
   272      - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
   273      - unconvert # removes unnecessary type conversions
   274      #- unparam # reports unused function parameters
   275      - usestdlibvars # detects the possibility to use variables/constants from the Go standard library
   276      # - wastedassign # finds wasted assignment statements
   277      - whitespace # detects leading and trailing whitespace
   278  
   279      ## you may want to enable
   280      #- decorder # checks declaration order and count of types, constants, variables and functions
   281      #- exhaustruct # checks if all structure fields are initialized
   282      #- gci # controls golang package import order and makes it always deterministic
   283      #- godox # detects FIXME, TODO and other comment keywords
   284      #- goheader # checks is file header matches to pattern
   285      #- interfacebloat # checks the number of methods inside an interface
   286      #- ireturn # accept interfaces, return concrete types
   287      #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
   288      #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
   289      #- wrapcheck # checks that errors returned from external packages are wrapped
   290  
   291      ## disabled
   292      #- containedctx # detects struct contained context.Context field
   293      #- contextcheck # [too many false positives] checks the function whether use a non-inherited context
   294      #- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
   295      #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
   296      #- dupword # [useless without config] checks for duplicate words in the source code
   297      #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted
   298      #- forcetypeassert # [replaced by errcheck] finds forced type assertions
   299      #- goerr113 # [too strict] checks the errors handling expressions
   300      #- gofmt # [replaced by goimports] checks whether code was gofmt-ed
   301      #- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
   302      #- grouper # analyzes expression groups
   303      #- importas # enforces consistent import aliases
   304      #- maintidx # measures the maintainability index of each function
   305      #- misspell # [useless] finds commonly misspelled English words in comments
   306      #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
   307      #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
   308      #- tagliatelle # checks the struct tags
   309      #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
   310      #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
   311  
   312      ## deprecated
   313      #- deadcode # [deprecated, replaced by unused] finds unused code
   314      #- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized
   315      #- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
   316      #- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible
   317      #- interfacer # [deprecated] suggests narrower interface types
   318      #- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted
   319      #- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name
   320      #- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs
   321      #- structcheck # [deprecated, replaced by unused] finds unused struct fields
   322      #- varcheck # [deprecated, replaced by unused] finds unused global variables and constants
   323  
   324  
   325      # - depguard
   326      # - dogsled
   327      # - gofmt
   328  
   329  #linters:
   330  #  enable:
   331  #    - bodyclose
   332  #    - dogsled
   333  #    - errcheck
   334  #    - errname
   335  #    - errorlint
   336  #    #    - exhaustive
   337  #    #    - exportloopref
   338  #    #    - funlen
   339  #    #    - gochecknoinits
   340  #    #    - goconst
   341  #    #    - gocritic
   342  #    #    - gocyclo
   343  #    #    - gofmt
   344  #    # - golint
   345  #    - gocritic
   346  #    # - goimports
   347  #    - gosec
   348  #    - stylecheck
   349  #    - unconvert
   350  #  disable:
   351  #    - maligned
   352  #    - unparam
   353  #    - lll
   354  #    - gochecknoinits
   355  #    - gochecknoglobals
   356  #    - dupl
   357  #    - deadcode
   358  #    - nakedret
   359  #    - structcheck
   360  #
   361  #  enable:
   362  #    - bodyclose
   363  #    - deadcode
   364  #    - dogsled
   365  #    - dupl
   366  #    - errcheck
   367  #    - errname
   368  #    - errorlint
   369  #    - exhaustive
   370  #    - exportloopref
   371  #    - funlen
   372  #    - gochecknoinits
   373  #    - goconst
   374  #    - gocritic
   375  #    - gocyclo
   376  #    - gofmt
   377  #    - goimports
   378  #    - gomnd
   379  #    - goprintffuncname
   380  #    - gosec
   381  #    - gosimple
   382  #    - govet
   383  #    - ifshort
   384  #    - ineffassign
   385  #    # - lll
   386  #    - makezero
   387  #    - misspell
   388  #    - nakedret
   389  #    - noctx
   390  #    - nolintlint
   391  #    - revive
   392  #    - staticcheck
   393  #    - structcheck
   394  #    - stylecheck
   395  #    # - testpackage
   396  #    - typecheck
   397  #    - unconvert
   398  #    - unparam
   399  #    - unused
   400  #    - varcheck
   401  #    - whitespace
   402  
   403  
   404  
   405  issues:
   406    # Maximum count of issues with the same text.
   407    # Set to 0 to disable.
   408    # Default: 3
   409    max-same-issues: 50
   410  
   411    exclude-rules:
   412      - source: "^//\\s*go:generate\\s"
   413        linters: [ lll ]
   414      - source: "(noinspection|TODO)"
   415        linters: [ godot ]
   416      - source: "//noinspection"
   417        linters: [ gocritic ]
   418      - source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {"
   419        linters: [ errorlint ]
   420      - path: "_test\\.go"
   421        linters:
   422          - bodyclose
   423          - dupl
   424          - funlen
   425          - goconst
   426          - gosec
   427          - noctx
   428          - wrapcheck