govet: add a warning about the deprecation of check-shadowing (#4535)
This commit is contained in:
		
							parent
							
								
									cba35e1d53
								
							
						
					
					
						commit
						3dbe882839
					
				@ -1074,40 +1074,6 @@ linters-settings:
 | 
				
			|||||||
      - Katakana
 | 
					      - Katakana
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  govet:
 | 
					  govet:
 | 
				
			||||||
    # Report about shadowed variables.
 | 
					 | 
				
			||||||
    # Default: false
 | 
					 | 
				
			||||||
    check-shadowing: true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Settings per analyzer.
 | 
					 | 
				
			||||||
    settings:
 | 
					 | 
				
			||||||
      # Analyzer name, run `go tool vet help` to see all analyzers.
 | 
					 | 
				
			||||||
      printf:
 | 
					 | 
				
			||||||
        # Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
 | 
					 | 
				
			||||||
        # Default: []
 | 
					 | 
				
			||||||
        funcs:
 | 
					 | 
				
			||||||
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
 | 
					 | 
				
			||||||
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
 | 
					 | 
				
			||||||
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
 | 
					 | 
				
			||||||
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
 | 
					 | 
				
			||||||
      shadow:
 | 
					 | 
				
			||||||
        # Whether to be strict about shadowing; can be noisy.
 | 
					 | 
				
			||||||
        # Default: false
 | 
					 | 
				
			||||||
        strict: true
 | 
					 | 
				
			||||||
      unusedresult:
 | 
					 | 
				
			||||||
        # Comma-separated list of functions whose results must be used
 | 
					 | 
				
			||||||
        # (in addition to default:
 | 
					 | 
				
			||||||
        #   context.WithCancel, context.WithDeadline, context.WithTimeout, context.WithValue, errors.New, fmt.Errorf,
 | 
					 | 
				
			||||||
        #   fmt.Sprint, fmt.Sprintf, sort.Reverse
 | 
					 | 
				
			||||||
        # ).
 | 
					 | 
				
			||||||
        # Default: []
 | 
					 | 
				
			||||||
        funcs:
 | 
					 | 
				
			||||||
          - pkg.MyFunc
 | 
					 | 
				
			||||||
        # Comma-separated list of names of methods of type func() string whose results must be used
 | 
					 | 
				
			||||||
        # (in addition to default Error,String)
 | 
					 | 
				
			||||||
        # Default: []
 | 
					 | 
				
			||||||
        stringmethods:
 | 
					 | 
				
			||||||
          - MyMethod
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Disable all analyzers.
 | 
					    # Disable all analyzers.
 | 
				
			||||||
    # Default: false
 | 
					    # Default: false
 | 
				
			||||||
    disable-all: true
 | 
					    disable-all: true
 | 
				
			||||||
@ -1214,6 +1180,36 @@ linters-settings:
 | 
				
			|||||||
      - unusedresult
 | 
					      - unusedresult
 | 
				
			||||||
      - unusedwrite
 | 
					      - unusedwrite
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Settings per analyzer.
 | 
				
			||||||
 | 
					    settings:
 | 
				
			||||||
 | 
					      # Analyzer name, run `go tool vet help` to see all analyzers.
 | 
				
			||||||
 | 
					      printf:
 | 
				
			||||||
 | 
					        # Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
 | 
				
			||||||
 | 
					        # Default: []
 | 
				
			||||||
 | 
					        funcs:
 | 
				
			||||||
 | 
					          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
 | 
				
			||||||
 | 
					          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
 | 
				
			||||||
 | 
					          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
 | 
				
			||||||
 | 
					          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
 | 
				
			||||||
 | 
					      shadow:
 | 
				
			||||||
 | 
					        # Whether to be strict about shadowing; can be noisy.
 | 
				
			||||||
 | 
					        # Default: false
 | 
				
			||||||
 | 
					        strict: true
 | 
				
			||||||
 | 
					      unusedresult:
 | 
				
			||||||
 | 
					        # Comma-separated list of functions whose results must be used
 | 
				
			||||||
 | 
					        # (in addition to default:
 | 
				
			||||||
 | 
					        #   context.WithCancel, context.WithDeadline, context.WithTimeout, context.WithValue, errors.New, fmt.Errorf,
 | 
				
			||||||
 | 
					        #   fmt.Sprint, fmt.Sprintf, sort.Reverse
 | 
				
			||||||
 | 
					        # ).
 | 
				
			||||||
 | 
					        # Default: []
 | 
				
			||||||
 | 
					        funcs:
 | 
				
			||||||
 | 
					          - pkg.MyFunc
 | 
				
			||||||
 | 
					        # Comma-separated list of names of methods of type func() string whose results must be used
 | 
				
			||||||
 | 
					        # (in addition to default Error,String)
 | 
				
			||||||
 | 
					        # Default: []
 | 
				
			||||||
 | 
					        stringmethods:
 | 
				
			||||||
 | 
					          - MyMethod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  grouper:
 | 
					  grouper:
 | 
				
			||||||
    # Require the use of a single global 'const' declaration only.
 | 
					    # Require the use of a single global 'const' declaration only.
 | 
				
			||||||
    # Default: false
 | 
					    # Default: false
 | 
				
			||||||
 | 
				
			|||||||
@ -155,6 +155,8 @@ issues:
 | 
				
			|||||||
    - path: pkg/commands/run.go
 | 
					    - path: pkg/commands/run.go
 | 
				
			||||||
      linters: [staticcheck]
 | 
					      linters: [staticcheck]
 | 
				
			||||||
      text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
 | 
					      text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
 | 
				
			||||||
 | 
					    - path: pkg/golinters/govet.go
 | 
				
			||||||
 | 
					      text: "SA1019: settings.CheckShadowing is deprecated: the linter should be enabled inside `Enable`."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    - path: pkg/golinters/gofumpt.go
 | 
					    - path: pkg/golinters/gofumpt.go
 | 
				
			||||||
      linters: [staticcheck]
 | 
					      linters: [staticcheck]
 | 
				
			||||||
 | 
				
			|||||||
@ -1661,11 +1661,6 @@
 | 
				
			|||||||
          "type": "object",
 | 
					          "type": "object",
 | 
				
			||||||
          "additionalProperties": false,
 | 
					          "additionalProperties": false,
 | 
				
			||||||
          "properties": {
 | 
					          "properties": {
 | 
				
			||||||
            "check-shadowing": {
 | 
					 | 
				
			||||||
              "description": "Report shadowed variables.",
 | 
					 | 
				
			||||||
              "type": "boolean",
 | 
					 | 
				
			||||||
              "default": true
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            "settings": {
 | 
					            "settings": {
 | 
				
			||||||
              "description": "Settings per analyzer. Map of analyzer name to specific settings.\nRun `go tool vet help` to find out more.",
 | 
					              "description": "Settings per analyzer. Map of analyzer name to specific settings.\nRun `go tool vet help` to find out more.",
 | 
				
			||||||
              "type": "object",
 | 
					              "type": "object",
 | 
				
			||||||
 | 
				
			|||||||
@ -599,13 +599,16 @@ type GosmopolitanSettings struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type GovetSettings struct {
 | 
					type GovetSettings struct {
 | 
				
			||||||
	Go string `mapstructure:"-"`
 | 
						Go string `mapstructure:"-"`
 | 
				
			||||||
	CheckShadowing bool   `mapstructure:"check-shadowing"`
 | 
					 | 
				
			||||||
	Settings       map[string]map[string]any
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Enable     []string
 | 
						Enable     []string
 | 
				
			||||||
	Disable    []string
 | 
						Disable    []string
 | 
				
			||||||
	EnableAll  bool `mapstructure:"enable-all"`
 | 
						EnableAll  bool `mapstructure:"enable-all"`
 | 
				
			||||||
	DisableAll bool `mapstructure:"disable-all"`
 | 
						DisableAll bool `mapstructure:"disable-all"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Settings map[string]map[string]any
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Deprecated: the linter should be enabled inside `Enable`.
 | 
				
			||||||
 | 
						CheckShadowing bool `mapstructure:"check-shadowing"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (cfg *GovetSettings) Validate() error {
 | 
					func (cfg *GovetSettings) Validate() error {
 | 
				
			||||||
 | 
				
			|||||||
@ -322,6 +322,13 @@ func (l *Loader) handleDeprecation() error {
 | 
				
			|||||||
		l.cfg.Output.Formats = f
 | 
							l.cfg.Output.Formats = f
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Deprecated since v1.57.0,
 | 
				
			||||||
 | 
						// but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
 | 
				
			||||||
 | 
						if l.cfg.LintersSettings.Govet.CheckShadowing {
 | 
				
			||||||
 | 
							l.warn("The configuration option `govet.check-shadowing` is deprecated. " +
 | 
				
			||||||
 | 
								"Please enable `shadow` instead, if you are not using `enable-all`.")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								test/testdata/configs/govet.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								test/testdata/configs/govet.yml
									
									
									
									
										vendored
									
									
								
							@ -1,3 +1,4 @@
 | 
				
			|||||||
linters-settings:
 | 
					linters-settings:
 | 
				
			||||||
  govet:
 | 
					  govet:
 | 
				
			||||||
    check-shadowing: true
 | 
					    enable:
 | 
				
			||||||
 | 
					      - shadow
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user