k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/golangci-strict.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      # The Kubernetes naming convention for conversion functions uses underscores
    50      # and intentionally deviates from normal Go conventions to make those function
    51      # names more readable. Same for SetDefaults_*.
    52      #
    53      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627
    54      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592
    55      - linters:
    56          - stylecheck
    57          - revive
    58        text: "(ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)|exported: exported function (Convert|SetDefaults)_.* should be of the form)"
    59  
    60      # This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91).
    61      - linters:
    62         - ginkgolinter
    63        text: use a function call in (Eventually|Consistently)
    64  
    65      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435
    66      - linters:
    67          - gocritic
    68        text: "ifElseChain: rewrite if-else to switch statement"
    69  
    70      # Only packages listed here opt into the strict "exported symbols must be documented".
    71      #
    72      # Exclude texts from https://github.com/golangci/golangci-lint/blob/ab3c3cd69e602ff53bb4c3e2c188f0caeb80305d/pkg/config/issues.go#L11-L103
    73      - linters:
    74          - golint
    75          - revive
    76          - stylecheck
    77        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
    78        path-except: cmd/kubeadm
    79  
    80      # The following issues were deemed "might be worth fixing, needs to be
    81      # decided on a case-by-case basis".  This was initially decided by a
    82      # majority of the developers who voted in
    83      # https://github.com/kubernetes/kubernetes/issues/117288 and may evolve
    84      # over time.
    85  
    86      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
    87      - linters:
    88          - gocritic
    89        text: "assignOp:"
    90  
    91      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507016854
    92      - linters:
    93          - gosimple
    94        text: "S1002: should omit comparison to bool constant"
    95  
    96      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507023980
    97      - linters:
    98          - gosimple
    99        text: "S1016: should convert opts .* instead of using struct literal"
   100  
   101      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507026758
   102      - linters:
   103          - gosimple
   104        text: "S1033: unnecessary guard around call to delete"
   105  
   106      # Didn't make it into https://github.com/kubernetes/kubernetes/issues/117288.
   107      # Discussion on Slack concluded that "it's hard to have a universal policy for all
   108      # functions marked deprecated" and thus this can only be a hint which must
   109      # be considered on a case-by-case basis.
   110      - linters:
   111          - staticcheck
   112        text: "SA1019: .*is deprecated"
   113  
   114      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507030071
   115      - linters:
   116          - stylecheck
   117        text: "ST1012: error var .* should have name of the form ErrFoo"
   118  
   119      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507031224
   120      - linters:
   121          - stylecheck
   122        text: "ST1023: should omit type .* from declaration; it will be inferred from the right-hand side"
   123  
   124  linters:
   125    disable-all: false
   126    enable: # please keep this alphabetized
   127      - forbidigo
   128      - ginkgolinter
   129      - gocritic
   130      - govet
   131      - ineffassign
   132      - logcheck
   133      - revive
   134      - staticcheck
   135      - stylecheck
   136      - unused
   137    disable:
   138      # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008359
   139      - errcheck
   140  
   141  linters-settings: # please keep this alphabetized
   142    custom:
   143      logcheck:
   144        # Installed there by hack/verify-golangci-lint.sh.
   145        path: ../_output/local/bin/logcheck.so
   146        description: structured logging checker
   147        original-url: k8s.io/logtools/logcheck
   148        settings:
   149          config: |
   150            # hack/logcheck.conf contains regular expressions that are matched against <pkg>/<file>,
   151            # for example k8s.io/cmd/kube-scheduler/app/config/config.go.
   152            #
   153            # By default, structured logging call parameters are checked, but usage of
   154            # those calls is not required. That is changed on a per-file basis.
   155            #
   156            # Remember to clean the golangci-lint cache when changing the configuration and
   157            # running the verify-golangci-lint.sh script multiple times, otherwise
   158            # golangci-lint will report stale results:
   159            #    _output/local/bin/golangci-lint cache clean
   160            
   161            # At this point we don't enforce the usage structured logging calls except in
   162            # those packages that were migrated. This disables the check for other files.
   163            -structured .*
   164            
   165            # Now enable it again for migrated packages.
   166            structured k8s.io/kubernetes/cmd/kubelet/.*
   167            structured k8s.io/kubernetes/pkg/kubelet/.*
   168            structured k8s.io/kubernetes/pkg/proxy/.*
   169            structured k8s.io/kms/.*
   170            structured k8s.io/apiserver/pkg/storage/value/.*
   171            structured k8s.io/apiserver/pkg/server/options/encryptionconfig/.*
   172            
   173            # The following packages have been migrated to contextual logging.
   174            # Packages matched here do not have to be listed above because
   175            # "contextual" implies "structured".
   176            contextual k8s.io/api/.*
   177            contextual k8s.io/apimachinery/pkg/util/runtime/.*
   178            contextual k8s.io/client-go/metadata/.*
   179            contextual k8s.io/client-go/tools/events/.*
   180            contextual k8s.io/client-go/tools/record/.*
   181            contextual k8s.io/component-helpers/.*
   182            contextual k8s.io/cri-api/.*
   183            contextual k8s.io/cri-client/.*
   184            contextual k8s.io/dynamic-resource-allocation/.*
   185            contextual k8s.io/endpointslice/.*
   186            contextual k8s.io/kms/.*
   187            contextual k8s.io/kube-controller-manager/.*
   188            contextual k8s.io/kube-proxy/.*
   189            contextual k8s.io/kube-scheduler/.*
   190            contextual k8s.io/sample-apiserver/.*
   191            contextual k8s.io/sample-cli-plugin/.*
   192            contextual k8s.io/sample-controller/.*
   193            contextual k8s.io/kubernetes/cmd/kube-proxy/.*
   194            contextual k8s.io/kubernetes/cmd/kube-scheduler/.*
   195            contextual k8s.io/kubernetes/pkg/controller/.*
   196            contextual k8s.io/kubernetes/pkg/scheduler/.*
   197            contextual k8s.io/kubernetes/test/e2e/dra/.*
   198            
   199            # As long as contextual logging is alpha or beta, all WithName, WithValues,
   200            # NewContext calls have to go through klog. Once it is GA, we can lift
   201            # this restriction. Whether we then do a global search/replace remains
   202            # to be decided.
   203            with-helpers .*
   204    forbidigo:
   205      analyze-types: true
   206      forbid:
   207      - p: ^managedfields\.ExtractInto$
   208        pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
   209        msg: should not be used because managedFields was removed
   210      - p: \.Extract
   211        pkg: ^k8s\.io/client-go/applyconfigurations/
   212        msg: should not be used because managedFields was removed
   213    revive:
   214      # Only these rules are enabled.
   215      rules:
   216        - name: exported
   217          arguments:
   218          - disableStutteringCheck
   219    staticcheck:
   220      checks:
   221        - "all"