...

Text file src/k8s.io/kubernetes/hack/golangci-strict.yaml

Documentation: k8s.io/kubernetes/hack

     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
    16run:
    17  timeout: 30m
    18  skip-files:
    19    - "^zz_generated.*"
    20
    21output:
    22  sort-results: true
    23
    24issues:
    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
   124linters:
   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
   141linters-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/client-go/metadata/.*
   177          contextual k8s.io/client-go/tools/events/.*
   178          contextual k8s.io/client-go/tools/record/.*
   179          contextual k8s.io/dynamic-resource-allocation/.*
   180          contextual k8s.io/kubernetes/cmd/kube-proxy/.*
   181          contextual k8s.io/kubernetes/cmd/kube-scheduler/.*
   182          contextual k8s.io/kubernetes/pkg/controller/.*
   183          contextual k8s.io/kubernetes/pkg/scheduler/.*
   184          contextual k8s.io/kubernetes/test/e2e/dra/.*
   185          
   186          # As long as contextual logging is alpha or beta, all WithName, WithValues,
   187          # NewContext calls have to go through klog. Once it is GA, we can lift
   188          # this restriction. Whether we then do a global search/replace remains
   189          # to be decided.
   190          with-helpers .*
   191  forbidigo:
   192    analyze-types: true
   193    forbid:
   194    - p: ^managedfields\.ExtractInto$
   195      pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
   196      msg: should not be used because managedFields was removed
   197    - p: \.Extract
   198      pkg: ^k8s\.io/client-go/applyconfigurations/
   199      msg: should not be used because managedFields was removed
   200  revive:
   201    # Only these rules are enabled.
   202    rules:
   203      - name: exported
   204        arguments:
   205        - disableStutteringCheck
   206  staticcheck:
   207    checks:
   208      - "all"

View as plain text