mirror of
https://github.com/harness/drone.git
synced 2025-05-04 01:11:59 +08:00
feat: [CODE-3149]: minor optimization of golangci-lint config, upgrade the linter version (#3382)
* Merge branch 'eb/code-3149' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into eb/code-3149 * include whole file * feat:[CODE-3149]: add ok to ignore for shadow declarations (#3394) * feat:[CODE-3149]: add ok to ignore for shadow declarations * requested changes * branch linting added * minor optimization of golangci-lint config, upgrade the linter version
This commit is contained in:
parent
49b0763130
commit
f11b24e08a
102
.golangci.yml
102
.golangci.yml
@ -1,22 +1,8 @@
|
|||||||
## Golden config for golangci-lint v1.49.0
|
## Golden config for golangci-lint v1.49.0
|
||||||
|
|
||||||
run:
|
|
||||||
# Timeout for analysis, e.g. 30s, 5m.
|
|
||||||
# Default: 1m
|
|
||||||
timeout: 3m
|
|
||||||
|
|
||||||
|
|
||||||
# This file contains only configs which differ from defaults.
|
# This file contains only configs which differ from defaults.
|
||||||
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
|
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
|
||||||
linters-settings:
|
linters-settings:
|
||||||
cyclop:
|
|
||||||
# The maximal code complexity to report.
|
|
||||||
# Default: 10
|
|
||||||
max-complexity: 30
|
|
||||||
# The maximal average package complexity.
|
|
||||||
# If it's higher than 0.0 (float) the check is enabled
|
|
||||||
# Default: 0.0
|
|
||||||
package-average: 10.0
|
|
||||||
|
|
||||||
errcheck:
|
errcheck:
|
||||||
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
|
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
|
||||||
@ -24,16 +10,6 @@ linters-settings:
|
|||||||
# Default: false
|
# Default: false
|
||||||
check-type-assertions: true
|
check-type-assertions: true
|
||||||
|
|
||||||
funlen:
|
|
||||||
# Checks the number of lines in a function.
|
|
||||||
# If lower than 0, disable the check.
|
|
||||||
# Default: 60
|
|
||||||
lines: 100
|
|
||||||
# Checks the number of statements in a function.
|
|
||||||
# If lower than 0, disable the check.
|
|
||||||
# Default: 40
|
|
||||||
statements: 50
|
|
||||||
|
|
||||||
gocritic:
|
gocritic:
|
||||||
# Settings passed to gocritic.
|
# Settings passed to gocritic.
|
||||||
# The settings key is the name of a supported gocritic checker.
|
# The settings key is the name of a supported gocritic checker.
|
||||||
@ -48,26 +24,6 @@ linters-settings:
|
|||||||
# Default: true
|
# Default: true
|
||||||
skipRecvDeref: false
|
skipRecvDeref: false
|
||||||
|
|
||||||
gomnd:
|
|
||||||
# List of function patterns to exclude from analysis.
|
|
||||||
# Values always ignored: `time.Date`
|
|
||||||
# Default: []
|
|
||||||
ignored-functions:
|
|
||||||
- os.Chmod
|
|
||||||
- os.Mkdir
|
|
||||||
- os.MkdirAll
|
|
||||||
- os.OpenFile
|
|
||||||
- os.WriteFile
|
|
||||||
- prometheus.ExponentialBuckets
|
|
||||||
- prometheus.ExponentialBucketsRange
|
|
||||||
- prometheus.LinearBuckets
|
|
||||||
- strconv.FormatFloat
|
|
||||||
- strconv.FormatInt
|
|
||||||
- strconv.FormatUint
|
|
||||||
- strconv.ParseFloat
|
|
||||||
- strconv.ParseInt
|
|
||||||
- strconv.ParseUint
|
|
||||||
|
|
||||||
gomodguard:
|
gomodguard:
|
||||||
blocked:
|
blocked:
|
||||||
# List of blocked modules.
|
# List of blocked modules.
|
||||||
@ -188,31 +144,24 @@ linters:
|
|||||||
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
|
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
|
||||||
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
|
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
|
||||||
- unused # checks for unused constants, variables, functions and types
|
- unused # checks for unused constants, variables, functions and types
|
||||||
|
|
||||||
## disabled by default
|
## disabled by default
|
||||||
- asasalint # checks for pass []any as any in variadic func(...any)
|
- asasalint # checks for pass []any as any in variadic func(...any)
|
||||||
- asciicheck # checks that your code does not contain non-ASCII identifiers
|
- asciicheck # checks that your code does not contain non-ASCII identifiers
|
||||||
- bidichk # checks for dangerous unicode character sequences
|
- bidichk # checks for dangerous unicode character sequences
|
||||||
- bodyclose # checks whether HTTP response body is closed successfully
|
- bodyclose # checks whether HTTP response body is closed successfully
|
||||||
#- contextcheck # checks the function whether use a non-inherited context # TODO: enable after golangci-lint uses https://github.com/sylvia7788/contextcheck/releases/tag/v1.0.7
|
- contextcheck # checks the function whether use a non-inherited context
|
||||||
- cyclop # checks function and package cyclomatic complexity
|
|
||||||
# - dupl # tool for code clone detection
|
# - dupl # tool for code clone detection
|
||||||
- durationcheck # checks for two durations multiplied together
|
- durationcheck # checks for two durations multiplied together
|
||||||
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
|
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
|
||||||
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
|
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
|
||||||
- execinquery # checks query string in Query function which reads your Go src files and warning it finds
|
|
||||||
- exhaustive # checks exhaustiveness of enum switch statements
|
- exhaustive # checks exhaustiveness of enum switch statements
|
||||||
- exportloopref # checks for pointers to enclosing loop variables
|
- copyloopvar # linter detects places where loop variables are copied
|
||||||
- forbidigo # forbids identifiers
|
- forbidigo # forbids identifiers
|
||||||
#- funlen # tool for detection of long functions
|
|
||||||
#- gochecknoglobals # checks that no global variables exist
|
|
||||||
#- gochecknoinits # checks that no init functions are present in Go code
|
|
||||||
- gocognit # computes and checks the cognitive complexity of functions
|
|
||||||
- goconst # finds repeated strings that could be replaced by a constant
|
- goconst # finds repeated strings that could be replaced by a constant
|
||||||
- gocritic # provides diagnostics that check for bugs, performance and style issues
|
- gocritic # provides diagnostics that check for bugs, performance and style issues
|
||||||
- gocyclo # computes and checks the cyclomatic complexity of functions
|
|
||||||
- godot # checks if comments end in a period
|
- godot # checks if comments end in a period
|
||||||
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
|
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
|
||||||
- gomnd # detects magic numbers
|
|
||||||
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
|
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
|
||||||
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
|
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations
|
||||||
- goprintffuncname # checks that printf-like functions are named with f at the end
|
- goprintffuncname # checks that printf-like functions are named with f at the end
|
||||||
@ -224,7 +173,6 @@ linters:
|
|||||||
- nilerr # finds the code that returns nil even if it checks that the error is not nil
|
- nilerr # finds the code that returns nil even if it checks that the error is not nil
|
||||||
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
|
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
|
||||||
- noctx # finds sending http request without context.Context
|
- noctx # finds sending http request without context.Context
|
||||||
# - nolintlint # reports ill-formed or insufficient nolint directives
|
|
||||||
# - nonamedreturns # reports all named returns
|
# - nonamedreturns # reports all named returns
|
||||||
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
|
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
|
||||||
- predeclared # finds code that shadows one of Go's predeclared identifiers
|
- predeclared # finds code that shadows one of Go's predeclared identifiers
|
||||||
@ -236,7 +184,6 @@ linters:
|
|||||||
- stylecheck # is a replacement for golint
|
- stylecheck # is a replacement for golint
|
||||||
- tagliatelle # checks the struct tags
|
- tagliatelle # checks the struct tags
|
||||||
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
|
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
|
||||||
#- testpackage # makes you use a separate _test package
|
|
||||||
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
|
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
|
||||||
- unconvert # removes unnecessary type conversions
|
- unconvert # removes unnecessary type conversions
|
||||||
- unparam # reports unused function parameters
|
- unparam # reports unused function parameters
|
||||||
@ -250,40 +197,16 @@ linters:
|
|||||||
- gci # controls golang package import order and makes it always deterministic
|
- gci # controls golang package import order and makes it always deterministic
|
||||||
#- godox # detects FIXME, TODO and other comment keywords
|
#- godox # detects FIXME, TODO and other comment keywords
|
||||||
- goheader # checks is file header matches to pattern
|
- goheader # checks is file header matches to pattern
|
||||||
#- interfacebloat # checks the number of methods inside an interface
|
|
||||||
#- ireturn # accept interfaces, return concrete types
|
|
||||||
#- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
|
|
||||||
#- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
|
|
||||||
#- wrapcheck # checks that errors returned from external packages are wrapped
|
|
||||||
|
|
||||||
## disabled
|
|
||||||
#- containedctx # detects struct contained context.Context field
|
|
||||||
#- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
|
|
||||||
#- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
|
||||||
#- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/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
|
|
||||||
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
|
|
||||||
#- goerr113 # [too strict] checks the errors handling expressions
|
|
||||||
#- gofmt # [replaced by goimports] checks whether code was gofmt-ed
|
|
||||||
#- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed
|
|
||||||
#- grouper # analyzes expression groups
|
|
||||||
#- importas # enforces consistent import aliases
|
|
||||||
#- logrlint # [owner archived repository] checks logr arguments
|
|
||||||
#- maintidx # measures the maintainability index of each function
|
|
||||||
- misspell # [useless] finds commonly misspelled English words in comments
|
- misspell # [useless] finds commonly misspelled English words in comments
|
||||||
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
|
|
||||||
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
|
|
||||||
#- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
|
|
||||||
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
|
|
||||||
|
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Maximum count of issues with the same text.
|
# Maximum count of issues with the same text.
|
||||||
# Set to 0 to disable.
|
# Set to 0 to disable.
|
||||||
# Default: 3
|
# Default: 3
|
||||||
max-same-issues: 50
|
max-same-issues: 10
|
||||||
|
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- text: 'shadow: declaration of "(err|ctx)" shadows declaration at'
|
- text: 'shadow: declaration of "(err|ctx|ok)" shadows declaration at'
|
||||||
linters: [ govet ]
|
linters: [ govet ]
|
||||||
- source: "^//\\s*go:generate\\s"
|
- source: "^//\\s*go:generate\\s"
|
||||||
linters: [ lll ]
|
linters: [ lll ]
|
||||||
@ -307,7 +230,7 @@ issues:
|
|||||||
- path: "^registry/app/driver/filesystem/.*"
|
- path: "^registry/app/driver/filesystem/.*"
|
||||||
linters: [ gocritic ]
|
linters: [ gocritic ]
|
||||||
- path: "^registry/app/driver/s3-aws/.*"
|
- path: "^registry/app/driver/s3-aws/.*"
|
||||||
linters: [ gocognit, gocyclo, gosec, nestif, cyclop]
|
linters: [ gocognit, gosec, nestif]
|
||||||
- path: "^registry/app/remote/clients/registry/interceptor/interceptor.go"
|
- path: "^registry/app/remote/clients/registry/interceptor/interceptor.go"
|
||||||
linters: [ goheader ]
|
linters: [ goheader ]
|
||||||
- path: "^registry/app/common/http/modifier/modifier.go"
|
- path: "^registry/app/common/http/modifier/modifier.go"
|
||||||
@ -492,16 +415,3 @@ issues:
|
|||||||
linters: [ goheader ]
|
linters: [ goheader ]
|
||||||
- path: "^registry/app/storage/blobStore.go"
|
- path: "^registry/app/storage/blobStore.go"
|
||||||
linters: [ gosec ]
|
linters: [ gosec ]
|
||||||
#Registry Specific ends
|
|
||||||
- text: "mnd: Magic number: \\d"
|
|
||||||
linters:
|
|
||||||
- gomnd
|
|
||||||
- path: "_test\\.go"
|
|
||||||
linters:
|
|
||||||
- bodyclose
|
|
||||||
- dupl
|
|
||||||
- funlen
|
|
||||||
- goconst
|
|
||||||
- gosec
|
|
||||||
- noctx
|
|
||||||
- wrapcheck
|
|
13
Makefile
13
Makefile
@ -102,10 +102,19 @@ sec:
|
|||||||
@echo "Vulnerability detection $(1)"
|
@echo "Vulnerability detection $(1)"
|
||||||
@govulncheck ./...
|
@govulncheck ./...
|
||||||
|
|
||||||
lint: tools generate # lint the golang code
|
lint: tools generate # lint the golang code - CI
|
||||||
|
@echo "Linting $(1)"
|
||||||
|
@golangci-lint run --timeout=3m --verbose --new-from-rev=HEAD~
|
||||||
|
|
||||||
|
lint-full: tools generate # full linting the golang code
|
||||||
@echo "Linting $(1)"
|
@echo "Linting $(1)"
|
||||||
@golangci-lint run --timeout=3m --verbose
|
@golangci-lint run --timeout=3m --verbose
|
||||||
|
|
||||||
|
lint-local: tools generate # lint the golang code - only untracked and staged changes
|
||||||
|
@echo "Linting $(1)"
|
||||||
|
@golangci-lint run --new --timeout=3m --verbose --whole-files
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Code Generation
|
# Code Generation
|
||||||
#
|
#
|
||||||
@ -139,7 +148,7 @@ delete-tools: ## Delete the tools
|
|||||||
# Install golangci-lint
|
# Install golangci-lint
|
||||||
$(GOBIN)/golangci-lint:
|
$(GOBIN)/golangci-lint:
|
||||||
@echo "🔘 Installing golangci-lint... (`date '+%H:%M:%S'`)"
|
@echo "🔘 Installing golangci-lint... (`date '+%H:%M:%S'`)"
|
||||||
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.56.2
|
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.63.4
|
||||||
|
|
||||||
# Install goimports to format code
|
# Install goimports to format code
|
||||||
$(GOBIN)/goimports:
|
$(GOBIN)/goimports:
|
||||||
|
Loading…
Reference in New Issue
Block a user