github.com/polarismesh/polaris@v1.17.8/.golangci.yml (about)

     1  # Tencent is pleased to support the open source community by making Polaris available.
     2  #
     3  # Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     4  #
     5  # Licensed under the BSD 3-Clause License (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  # https://opensource.org/licenses/BSD-3-Clause
    10  #
    11  # Unless required by applicable law or agreed to in writing, software distributed
    12  # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    13  # CONDITIONS OF ANY KIND, either express or implied. See the License for the
    14  # specific language governing permissions and limitations under the License.
    15  
    16  ## This file contains all available configuration options
    17  ## with their default values.
    18  
    19  # See https://github.com/golangci/golangci-lint#config-file
    20  # See https://golangci-lint.run/usage/configuration/
    21  
    22  # Options for analysis running.
    23  run:
    24    # Exit code when at least one issue was found.
    25    # Default: 1
    26    issues-exit-code: 2
    27  
    28    # Include test files or not.
    29    # Default: true
    30    tests: false
    31  
    32    # Which dirs to skip: issues from them won't be reported.
    33    # Can use regexp here: `generated.*`, regexp is applied on full path.
    34    # Default value is empty list,
    35    # but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
    36    # "/" will be replaced by current OS file path separator to properly work on Windows.
    37    skip-dirs:
    38      - pkg/model/pb
    39      - .*~
    40      - test
    41  
    42    # Which files to skip: they will be analyzed, but issues from them won't be reported.
    43    # Default value is empty list,
    44    # but there is no need to include all autogenerated files,
    45    # we confidently recognize autogenerated files.
    46    # If it's not please let us know.
    47    # "/" will be replaced by current OS file path separator to properly work on Windows.
    48    skip-files:
    49      - ".*\\.my\\.go$"
    50      - ".*\\.pb\\.go$"
    51      - ".*_test\\.go$"
    52      - ".*\\.yaml$"
    53      - ".*\\.yml$"
    54  
    55  
    56  # Main linters configurations.
    57  # See https://golangci-lint.run/usage/linters
    58  linters:
    59    # Disable all default enabled linters.
    60    disable-all: true
    61    # Custom enable linters we want to use.
    62    enable:
    63      - errcheck      # Errcheck is a program for checking for unchecked errors in go programs.
    64      - 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.
    65      - funlen        # Tool for detection of long functions
    66      - gci           # Gci controls golang package import order and makes it always deterministic.
    67      - goconst       # Finds repeated strings that could be replaced by a constant
    68      - gocritic      # Provides diagnostics that check for bugs, performance and style issues.
    69      - gofmt         # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
    70      - gosimple      # Linter for Go source code that specializes in simplifying code
    71      - govet         # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
    72      - misspell      # Finds commonly misspelled English words in comments
    73      - nolintlint    # Reports ill-formed or insufficient nolint directives
    74      - revive        # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
    75      - staticcheck   # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
    76      - typecheck     # Like the front-end of a Go compiler, parses and type-checks Go code
    77      - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
    78      - lll
    79      #- whitespace    # Tool for detection of leading and trailing whitespace
    80  
    81  
    82  issues:
    83    max-issues-per-linter: 0
    84    max-same-issues: 0
    85    exclude-rules:
    86      # helpers in tests often (rightfully) pass a *testing.T as their first argument
    87      - path: _test\.go
    88        text: "context.Context should be the first parameter of a function"
    89        linters:
    90          - revive
    91      # Yes, they are, but it's okay in a test
    92      - path: _test\.go
    93        text: "exported func.*returns unexported type.*which can be annoying to use"
    94        linters:
    95          - revive
    96      # https://github.com/go-critic/go-critic/issues/926
    97      - linters:
    98          - gocritic
    99        text: "unnecessaryDefer:"
   100  
   101  
   102  # https://golangci-lint.run/usage/linters
   103  linters-settings:
   104    # https://golangci-lint.run/usage/linters/#misspell
   105    misspell:
   106      locale: US
   107      ignore-words:
   108        - cancelled
   109  
   110    # https://golangci-lint.run/usage/linters/#revive
   111    revive:
   112      ignore-generated-header: true
   113      severity: error
   114      rules:
   115        - name: atomic
   116        - name: line-length-limit
   117          severity: error
   118          arguments: [ 480 ]
   119        - name: unhandled-error
   120          severity: warning
   121          disabled: true
   122          arguments: [ "fmt.Printf", "myFunction" ]
   123        - name: var-naming
   124          severity: warning
   125          disabled: true
   126          arguments:
   127            - [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url" ] # AllowList
   128            - [ "VM" ] # DenyList
   129        - name: string-format
   130          severity: warning
   131          disabled: false
   132          arguments:
   133            - - 'core.WriteError[1].Message'
   134              - '/^([^A-Z]|$)/'
   135              - must not start with a capital letter
   136            - - 'fmt.Errorf[0]'
   137              - '/(^|[^\.!?])$/'
   138              - must not end in punctuation
   139            - - panic
   140              - '/^[^\n]*$/'
   141              - must not contain line breaks
   142        - name: function-result-limit
   143          severity: warning
   144          disabled: false
   145          arguments: [ 5 ]
   146        - name: import-shadowing
   147          severity: warning
   148          disabled: false
   149          arguments: [ "github.com/polarismesh/polaris","namespace" ]
   150        - name: waitgroup-by-value
   151          severity: warning
   152          disabled: false
   153        - name: max-public-structs
   154          severity: warning
   155          disabled: false
   156          arguments: [ 35 ]
   157        - name: indent-error-flow
   158          severity: warning
   159          disabled: false
   160        - name: function-length
   161          severity: warning
   162          disabled: false
   163          arguments: [ 80,0 ]
   164        - name: file-header
   165          arguments: [ "Tencent is pleased to support the open source community by making Polaris available." ]
   166        - name: exported
   167          severity: warning
   168          disabled: true
   169        - name: errorf
   170          severity: warning
   171          disabled: false
   172        - name: error-naming
   173          severity: warning
   174          disabled: false
   175  
   176    # https://golangci-lint.run/usage/linters/#funlen
   177    funlen:
   178      # Checks the number of lines in a function.
   179      # If lower than 0, disable the check.
   180      # Default: 60
   181      lines: 230
   182      # Checks the number of statements in a function.
   183      # If lower than 0, disable the check.
   184      # Default: 40
   185      statements: -1
   186    
   187    # https://golangci-lint.run/usage/linters/#lll
   188    lll:
   189      # Max line length, lines longer will be reported.
   190      # '\t' is counted as 1 character by default, and can be changed with the tab-width option.
   191      # Default: 120.
   192      line-length: 140
   193      # Tab width in spaces.
   194      # Default: 1
   195      tab-width: 1
   196  
   197    # https://golangci-lint.run/usage/linters/#goconst
   198    goconst:
   199      # Minimal length of string constant.
   200      # Default: 3
   201      min-len: 2
   202      # Minimum occurrences of constant string count to trigger issue.
   203      # Default: 3
   204      # For subsequent optimization, the value is reduced.
   205      min-occurrences: 60
   206      # Ignore test files.
   207      # Default: false
   208      ignore-tests: true
   209      # Look for existing constants matching the values.
   210      # Default: true
   211      match-constant: false
   212      # Search also for duplicated numbers.
   213      # Default: false
   214      numbers: true
   215      # Minimum value, only works with goconst.numbers
   216      # Default: 3
   217      min: 5
   218      # Maximum value, only works with goconst.numbers
   219      # Default: 3
   220      max: 20
   221      # Ignore when constant is not used as function argument.
   222      # Default: true
   223      ignore-calls: false
   224  
   225    # https://golangci-lint.run/usage/linters/#gocritic
   226    gocritic:
   227      disabled-checks:
   228        - ifElseChain
   229        - assignOp
   230        - appendAssign
   231        - singleCaseSwitch
   232        - regexpMust
   233        - typeSwitchVar
   234        - elseif
   235        - badCall
   236  
   237    # https://golangci-lint.run/usage/linters/#gosimple
   238    gosimple:
   239      # Select the Go version to target.
   240      # Default: 1.13
   241      # Deprecated: use the global `run.go` instead.
   242      go: "1.15"
   243      # Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
   244      # Default: ["*"]
   245      checks: [
   246        "all", "-S1000", "-S1001", "-S1002", "-S1008", "-S1009", "-S1016", "-S1023", "-S1025", "-S1029", "-S1034", "-S1040","-S1019"
   247      ]
   248  
   249    # https://golangci-lint.run/usage/linters/#govet
   250    govet:
   251      # Report about shadowed variables.
   252      # Default: false
   253      check-shadowing: true
   254      # Settings per analyzer.
   255      settings:
   256        # Analyzer name, run `go tool vet help` to see all analyzers.
   257        printf:
   258          # Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
   259          # Default: []
   260          funcs:
   261            - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
   262            - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
   263            - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
   264            - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
   265          # shadow:
   266          # Whether to be strict about shadowing; can be noisy.
   267          # Default: false
   268          # strict: false
   269        unusedresult:
   270          # Comma-separated list of functions whose results must be used
   271          # (in addition to defaults context.WithCancel,context.WithDeadline,context.WithTimeout,context.WithValue,
   272          # errors.New,fmt.Errorf,fmt.Sprint,fmt.Sprintf,sort.Reverse)
   273          # Default []
   274          funcs:
   275            - pkg.MyFunc
   276            - context.WithCancel
   277            - context.WithDeadline
   278            - context.WithTimeout
   279            - context.WithValue
   280            - sort.Reverse
   281          # Comma-separated list of names of methods of type func() string whose results must be used
   282          # (in addition to default Error,String)
   283          # Default []
   284          stringmethods:
   285            - MyMethod
   286      # Enable all analyzers.
   287      # Default: false
   288      enable-all: true
   289      # Disable analyzers by name.
   290      # Run `go tool vet help` to see all analyzers.
   291      # Default: []
   292      disable:
   293        - asmdecl
   294        - assign
   295        - atomic
   296        - atomicalign
   297        - bools
   298        - buildtag
   299        - cgocall
   300        - composites
   301        - copylocks
   302        - deepequalerrors
   303        - errorsas
   304        - fieldalignment
   305        - findcall
   306        - framepointer
   307        - httpresponse
   308        - ifaceassert
   309        - loopclosure
   310        - lostcancel
   311        - nilfunc
   312        - nilness
   313        - reflectvaluecompare
   314        - shift
   315        - shadow
   316        - sigchanyzer
   317        - sortslice
   318        - stdmethods
   319        - stringintconv
   320        - structtag
   321        - testinggoroutine
   322        - tests
   323        - unmarshal
   324        - unreachable
   325        - unsafeptr
   326        - unusedwrite
   327  
   328    # https://golangci-lint.run/usage/linters/#staticcheck
   329    staticcheck:
   330      # Select the Go version to target.
   331      # Default: "1.13"
   332      # Deprecated: use the global `run.go` instead.
   333      go: "1.15"
   334      # SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
   335      # Default: ["*"]
   336      checks: [ "all","-SA1019","-SA4015","-SA1029","-SA1016","-SA9003","-SA4006","-SA6003","-SA1004","-SA4009","-SA6002","-SA4017","-SA4021","-SA1006","-SA4010" ]
   337  
   338    # https://golangci-lint.run/usage/linters/#gofmt
   339    gofmt:
   340      # Simplify code: gofmt with `-s` option.
   341      # Default: true
   342      simplify: true
   343      # Apply the rewrite rules to the source before reformatting.
   344      # https://pkg.go.dev/cmd/gofmt
   345      # Default: []
   346      rewrite-rules: [ ]
   347  
   348    # https://golangci-lint.run/usage/linters/#gci
   349    gci:
   350      # Section configuration to compare against.
   351      # Section names are case-insensitive and may contain parameters in ().
   352      # The default order of sections is `standard > default > custom > blank > dot`,
   353      # If `custom-order` is `true`, it follows the order of `sections` option.
   354      # Default: ["standard", "default"]
   355      sections:
   356        - standard # Standard section: captures all standard packages.
   357        - default # Default section: contains all imports that could not be matched to another section type.
   358        - prefix(github.com/polarismesh/polaris) # Custom section: groups all imports with the specified Prefix.
   359        #- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
   360        #- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
   361      # Skip generated files.
   362      # Default: true
   363      skip-generated: true
   364      # Enable custom order of sections.
   365      # If `true`, make the section order the same as the order of `sections`.
   366      # Default: false
   367      custom-order: true
   368  
   369    # https://golangci-lint.run/usage/linters/#whitespace
   370    whitespace:
   371      # Enforces newlines (or comments) after every multi-line if statement.
   372      # Default: false
   373      multi-if: false
   374      # Enforces newlines (or comments) after every multi-line function signature.
   375      # Default: false
   376      multi-func: false