k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/golangci.yaml (about)

     1  # golangci-lint is used in Kubernetes with different configurations that
     2  # enable an increasing amount of checks:
     3  # - golangci.yaml is the most permissive configuration. All existing code
     4  #   passed.
     5  # - golangci-strict.yaml adds checks that all new code in pull requests
     6  #   must pass.
     7  # - golangci-hints.yaml adds checks for code patterns where developer
     8  #   and reviewer may decide whether findings should get addressed before
     9  #   merging. Beware that the golangci-lint output includes also the
    10  #   issues that must be fixed and doesn't indicate how severe each issue
    11  #   is (https://gophers.slack.com/archives/CS0TBRKPC/p1685721815275349).
    12  #
    13  # All three flavors are generated from golangci.yaml.in with
    14  # hack/update-golangci-lint-config.sh.
    15  
    16  run:
    17    timeout: 30m
    18    skip-files:
    19      - "^zz_generated.*"
    20  
    21  output:
    22    sort-results: true
    23  
    24  issues:
    25    max-issues-per-linter: 0
    26    max-same-issues: 0
    27  
    28    # The default excludes disable the "should have comment or be unexported" check from revive.
    29    # We want that to be enabled, therefore we have to disable all default excludes and
    30    # add those back one-by-one that we want. See https://github.com/golangci/golangci-lint/issues/456#issuecomment-617470264
    31    exclude-use-default: false
    32    exclude:
    33      # staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
    34      - ineffective break statement. Did you mean to break out of the outer loop
    35  
    36    # Excluding configuration per-path, per-linter, per-text and per-source
    37    exclude-rules:
    38      # exclude ineffassign linter for generated files for conversion
    39      - path: conversion\.go
    40        linters:
    41          - ineffassign
    42  
    43      # SSA Extract calls are allowed in tests.
    44      - linters:
    45          - forbidigo
    46        text: should not be used because managedFields was removed
    47        path: _test.go$
    48  
    49      # TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components
    50      # with different owners it's hard to fix everything in a single pr. This will therefore be done in multiple prs.
    51      - path: (pkg/volume/*|test/*|azure/*|pkg/cmd/wait*|request/bearertoken/*|metrics/*|filters/*)
    52        linters:
    53          - gocritic
    54  
    55      # The Kubernetes naming convention for conversion functions uses underscores
    56      # and intentionally deviates from normal Go conventions to make those function
    57      # names more readable. Same for SetDefaults_*.
    58      #
    59      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627
    60      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592
    61      - linters:
    62          - stylecheck
    63          - revive
    64        text: "(ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)|exported: exported function (Convert|SetDefaults)_.* should be of the form)"
    65  
    66      # This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91).
    67      - linters:
    68         - ginkgolinter
    69        text: use a function call in (Eventually|Consistently)
    70  
    71      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435
    72      - linters:
    73          - gocritic
    74        text: "ifElseChain: rewrite if-else to switch statement"
    75  
    76      # Only packages listed here opt into the strict "exported symbols must be documented".
    77      #
    78      # Exclude texts from https://github.com/golangci/golangci-lint/blob/ab3c3cd69e602ff53bb4c3e2c188f0caeb80305d/pkg/config/issues.go#L11-L103
    79      - linters:
    80          - golint
    81          - revive
    82          - stylecheck
    83        text: comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form|comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form|exported (.+) should have comment( \(or a comment on this block\))? or be unexported|package comment should be of the form "(.+)...|comment on exported (.+) should be of the form "(.+)...|should have a package comment
    84        path-except: cmd/kubeadm
    85  
    86      # The following issues were deemed "might be worth fixing, needs to be
    87      # decided on a case-by-case basis".  This was initially decided by a
    88      # majority of the developers who voted in
    89      # https://github.com/kubernetes/kubernetes/issues/117288 and may evolve
    90      # over time.
    91  
    92      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
    93      - linters:
    94          - gocritic
    95        text: "assignOp:"
    96  
    97      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507016854
    98      - linters:
    99          - gosimple
   100        text: "S1002: should omit comparison to bool constant"
   101  
   102      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507023980
   103      - linters:
   104          - gosimple
   105        text: "S1016: should convert opts .* instead of using struct literal"
   106  
   107      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507026758
   108      - linters:
   109          - gosimple
   110        text: "S1033: unnecessary guard around call to delete"
   111  
   112      # Didn't make it into https://github.com/kubernetes/kubernetes/issues/117288.
   113      # Discussion on Slack concluded that "it's hard to have a universal policy for all
   114      # functions marked deprecated" and thus this can only be a hint which must
   115      # be considered on a case-by-case basis.
   116      - linters:
   117          - staticcheck
   118        text: "SA1019: .*is deprecated"
   119  
   120      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507030071
   121      - linters:
   122          - stylecheck
   123        text: "ST1012: error var .* should have name of the form ErrFoo"
   124  
   125      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507031224
   126      - linters:
   127          - stylecheck
   128        text: "ST1023: should omit type .* from declaration; it will be inferred from the right-hand side"
   129  
   130  linters:
   131    disable-all: true
   132    enable: # please keep this alphabetized
   133      - forbidigo
   134      - ginkgolinter
   135      - gocritic
   136      - govet
   137      - ineffassign
   138      - logcheck
   139      - revive
   140      - staticcheck
   141      - stylecheck
   142      - unused
   143  
   144  linters-settings: # please keep this alphabetized
   145    custom:
   146      logcheck:
   147        # Installed there by hack/verify-golangci-lint.sh.
   148        path: ../_output/local/bin/logcheck.so
   149        description: structured logging checker
   150        original-url: k8s.io/logtools/logcheck
   151        settings:
   152          config: |
   153            # hack/logcheck.conf contains regular expressions that are matched against <pkg>/<file>,
   154            # for example k8s.io/cmd/kube-scheduler/app/config/config.go.
   155            #
   156            # By default, structured logging call parameters are checked, but usage of
   157            # those calls is not required. That is changed on a per-file basis.
   158            #
   159            # Remember to clean the golangci-lint cache when changing the configuration and
   160            # running the verify-golangci-lint.sh script multiple times, otherwise
   161            # golangci-lint will report stale results:
   162            #    _output/local/bin/golangci-lint cache clean
   163            
   164            # At this point we don't enforce the usage structured logging calls except in
   165            # those packages that were migrated. This disables the check for other files.
   166            -structured .*
   167            
   168            # Now enable it again for migrated packages.
   169            structured k8s.io/kubernetes/cmd/kubelet/.*
   170            structured k8s.io/kubernetes/pkg/kubelet/.*
   171            structured k8s.io/kubernetes/pkg/proxy/.*
   172            structured k8s.io/kms/.*
   173            structured k8s.io/apiserver/pkg/storage/value/.*
   174            structured k8s.io/apiserver/pkg/server/options/encryptionconfig/.*
   175            
   176            # The following packages have been migrated to contextual logging.
   177            # Packages matched here do not have to be listed above because
   178            # "contextual" implies "structured".
   179            contextual k8s.io/api/.*
   180            contextual k8s.io/apimachinery/pkg/util/runtime/.*
   181            contextual k8s.io/client-go/metadata/.*
   182            contextual k8s.io/client-go/tools/events/.*
   183            contextual k8s.io/client-go/tools/record/.*
   184            contextual k8s.io/component-helpers/.*
   185            contextual k8s.io/cri-api/.*
   186            contextual k8s.io/cri-client/.*
   187            contextual k8s.io/dynamic-resource-allocation/.*
   188            contextual k8s.io/endpointslice/.*
   189            contextual k8s.io/kms/.*
   190            contextual k8s.io/kube-controller-manager/.*
   191            contextual k8s.io/kube-proxy/.*
   192            contextual k8s.io/kube-scheduler/.*
   193            contextual k8s.io/sample-apiserver/.*
   194            contextual k8s.io/sample-cli-plugin/.*
   195            contextual k8s.io/sample-controller/.*
   196            contextual k8s.io/kubernetes/cmd/kube-proxy/.*
   197            contextual k8s.io/kubernetes/cmd/kube-scheduler/.*
   198            contextual k8s.io/kubernetes/pkg/controller/.*
   199            contextual k8s.io/kubernetes/pkg/scheduler/.*
   200            contextual k8s.io/kubernetes/test/e2e/dra/.*
   201            
   202            # As long as contextual logging is alpha or beta, all WithName, WithValues,
   203            # NewContext calls have to go through klog. Once it is GA, we can lift
   204            # this restriction. Whether we then do a global search/replace remains
   205            # to be decided.
   206            with-helpers .*
   207    forbidigo:
   208      analyze-types: true
   209      forbid:
   210      - p: ^managedfields\.ExtractInto$
   211        pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
   212        msg: should not be used because managedFields was removed
   213      - p: \.Extract
   214        pkg: ^k8s\.io/client-go/applyconfigurations/
   215        msg: should not be used because managedFields was removed
   216    gocritic:
   217      enabled-checks:
   218        - equalFold
   219        - boolExprSimplify
   220    revive:
   221      # Only these rules are enabled.
   222      rules:
   223        - name: exported
   224          arguments:
   225          - disableStutteringCheck
   226    staticcheck:
   227      checks:
   228        - "all"
   229        - "-SA1019"  # TODO(fix) Using a deprecated function, variable, constant or field
   230        - "-SA2002"  # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed
   231    stylecheck:
   232      checks:
   233        - "ST1019"   # Importing the same package multiple times