diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index be686a73c8c7..9bfa6efaef42 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,3 +8,12 @@ The updates happen at least automatically once a week (Sunday 11am UTC). No pull requests to update a linter will be accepted unless you are the author of the linter AND specific changes are required. --> + + diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 32b46fe168b1..1e4618407dd5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,6 +10,7 @@ updates: # Ignore forked linters because of their versioning issues. - dependency-name: "github.com/golangci/dupl" - dependency-name: "github.com/golangci/gofmt" + - dependency-name: "github.com/golangci/swaggoswag" - dependency-name: "github.com/golangci/unconvert" - package-ecosystem: github-actions directory: "/" @@ -37,6 +38,7 @@ updates: - "*" # Group all updates into a single larger pull request. - package-ecosystem: gomod directories: + - pkg/golinters/arangolint/testdata/ - pkg/golinters/ginkgolinter/testdata/ - pkg/golinters/loggercheck/testdata/ - pkg/golinters/protogetter/testdata/ diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index 380472037050..5f5606e97835 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -41,7 +41,7 @@ jobs: # - 1.18rc1 -> 1.18.0-rc.1 go-version: ${{ env.GO_VERSION }} - name: lint - uses: golangci/golangci-lint-action@v7.0.0 + uses: golangci/golangci-lint-action@v8.0.0 with: version: latest diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 37866ff00f2c..abc9c060efbe 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -10,13 +10,17 @@ version: "2" linters: # Default set of linters. - # The value can be: `standard`, `all`, `none`, or `fast`. + # The value can be: + # - `standard`: https://golangci-lint.run/usage/linters/#enabled-by-default + # - `all`: enables all linters by default. + # - `none`: disables all linters by default. + # - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`). # Default: standard default: all # Enable specific linter. - # https://golangci-lint.run/usage/linters/#enabled-by-default enable: + - arangolint - asasalint - asciicheck - bidichk @@ -32,6 +36,7 @@ linters: - dupl - dupword - durationcheck + - embeddedstructfieldcheck - err113 - errcheck - errchkjson @@ -86,6 +91,7 @@ linters: - nilnil - nlreturn - noctx + - noinlineerr - nolintlint - nonamedreturns - nosprintfhostport @@ -122,9 +128,9 @@ linters: - wsl - zerologlint - # Disable specific linter. - # https://golangci-lint.run/usage/linters/#disabled-by-default + # Disable specific linters. disable: + - arangolint - asasalint - asciicheck - bidichk @@ -140,6 +146,7 @@ linters: - dupl - dupword - durationcheck + - embeddedstructfieldcheck - err113 - errcheck - errchkjson @@ -194,6 +201,7 @@ linters: - nilnil - nlreturn - noctx + - noinlineerr - nolintlint - nonamedreturns - nosprintfhostport @@ -381,6 +389,11 @@ linters: ignore: - "0C0C" + embeddedstructfieldcheck: + # Checks that sync.Mutex and sync.RWMutex are not used as embedded fields. + # Default: false + forbid-mutex: true + errcheck: # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. # Such cases aren't reported by default. @@ -404,6 +417,10 @@ linters: - io.Copy(*bytes.Buffer) - io.Copy(os.Stdout) + # Display function signature instead of selector. + # Default: false + verbose: true + errchkjson: # With check-error-free-encoding set to true, errchkjson does warn about errors # from json encoding functions that are safe to be ignored, @@ -539,6 +556,9 @@ linters: # Checks if the exported methods of a structure are placed before the non-exported ones. # Default: true struct-method: false + # Checks if the constructors and/or structure methods are sorted alphabetically. + # Default: false + alphabetical: true funlen: # Checks the number of lines in a function. @@ -1597,6 +1617,8 @@ linters: - findcall # Report assembly that clobbers the frame pointer before saving it. - framepointer + # Check format of addresses passed to net.Dial. + - hostport # Report using Go 1.22 enhanced ServeMux patterns in older Go versions. - httpmux # Check for mistakes using HTTP responses. @@ -1680,6 +1702,7 @@ linters: - fieldalignment - findcall - framepointer + - hostport - httpmux - httpresponse - ifaceassert @@ -1774,6 +1797,7 @@ linters: - identical # Identifies interfaces in the same package that have identical method sets. - unused # Identifies interfaces that are not used anywhere in the same package where the interface is defined. - opaque # Identifies functions that return interfaces, but the actual returned value is always a single concrete implementation. + - unexported # Identifies interfaces that are not exported but are used in exported functions or methods. settings: unused: # List of packages path to exclude from the check. @@ -2567,7 +2591,7 @@ linters: severity: warning disabled: false exclude: [""] - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redundant-test-main-exit + # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#redundant-test-main-exit - name: redundant-test-main-exit severity: warning disabled: false @@ -2607,6 +2631,11 @@ linters: exclude: [""] arguments: - "preserve-scope" + # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#time-date + - name: time-date + severity: warning + disabled: false + exclude: [""] # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#time-equal - name: time-equal severity: warning @@ -2647,6 +2676,11 @@ linters: arguments: - "fmt.Printf" - "myFunction" + # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unnecessary-format + - name: unnecessary-format + severity: warning + disabled: false + exclude: [""] # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unnecessary-stmt - name: unnecessary-stmt severity: warning @@ -2681,6 +2715,11 @@ linters: severity: warning disabled: false exclude: [""] + # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#use-fmt-print + - name: use-fmt-print + severity: warning + disabled: false + exclude: [""] # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#useless-break - name: useless-break severity: warning @@ -3594,6 +3633,9 @@ linters: # Suggest the use of http.StatusXX. # Default: true http-status-code: false + # Suggest the use of time.Month in time.Date. + # Default: false + time-date-month: true # Suggest the use of time.Weekday.String(). # Default: true time-weekday: true @@ -3969,6 +4011,7 @@ formatters: - gofumpt - goimports - golines + - swaggo # Formatters settings. settings: @@ -4065,6 +4108,7 @@ formatters: # Default: lax generated: strict # Which file paths to exclude. + # This option is ignored when using `--stdin` as the path is unknown. # Default: [] paths: - ".*\\.my\\.go$" diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 37866ff00f2c..38b1d26ed729 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -10,12 +10,15 @@ version: "2" linters: # Default set of linters. - # The value can be: `standard`, `all`, `none`, or `fast`. + # The value can be: + # - `standard`: https://golangci-lint.run/usage/linters/#enabled-by-default + # - `all`: enables all linters by default. + # - `none`: disables all linters by default. + # - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`). # Default: standard default: all # Enable specific linter. - # https://golangci-lint.run/usage/linters/#enabled-by-default enable: - asasalint - asciicheck @@ -123,7 +126,6 @@ linters: - zerologlint # Disable specific linter. - # https://golangci-lint.run/usage/linters/#disabled-by-default disable: - asasalint - asciicheck @@ -2300,12 +2302,11 @@ linters: disabled: false exclude: [""] arguments: - - "call-chain" - - "loop" - - "method-call" - - "recover" - - "immediate-recover" - - "return" + - - "call-chain" + - "loop" + - "method-call" + - "recover" + - "return" # https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#dot-imports - name: dot-imports severity: warning diff --git a/.goreleaser.yml b/.goreleaser.yml index 98346da5f7fd..d40fb1a4a034 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -172,46 +172,6 @@ aurs: ./golangci-lint completion zsh | install -Dm644 /dev/stdin "${pkgdir}/usr/share/zsh/site-functions/_golangci-lint" ./golangci-lint completion fish | install -Dm644 /dev/stdin "${pkgdir}/usr/share/fish/vendor_completions.d/golangci-lint.fish" -aur_sources: - - description: Fast linters runner for Go. - skip_upload: false - homepage: https://golangci.com - provides: - - "golangci-lint" - maintainers: - - "Fernandez Ludovic " - license: GPL-3.0 - private_key: "{{ .Env.AUR_KEY }}" - git_url: "ssh://aur@aur.archlinux.org/golangci-lint.git" - commit_author: - name: golangci-releaser - email: 65486276+golangci-releaser@users.noreply.github.com - build: |- - local _commit _flags - _commit=$(bsdcat "${pkgname}_${pkgver}.tar.gz" | git get-tar-commit-id) - _flags=( - -X=main.version="$pkgver" - -X=main.commit="${_commit::7}" - -X=main.date="$(date -u -d "@${SOURCE_DATE_EPOCH}" +'%FT%TZ')" - -linkmode=external - ) - export CGO_ENABLED=1 - export CGO_CFLAGS="${CFLAGS}" - export CGO_CPPFLAGS="$CPPFLAGS" - export CGO_CXXFLAGS="$CXXFLAGS" - export CGO_LDFLAGS="${LDFLAGS}" - export GOFLAGS='-buildmode=pie -trimpath -modcacherw' - - go build -o "$pkgname" -ldflags="${_flags[*]}" ./cmd/"$pkgname" - ./"$pkgname" completion bash > completion.bash - ./"$pkgname" completion zsh > completion.zsh - ./"$pkgname" completion fish > completion.fish - package: |- - install -Dm755 "$pkgname" -t "$pkgdir"/usr/bin - install -Dm644 completion.bash "$pkgdir"/usr/share/bash-completion/completions/"$pkgname" - install -Dm644 completion.zsh "$pkgdir"/usr/share/zsh/site-functions/_"$pkgname" - install -Dm644 completion.fish "$pkgdir"/usr/share/fish/vendor_completions.d/"$pkgname".fish - snapcrafts: - summary: Fast linters runner for Go. description: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fe75cef256a..403a833fcb27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,20 @@ If you value it, consider supporting us, we appreciate it! ❤️ [![Open Collective backers and sponsors](https://img.shields.io/badge/OpenCollective-Donate-blue?logo=opencollective&style=for-the-badge)](https://opencollective.com/golangci-lint) [![GitHub Sponsors](https://img.shields.io/badge/GitHub-Donate-blue?logo=github&style=for-the-badge)](https://github.com/sponsors/golangci) +### v2.1.6 + +1. Linters bug fixes + * `godot`: from 1.5.0 to 1.5.1 + * `musttag`: from 0.13.0 to 0.13.1 +2. Documentation + * Add note about golangci-lint v2 integration in VS Code + +### v2.1.5 + +Due to an error related to Snapcraft, some artifacts of the v2.1.4 release have not been published. + +This release contains the same things as v2.1.3. + ### v2.1.4 Due to an error related to Snapcraft, some artifacts of the v2.1.3 release have not been published. diff --git a/assets/github-action-config-v2.json b/assets/github-action-config-v2.json index 99f2a6f8b3c9..2a099a8ff534 100644 --- a/assets/github-action-config-v2.json +++ b/assets/github-action-config-v2.json @@ -1,7 +1,7 @@ { "MinorVersionToConfig": { "latest": { - "TargetVersion": "v2.1.3" + "TargetVersion": "v2.1.6" }, "v1.10": { "Error": "golangci-lint version 'v1.10' isn't supported: we support only v2.0.0 and later versions" @@ -193,7 +193,7 @@ "TargetVersion": "v2.0.2" }, "v2.1": { - "TargetVersion": "v2.1.3" + "TargetVersion": "v2.1.6" } } } diff --git a/cmd/golangci-lint/main.go b/cmd/golangci-lint/main.go index f7f3091dc653..acb09cd8c0be 100644 --- a/cmd/golangci-lint/main.go +++ b/cmd/golangci-lint/main.go @@ -4,7 +4,9 @@ import ( "cmp" "fmt" "os" + "regexp" "runtime/debug" + "strings" "github.com/golangci/golangci-lint/v2/pkg/commands" "github.com/golangci/golangci-lint/v2/pkg/exitcodes" @@ -23,7 +25,7 @@ func main() { info := createBuildInfo() if err := commands.Execute(info); err != nil { - _, _ = fmt.Fprintf(os.Stderr, "Failed executing command with error: %v\n", err) + _, _ = fmt.Fprintf(os.Stderr, "The command is terminated due to an error: %v\n", err) os.Exit(exitcodes.Failure) } } @@ -49,6 +51,11 @@ func createBuildInfo() commands.BuildInfo { info.Version = buildInfo.Main.Version + matched, _ := regexp.MatchString(`v\d+\.\d+\.\d+`, buildInfo.Main.Version) + if matched { + info.Version = strings.TrimPrefix(buildInfo.Main.Version, "v") + } + var revision string var modified string for _, setting := range buildInfo.Settings { diff --git a/docs/package-lock.json b/docs/package-lock.json index 5693665902e0..ccf2b1809d7f 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -5885,9 +5885,10 @@ } }, "node_modules/base-x": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz", - "integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==", + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.11.tgz", + "integrity": "sha512-xz7wQ8xDhdyP7tQxwdteLYeFfS68tSMNCZ/Y37WJ4bhGfKPpqEIlmIyueQHqOyoPhE6xNUqjzRr8ra0eF9VRvA==", + "license": "MIT", "dependencies": { "safe-buffer": "^5.0.1" } @@ -28360,9 +28361,9 @@ } }, "base-x": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.9.tgz", - "integrity": "sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==", + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.11.tgz", + "integrity": "sha512-xz7wQ8xDhdyP7tQxwdteLYeFfS68tSMNCZ/Y37WJ4bhGfKPpqEIlmIyueQHqOyoPhE6xNUqjzRr8ra0eF9VRvA==", "requires": { "safe-buffer": "^5.0.1" } diff --git a/docs/src/docs/contributing/architecture.mdx b/docs/src/docs/contributing/architecture.mdx index e9df647556da..e398db57e4e8 100644 --- a/docs/src/docs/contributing/architecture.mdx +++ b/docs/src/docs/contributing/architecture.mdx @@ -222,7 +222,7 @@ The abstraction is simple: ```go title=pkg/result/processors/processor.go type Processor interface { - Process(issues []result.Issue) ([]result.Issue, error) + Process(issues []*result.Issue) ([]*result.Issue, error) Name() string Finish() } diff --git a/docs/src/docs/contributing/new-linters.mdx b/docs/src/docs/contributing/new-linters.mdx index 1e22d714a896..57654e887f89 100644 --- a/docs/src/docs/contributing/new-linters.mdx +++ b/docs/src/docs/contributing/new-linters.mdx @@ -43,5 +43,5 @@ Typically, these linters can't be open-sourced or too specific. Such linters can be added through 2 plugin systems: -1. [Module Plugin System](/plugins/module-plugins) +1. [Module Plugin System](/plugins/module-plugins) (Recommended) 2. [Go Plugin System](/plugins/go-plugins) diff --git a/docs/src/docs/plugins/go-plugins.mdx b/docs/src/docs/plugins/go-plugins.mdx index ce742b9bc62c..bf05d1fc92b4 100644 --- a/docs/src/docs/plugins/go-plugins.mdx +++ b/docs/src/docs/plugins/go-plugins.mdx @@ -2,6 +2,10 @@ title: Go Plugin System --- +**We recommend using [Module Plugin System](/plugins/module-plugins) instead of the Go Plugin System.** + +--- + Private linters can be added through [Go's plugin system](https://pkg.go.dev/plugin). For a private linter (which acts as a plugin) to work properly, diff --git a/docs/src/docs/plugins/module-plugins.mdx b/docs/src/docs/plugins/module-plugins.mdx index 9fa36766ebb6..f6e4ad77d2c1 100644 --- a/docs/src/docs/plugins/module-plugins.mdx +++ b/docs/src/docs/plugins/module-plugins.mdx @@ -9,7 +9,7 @@ An example linter can be found at [here](https://github.com/golangci/example-plu - Define your building configuration into `.custom-gcl.yml`. - Run the command `golangci-lint custom` (or `golangci-lint custom -v` to have logs). - Define the plugin inside the `linters.settings.custom` section with the type `module`. -- Run your custom version of golangci-lint. +- Run the resulting custom binary of golangci-lint (`./custom-gcl` by default). Requirements: - Go diff --git a/docs/src/docs/welcome/faq.mdx b/docs/src/docs/welcome/faq.mdx index 46e57aacdbaa..62109ac5afb7 100644 --- a/docs/src/docs/welcome/faq.mdx +++ b/docs/src/docs/welcome/faq.mdx @@ -33,7 +33,7 @@ it's just a way to identify, parse, and display compiling errors (produced by th It cannot be disabled because of that. -Of course, this is just as good as the compiler itself and a lot of compilation issues will not properly show where in the code your error lies. +Of course, this is just as good as the compiler itself, and a lot of compilation issues will not properly show where in the code your error lies. As a consequence, the code to analyze should compile. It means that if you try to run an analysis on a single file or a group of files or a package or a group of packages, @@ -45,10 +45,11 @@ If there are `typecheck` errors, golangci-lint will not be able to produce other How to troubleshoot: - [ ] Ensure the version of golangci-lint is built with a compatible version of Go. -- [ ] Ensure dependencies are up-to-date with `go mod tidy`. +- [ ] Ensure dependencies are up to date with `go mod tidy`. - [ ] Ensure building works with `go run ./...`/`go build ./...` - whole package. - [ ] Ensure you are not running an analysis on code that depends on files/packages outside the scope of the analyzed elements. - [ ] If using CGO, ensure all require system libraries are installed. +- [ ] If you are using private repositories/dependencies, ensure the [Go proxy](https://go.dev/ref/mod#module-proxy) (`GOPROXY`) and [checksum database](https://go.dev/ref/mod#checksum-database) (`GOSUMDB`) are right and/or your git configuration. ## Why is it not possible to skip/ignore `typecheck` errors? diff --git a/docs/src/docs/welcome/integrations.mdx b/docs/src/docs/welcome/integrations.mdx index 747b7ee29e2d..03e6d7e8d57e 100644 --- a/docs/src/docs/welcome/integrations.mdx +++ b/docs/src/docs/welcome/integrations.mdx @@ -15,6 +15,8 @@ Both v1 and v2 versions are supported. Install the [extension](https://marketplace.visualstudio.com/items?itemName=golang.Go). +**Note:** To use golangci-lint v2, you may need to switch to the pre-release version of the extension: [vscode-go#3732](https://github.com/golang/vscode-go/issues/3732#issuecomment-2805974456). +
Recommended settings for those who installed golangci-lint manually diff --git a/go.mod b/go.mod index a8835e203561..c4b63fa87ff7 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,8 @@ require ( 4d63.com/gocheckcompilerdirectives v1.3.0 4d63.com/gochecknoglobals v0.2.2 github.com/4meepo/tagalign v1.4.2 - github.com/Abirdcfly/dupword v0.1.3 + github.com/Abirdcfly/dupword v0.1.6 + github.com/AlwxSin/noinlineerr v1.0.3 github.com/Antonboom/errname v1.1.0 github.com/Antonboom/nilnil v1.1.0 github.com/Antonboom/testifylint v1.6.1 @@ -14,14 +15,14 @@ require ( github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.1 github.com/OpenPeeDeeP/depguard/v2 v2.2.1 - github.com/alecthomas/chroma/v2 v2.16.0 + github.com/alecthomas/chroma/v2 v2.18.0 github.com/alecthomas/go-check-sumtype v0.3.1 github.com/alexkohler/nakedret/v2 v2.0.6 github.com/alexkohler/prealloc v1.0.0 github.com/alingse/asasalint v0.0.11 github.com/alingse/nilnesserr v0.2.0 - github.com/ashanbrown/forbidigo v1.6.0 - github.com/ashanbrown/makezero v1.2.0 + github.com/ashanbrown/forbidigo/v2 v2.1.0 + github.com/ashanbrown/makezero/v2 v2.0.1 github.com/bkielbasa/cyclop v1.2.3 github.com/blizzy78/varnamelen v0.8.0 github.com/bombsimon/wsl/v4 v4.7.0 @@ -48,17 +49,18 @@ require ( github.com/golangci/go-printf-func-name v0.1.0 github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d github.com/golangci/golines v0.0.0-20250217134842-442fd0091d95 - github.com/golangci/misspell v0.6.0 - github.com/golangci/plugin-module-register v0.1.1 + github.com/golangci/misspell v0.7.0 + github.com/golangci/plugin-module-register v0.1.2 github.com/golangci/revgrep v0.8.0 + github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e github.com/gordonklaus/ineffassign v0.1.0 github.com/gostaticanalysis/forcetypeassert v0.2.0 github.com/gostaticanalysis/nilerr v0.1.1 github.com/hashicorp/go-version v1.7.0 - github.com/jgautheron/goconst v1.8.1 + github.com/jgautheron/goconst v1.8.2 github.com/jingyugao/rowserrcheck v1.1.1 - github.com/jjti/go-spancheck v0.6.4 + github.com/jjti/go-spancheck v0.6.5 github.com/julz/importas v0.2.0 github.com/karamaru-alpha/copyloopvar v1.2.1 github.com/kisielk/errcheck v1.9.0 @@ -73,12 +75,13 @@ require ( github.com/ldez/usetesting v0.4.3 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.2.0 - github.com/manuelarte/funcorder v0.2.1 + github.com/manuelarte/embeddedstructfieldcheck v0.3.0 + github.com/manuelarte/funcorder v0.5.0 github.com/maratori/testableexamples v1.0.0 github.com/maratori/testpackage v1.1.1 github.com/matoous/godox v1.1.0 github.com/mattn/go-colorable v0.1.14 - github.com/mgechev/revive v1.9.0 + github.com/mgechev/revive v1.10.0 github.com/mitchellh/go-homedir v1.1.0 github.com/moricho/tparallel v0.3.2 github.com/nakabonne/nestif v0.3.1 @@ -93,14 +96,14 @@ require ( github.com/ryancurrah/gomodguard v1.4.1 github.com/ryanrolds/sqlclosecheck v0.5.1 github.com/sanposhiho/wastedassign/v2 v2.1.0 - github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 + github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 github.com/sashamelentyev/interfacebloat v1.1.0 - github.com/sashamelentyev/usestdlibvars v1.28.0 - github.com/securego/gosec/v2 v2.22.3 - github.com/shirou/gopsutil/v4 v4.25.3 + github.com/sashamelentyev/usestdlibvars v1.29.0 + github.com/securego/gosec/v2 v2.22.4 + github.com/shirou/gopsutil/v4 v4.25.5 github.com/sirupsen/logrus v1.9.3 github.com/sivchari/containedctx v1.0.3 - github.com/sonatard/noctx v0.1.0 + github.com/sonatard/noctx v0.3.3 github.com/sourcegraph/go-diff v0.7.0 github.com/spf13/cobra v1.9.1 github.com/spf13/pflag v1.0.6 @@ -109,7 +112,7 @@ require ( github.com/stbenjam/no-sprintf-host-port v0.2.0 github.com/stretchr/testify v1.10.0 github.com/tdakkota/asciicheck v0.4.1 - github.com/tetafro/godot v1.5.0 + github.com/tetafro/godot v1.5.1 github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 github.com/timonwong/loggercheck v0.11.0 github.com/tomarrell/wrapcheck/v2 v2.11.0 @@ -117,20 +120,21 @@ require ( github.com/ultraware/funlen v0.2.0 github.com/ultraware/whitespace v0.2.0 github.com/uudashr/gocognit v1.2.0 - github.com/uudashr/iface v1.3.1 + github.com/uudashr/iface v1.4.0 github.com/valyala/quicktemplate v1.8.0 github.com/xen0n/gosmopolitan v1.3.0 github.com/yagipy/maintidx v1.0.0 github.com/yeya24/promlinter v0.3.0 github.com/ykadowak/zerologlint v0.1.5 gitlab.com/bosi/decorder v0.4.2 - go-simpler.org/musttag v0.13.0 + go-simpler.org/musttag v0.13.1 go-simpler.org/sloglint v0.11.0 + go.augendre.info/arangolint v0.2.0 go.augendre.info/fatcontext v0.8.0 go.uber.org/automaxprocs v1.6.0 golang.org/x/mod v0.24.0 - golang.org/x/sys v0.32.0 - golang.org/x/tools v0.32.0 + golang.org/x/sys v0.33.0 + golang.org/x/tools v0.33.0 gopkg.in/yaml.v3 v3.0.1 honnef.co/go/tools v0.6.1 mvdan.cc/gofumpt v0.8.0 @@ -138,20 +142,20 @@ require ( ) require ( + codeberg.org/chavacava/garif v0.2.0 // indirect github.com/Masterminds/semver/v3 v3.3.1 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/ccojocar/zxcvbn-go v1.0.2 // indirect + github.com/ccojocar/zxcvbn-go v1.0.4 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect github.com/charmbracelet/x/ansi v0.8.0 // indirect github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect github.com/charmbracelet/x/term v0.2.1 // indirect - github.com/chavacava/garif v0.1.0 // indirect github.com/dave/dst v0.27.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.11.5 // indirect - github.com/ebitengine/purego v0.8.2 // indirect + github.com/ebitengine/purego v0.8.4 // indirect github.com/ettle/strcase v0.2.0 // indirect github.com/fatih/structtag v1.2.0 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect @@ -181,7 +185,6 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/muesli/termenv v0.16.0 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect @@ -209,8 +212,8 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect - golang.org/x/sync v0.13.0 // indirect - golang.org/x/text v0.24.0 // indirect + golang.org/x/sync v0.14.0 // indirect + golang.org/x/text v0.25.0 // indirect google.golang.org/protobuf v1.36.6 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index ff028d1c4652..182e746f2b29 100644 --- a/go.sum +++ b/go.sum @@ -34,11 +34,15 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +codeberg.org/chavacava/garif v0.2.0 h1:F0tVjhYbuOCnvNcU3YSpO6b3Waw6Bimy4K0mM8y6MfY= +codeberg.org/chavacava/garif v0.2.0/go.mod h1:P2BPbVbT4QcvLZrORc2T29szK3xEOlnl0GiPTJmEqBQ= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/4meepo/tagalign v1.4.2 h1:0hcLHPGMjDyM1gHG58cS73aQF8J4TdVR96TZViorO9E= github.com/4meepo/tagalign v1.4.2/go.mod h1:+p4aMyFM+ra7nb41CnFG6aSDXqRxU/w1VQqScKqDARI= -github.com/Abirdcfly/dupword v0.1.3 h1:9Pa1NuAsZvpFPi9Pqkd93I7LIYRURj+A//dFd5tgBeE= -github.com/Abirdcfly/dupword v0.1.3/go.mod h1:8VbB2t7e10KRNdwTVoxdBaxla6avbhGzb8sCTygUMhw= +github.com/Abirdcfly/dupword v0.1.6 h1:qeL6u0442RPRe3mcaLcbaCi2/Y/hOcdtw6DE9odjz9c= +github.com/Abirdcfly/dupword v0.1.6/go.mod h1:s+BFMuL/I4YSiFv29snqyjwzDp4b65W2Kvy+PKzZ6cw= +github.com/AlwxSin/noinlineerr v1.0.3 h1:9b5edChzzwX30BuBci13LHVZHF5q7hW9qtrs+wJdDog= +github.com/AlwxSin/noinlineerr v1.0.3/go.mod h1:+QgkkoYrMH7RHvcdxdlI7vYYEdgeoFOVjU9sUhw/rQc= github.com/Antonboom/errname v1.1.0 h1:A+ucvdpMwlo/myWrkHEUEBWc/xuXdud23S8tmTb/oAE= github.com/Antonboom/errname v1.1.0/go.mod h1:O1NMrzgUcVBGIfi3xlVuvX8Q/VP/73sseCaAppfjqZw= github.com/Antonboom/nilnil v1.1.0 h1:jGxJxjgYS3VUUtOTNk8Z1icwT5ESpLH/426fjmQG+ng= @@ -59,8 +63,8 @@ github.com/OpenPeeDeeP/depguard/v2 v2.2.1 h1:vckeWVESWp6Qog7UZSARNqfu/cZqvki8zsu github.com/OpenPeeDeeP/depguard/v2 v2.2.1/go.mod h1:q4DKzC4UcVaAvcfd41CZh0PWpGgzrVxUYBlgKNGquUo= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= -github.com/alecthomas/chroma/v2 v2.16.0 h1:QC5ZMizk67+HzxFDjQ4ASjni5kWBTGiigRG1u23IGvA= -github.com/alecthomas/chroma/v2 v2.16.0/go.mod h1:RVX6AvYm4VfYe/zsk7mjHueLDZor3aWCNE14TFlepBk= +github.com/alecthomas/chroma/v2 v2.18.0 h1:6h53Q4hW83SuF+jcsp7CVhLsMozzvQvO8HBbKQW+gn4= +github.com/alecthomas/chroma/v2 v2.18.0/go.mod h1:RVX6AvYm4VfYe/zsk7mjHueLDZor3aWCNE14TFlepBk= github.com/alecthomas/go-check-sumtype v0.3.1 h1:u9aUvbGINJxLVXiFvHUlPEaD7VDULsrxJb4Aq31NLkU= github.com/alecthomas/go-check-sumtype v0.3.1/go.mod h1:A8TSiN3UPRw3laIgWEUOHHLPa6/r9MtoigdlP5h3K/E= github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= @@ -78,10 +82,10 @@ github.com/alingse/asasalint v0.0.11 h1:SFwnQXJ49Kx/1GghOFz1XGqHYKp21Kq1nHad/0WQ github.com/alingse/asasalint v0.0.11/go.mod h1:nCaoMhw7a9kSJObvQyVzNTPBDbNpdocqrSP7t/cW5+I= github.com/alingse/nilnesserr v0.2.0 h1:raLem5KG7EFVb4UIDAXgrv3N2JIaffeKNtcEXkEWd/w= github.com/alingse/nilnesserr v0.2.0/go.mod h1:1xJPrXonEtX7wyTq8Dytns5P2hNzoWymVUIaKm4HNFg= -github.com/ashanbrown/forbidigo v1.6.0 h1:D3aewfM37Yb3pxHujIPSpTf6oQk9sc9WZi8gerOIVIY= -github.com/ashanbrown/forbidigo v1.6.0/go.mod h1:Y8j9jy9ZYAEHXdu723cUlraTqbzjKF1MUyfOKL+AjcU= -github.com/ashanbrown/makezero v1.2.0 h1:/2Lp1bypdmK9wDIq7uWBlDF1iMUpIIS4A+pF6C9IEUU= -github.com/ashanbrown/makezero v1.2.0/go.mod h1:dxlPhHbDMC6N6xICzFBSK+4njQDdK8euNO0qjQMtGY4= +github.com/ashanbrown/forbidigo/v2 v2.1.0 h1:NAxZrWqNUQiDz19FKScQ/xvwzmij6BiOw3S0+QUQ+Hs= +github.com/ashanbrown/forbidigo/v2 v2.1.0/go.mod h1:0zZfdNAuZIL7rSComLGthgc/9/n2FqspBOH90xlCHdA= +github.com/ashanbrown/makezero/v2 v2.0.1 h1:r8GtKetWOgoJ4sLyUx97UTwyt2dO7WkGFHizn/Lo8TY= +github.com/ashanbrown/makezero/v2 v2.0.1/go.mod h1:kKU4IMxmYW1M4fiEHMb2vc5SFoPzXvgbMR9gIp5pjSw= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= @@ -106,8 +110,8 @@ github.com/butuzov/mirror v1.3.0 h1:HdWCXzmwlQHdVhwvsfBb2Au0r3HyINry3bDWLYXiKoc= github.com/butuzov/mirror v1.3.0/go.mod h1:AEij0Z8YMALaq4yQj9CPPVYOyJQyiexpQEQgihajRfI= github.com/catenacyber/perfsprint v0.9.1 h1:5LlTp4RwTooQjJCvGEFV6XksZvWE7wCOUvjD2z0vls0= github.com/catenacyber/perfsprint v0.9.1/go.mod h1:q//VWC2fWbcdSLEY1R3l8n0zQCDPdE4IjZwyY1HMunM= -github.com/ccojocar/zxcvbn-go v1.0.2 h1:na/czXU8RrhXO4EZme6eQJLR4PzcGsahsBOAwU6I3Vg= -github.com/ccojocar/zxcvbn-go v1.0.2/go.mod h1:g1qkXtUSvHP8lhHp5GrSmTz6uWALGRMQdw6Qnz/hi60= +github.com/ccojocar/zxcvbn-go v1.0.4 h1:FWnCIRMXPj43ukfX000kvBZvV6raSxakYr1nzyNrUcc= +github.com/ccojocar/zxcvbn-go v1.0.4/go.mod h1:3GxGX+rHmueTUMvm5ium7irpyjmm7ikxYFOSJB21Das= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -125,8 +129,6 @@ github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0G github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc= -github.com/chavacava/garif v0.1.0/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+UIPD+Gww= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -150,8 +152,8 @@ github.com/denis-tingaikin/go-header v0.5.0 h1:SRdnP5ZKvcO9KKRP1KJrhFR3RrlGuD+42 github.com/denis-tingaikin/go-header v0.5.0/go.mod h1:mMenU5bWrok6Wl2UsZjy+1okegmwQ3UgWl4V1D8gjlY= github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ= github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I= -github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw= +github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -257,12 +259,14 @@ github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d h1:viFft9sS/dxoYY0a github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d/go.mod h1:ivJ9QDg0XucIkmwhzCDsqcnxxlDStoTl89jDMIoNxKY= github.com/golangci/golines v0.0.0-20250217134842-442fd0091d95 h1:AkK+w9FZBXlU/xUmBtSJN1+tAI4FIvy5WtnUnY8e4p8= github.com/golangci/golines v0.0.0-20250217134842-442fd0091d95/go.mod h1:k9mmcyWKSTMcPPvQUCfRWWQ9VHJ1U9Dc0R7kaXAgtnQ= -github.com/golangci/misspell v0.6.0 h1:JCle2HUTNWirNlDIAUO44hUsKhOFqGPoC4LZxlaSXDs= -github.com/golangci/misspell v0.6.0/go.mod h1:keMNyY6R9isGaSAu+4Q8NMBwMPkh15Gtc8UCVoDtAWo= -github.com/golangci/plugin-module-register v0.1.1 h1:TCmesur25LnyJkpsVrupv1Cdzo+2f7zX0H6Jkw1Ol6c= -github.com/golangci/plugin-module-register v0.1.1/go.mod h1:TTpqoB6KkwOJMV8u7+NyXMrkwwESJLOkfl9TxR1DGFc= +github.com/golangci/misspell v0.7.0 h1:4GOHr/T1lTW0hhR4tgaaV1WS/lJ+ncvYCoFKmqJsj0c= +github.com/golangci/misspell v0.7.0/go.mod h1:WZyyI2P3hxPY2UVHs3cS8YcllAeyfquQcKfdeE9AFVg= +github.com/golangci/plugin-module-register v0.1.2 h1:e5WM6PO6NIAEcij3B053CohVp3HIYbzSuP53UAYgOpg= +github.com/golangci/plugin-module-register v0.1.2/go.mod h1:1+QGTsKBvAIvPvoY/os+G5eoqxWn70HYDm2uvUyGuVw= github.com/golangci/revgrep v0.8.0 h1:EZBctwbVd0aMeRnNUsFogoyayvKHyxlV3CdUA46FX2s= github.com/golangci/revgrep v0.8.0/go.mod h1:U4R/s9dlXZsg8uJmaR1GrloUr14D7qDl8gi2iPXJH8k= +github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e h1:ai0EfmVYE2bRA5htgAG9r7s3tHsfjIhN98WshBTJ9jM= +github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e/go.mod h1:Vrn4B5oR9qRwM+f54koyeH3yzphlecwERs0el27Fr/s= github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e h1:gD6P7NEo7Eqtt0ssnqSJNNndxe69DOQ24A5h7+i3KpM= github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e/go.mod h1:h+wZwLjUTJnm/P2rwlbJdRPZXOzaT36/FwnPnY2inzc= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -291,8 +295,8 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -329,12 +333,12 @@ github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSo github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jgautheron/goconst v1.8.1 h1:PPqCYp3K/xlOj5JmIe6O1Mj6r1DbkdbLtR3AJuZo414= -github.com/jgautheron/goconst v1.8.1/go.mod h1:A0oxgBCHy55NQn6sYpO7UdnA9p+h7cPtoOZUmvNIako= +github.com/jgautheron/goconst v1.8.2 h1:y0XF7X8CikZ93fSNT6WBTb/NElBu9IjaY7CCYQrCMX4= +github.com/jgautheron/goconst v1.8.2/go.mod h1:A0oxgBCHy55NQn6sYpO7UdnA9p+h7cPtoOZUmvNIako= github.com/jingyugao/rowserrcheck v1.1.1 h1:zibz55j/MJtLsjP1OF4bSdgXxwL1b+Vn7Tjzq7gFzUs= github.com/jingyugao/rowserrcheck v1.1.1/go.mod h1:4yvlZSDb3IyDTUZJUmpZfm2Hwok+Dtp+nu2qOq+er9c= -github.com/jjti/go-spancheck v0.6.4 h1:Tl7gQpYf4/TMU7AT84MN83/6PutY21Nb9fuQjFTpRRc= -github.com/jjti/go-spancheck v0.6.4/go.mod h1:yAEYdKJ2lRkDA8g7X+oKUHXOWVAXSBJRv04OhF+QUjk= +github.com/jjti/go-spancheck v0.6.5 h1:lmi7pKxa37oKYIMScialXUK6hP3iY5F1gu+mLBPgYB8= +github.com/jjti/go-spancheck v0.6.5/go.mod h1:aEogkeatBrbYsyW6y5TgDfihCulDYciL1B7rG2vSsrU= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -389,8 +393,10 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/manuelarte/funcorder v0.2.1 h1:7QJsw3qhljoZ5rH0xapIvjw31EcQeFbF31/7kQ/xS34= -github.com/manuelarte/funcorder v0.2.1/go.mod h1:BQQ0yW57+PF9ZpjpeJDKOffEsQbxDFKW8F8zSMe/Zd0= +github.com/manuelarte/embeddedstructfieldcheck v0.3.0 h1:VhGqK8gANDvFYDxQkjPbv7/gDJtsGU9k6qj/hC2hgso= +github.com/manuelarte/embeddedstructfieldcheck v0.3.0/go.mod h1:LSo/IQpPfx1dXMcX4ibZCYA7Yy6ayZHIaOGM70+1Wy8= +github.com/manuelarte/funcorder v0.5.0 h1:llMuHXXbg7tD0i/LNw8vGnkDTHFpTnWqKPI85Rknc+8= +github.com/manuelarte/funcorder v0.5.0/go.mod h1:Yt3CiUQthSBMBxjShjdXMexmzpP8YGvGLjrxJNkO2hA= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE= github.com/maratori/testpackage v1.1.1 h1:S58XVV5AD7HADMmD0fNnziNHqKvSdDuEKdPD1rNTU04= @@ -403,13 +409,12 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mgechev/revive v1.9.0 h1:8LaA62XIKrb8lM6VsBSQ92slt/o92z5+hTw3CmrvSrM= -github.com/mgechev/revive v1.9.0/go.mod h1:LAPq3+MgOf7GcL5PlWIkHb0PT7XH4NuC2LdWymhb9Mo= +github.com/mgechev/revive v1.10.0 h1:x2oJsd7yrDp0mC6IgZqSKBTjSUC9Zk5Ob2WfBwZic2I= +github.com/mgechev/revive v1.10.0/go.mod h1:1MRO9zUV7Yukhqh/nGRKSaw6xC5XDzPWPja5GMPWoSE= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -433,12 +438,10 @@ github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= github.com/nunnatsa/ginkgolinter v0.19.1 h1:mjwbOlDQxZi9Cal+KfbEJTCz327OLNfwNvoZ70NJ+c4= github.com/nunnatsa/ginkgolinter v0.19.1/go.mod h1:jkQ3naZDmxaZMXPWaS9rblH+i+GWXQCaS/JFIWcOH2s= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0= -github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM= -github.com/onsi/gomega v1.36.3 h1:hID7cr8t3Wp26+cYnfcjR6HpJ00fdogN6dqZ1t6IylU= -github.com/onsi/gomega v1.36.3/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= +github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus= +github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8= +github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y= +github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw= github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= @@ -509,18 +512,18 @@ github.com/ryanrolds/sqlclosecheck v0.5.1 h1:dibWW826u0P8jNLsLN+En7+RqWWTYrjCB9f github.com/ryanrolds/sqlclosecheck v0.5.1/go.mod h1:2g3dUjoS6AL4huFdv6wn55WpLIDjY7ZgUR4J8HOO/XQ= github.com/sanposhiho/wastedassign/v2 v2.1.0 h1:crurBF7fJKIORrV85u9UUpePDYGWnwvv3+A96WvwXT0= github.com/sanposhiho/wastedassign/v2 v2.1.0/go.mod h1:+oSmSC+9bQ+VUAxA66nBb0Z7N8CK7mscKTDYC6aIek4= -github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw= -github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tMEOsumirXcOJqAw= github.com/sashamelentyev/interfacebloat v1.1.0/go.mod h1:+Y9yU5YdTkrNvoX0xHc84dxiN1iBi9+G8zZIhPVoNjQ= -github.com/sashamelentyev/usestdlibvars v1.28.0 h1:jZnudE2zKCtYlGzLVreNp5pmCdOxXUzwsMDBkR21cyQ= -github.com/sashamelentyev/usestdlibvars v1.28.0/go.mod h1:9nl0jgOfHKWNFS43Ojw0i7aRoS4j6EBye3YBhmAIRF8= -github.com/securego/gosec/v2 v2.22.3 h1:mRrCNmRF2NgZp4RJ8oJ6yPJ7G4x6OCiAXHd8x4trLRc= -github.com/securego/gosec/v2 v2.22.3/go.mod h1:42M9Xs0v1WseinaB/BmNGO8AVqG8vRfhC2686ACY48k= +github.com/sashamelentyev/usestdlibvars v1.29.0 h1:8J0MoRrw4/NAXtjQqTHrbW9NN+3iMf7Knkq057v4XOQ= +github.com/sashamelentyev/usestdlibvars v1.29.0/go.mod h1:8PpnjHMk5VdeWlVb4wCdrB8PNbLqZ3wBZTZWkrpZZL8= +github.com/securego/gosec/v2 v2.22.4 h1:21VdNGcKicFSv6rUDBc0cEtEl7lWyCKZxKIm0iwvrIM= +github.com/securego/gosec/v2 v2.22.4/go.mod h1:ww5Yie7KJ3AH8XZQTletkW5zOmIse6FACs/Ys8VR3qE= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/shirou/gopsutil/v4 v4.25.3 h1:SeA68lsu8gLggyMbmCn8cmp97V1TI9ld9sVzAUcKcKE= -github.com/shirou/gopsutil/v4 v4.25.3/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA= +github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQUJAsc= +github.com/shirou/gopsutil/v4 v4.25.5/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c= github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -530,8 +533,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sivchari/containedctx v1.0.3 h1:x+etemjbsh2fB5ewm5FeLNi5bUjK0V8n0RB+Wwfd0XE= github.com/sivchari/containedctx v1.0.3/go.mod h1:c1RDvCbnJLtH4lLcYD/GqwiBSSf4F5Qk0xld2rBqzJ4= -github.com/sonatard/noctx v0.1.0 h1:JjqOc2WN16ISWAjAk8M5ej0RfExEXtkEyExl2hLW+OM= -github.com/sonatard/noctx v0.1.0/go.mod h1:0RvBxqY8D4j9cTTTWE8ylt2vqj2EPI8fHmrxHdsaZ2c= +github.com/sonatard/noctx v0.3.3 h1:9+wFUxZfjiCdNadFaGH55sa7Y1r6yKZiAsUVmCP+tjw= +github.com/sonatard/noctx v0.3.3/go.mod h1:64XdbzFb18XL4LporKXp8poqZtPKbCrqQ402CV+kJas= github.com/sourcegraph/go-diff v0.7.0 h1:9uLlrd5T46OXs5qpp8L/MTltk0zikUGi0sNNyCpA8G0= github.com/sourcegraph/go-diff v0.7.0/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs= github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= @@ -553,18 +556,12 @@ github.com/stbenjam/no-sprintf-host-port v0.2.0 h1:i8pxvGrt1+4G0czLr/WnmyH7zbZ8B github.com/stbenjam/no-sprintf-host-port v0.2.0/go.mod h1:eL0bQ9PasS0hsyTyfTjjG+E80QIyPnBVQbYZyv20Jfk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= @@ -575,8 +572,8 @@ github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY= -github.com/tetafro/godot v1.5.0 h1:aNwfVI4I3+gdxjMgYPus9eHmoBeJIbnajOyqZYStzuw= -github.com/tetafro/godot v1.5.0/go.mod h1:2oVxTBSftRTh4+MVfUaUXR6bn2GDXCaMcOG4Dk3rfio= +github.com/tetafro/godot v1.5.1 h1:PZnjCol4+FqaEzvZg5+O8IY2P3hfY9JzRBNPv1pEDS4= +github.com/tetafro/godot v1.5.1/go.mod h1:cCdPtEndkmqqrhiCfkmxDodMQJ/f3L1BCNskCUZdTwk= github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 h1:9LPGD+jzxMlnk5r6+hJnar67cgpDIz/iyD+rfl5r2Vk= github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67/go.mod h1:mkjARE7Yr8qU23YcGMSALbIxTQ9r9QBVahQOBRfU460= github.com/timonwong/loggercheck v0.11.0 h1:jdaMpYBl+Uq9mWPXv1r8jc5fC3gyXx4/WGwTnnNKn4M= @@ -595,8 +592,8 @@ github.com/ultraware/whitespace v0.2.0 h1:TYowo2m9Nfj1baEQBjuHzvMRbp19i+RCcRYrSW github.com/ultraware/whitespace v0.2.0/go.mod h1:XcP1RLD81eV4BW8UhQlpaR+SDc2givTvyI8a586WjW8= github.com/uudashr/gocognit v1.2.0 h1:3BU9aMr1xbhPlvJLSydKwdLN3tEUUrzPSSM8S4hDYRA= github.com/uudashr/gocognit v1.2.0/go.mod h1:k/DdKPI6XBZO1q7HgoV2juESI2/Ofj9AcHPZhBBdrTU= -github.com/uudashr/iface v1.3.1 h1:bA51vmVx1UIhiIsQFSNq6GZ6VPTk3WNMZgRiCe9R29U= -github.com/uudashr/iface v1.3.1/go.mod h1:4QvspiRd3JLPAEXBQ9AiZpLbJlrWWgRChOKDJEuQTdg= +github.com/uudashr/iface v1.4.0 h1:ImZ+1oEJPXvjap7nK0md7gA9RRH7PMp4vliaLkJ2+cg= +github.com/uudashr/iface v1.4.0/go.mod h1:i/H4cfRMPe0izticV8Yz0g6/zcsh5xXlvthrdh1kqcY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/quicktemplate v1.8.0 h1:zU0tjbIqTRgKQzFY1L42zq0qR3eh4WoQQdIdqCysW5k= @@ -624,10 +621,12 @@ gitlab.com/bosi/decorder v0.4.2 h1:qbQaV3zgwnBZ4zPMhGLW4KZe7A7NwxEhJx39R3shffo= gitlab.com/bosi/decorder v0.4.2/go.mod h1:muuhHoaJkA9QLcYHq4Mj8FJUwDZ+EirSHRiaTcTf6T8= go-simpler.org/assert v0.9.0 h1:PfpmcSvL7yAnWyChSjOz6Sp6m9j5lyK8Ok9pEL31YkQ= go-simpler.org/assert v0.9.0/go.mod h1:74Eqh5eI6vCK6Y5l3PI8ZYFXG4Sa+tkr70OIPJAUr28= -go-simpler.org/musttag v0.13.0 h1:Q/YAW0AHvaoaIbsPj3bvEI5/QFP7w696IMUpnKXQfCE= -go-simpler.org/musttag v0.13.0/go.mod h1:FTzIGeK6OkKlUDVpj0iQUXZLUO1Js9+mvykDQy9C5yM= +go-simpler.org/musttag v0.13.1 h1:lw2sJyu7S1X8lc8zWUAdH42y+afdcCnHhWpnkWvd6vU= +go-simpler.org/musttag v0.13.1/go.mod h1:8r450ehpMLQgvpb6sg+hV5Ur47eH6olp/3yEanfG97k= go-simpler.org/sloglint v0.11.0 h1:JlR1X4jkbeaffiyjLtymeqmGDKBDO1ikC6rjiuFAOco= go-simpler.org/sloglint v0.11.0/go.mod h1:CFDO8R1i77dlciGfPEPvYke2ZMx4eyGiEIWkyeW2Pvw= +go.augendre.info/arangolint v0.2.0 h1:2NP/XudpPmfBhQKX4rMk+zDYIj//qbt4hfZmSSTcpj8= +go.augendre.info/arangolint v0.2.0/go.mod h1:Vx4KSJwu48tkE+8uxuf0cbBnAPgnt8O1KWiT7bljq7w= go.augendre.info/fatcontext v0.8.0 h1:2dfk6CQbDGeu1YocF59Za5Pia7ULeAM6friJ3LP7lmk= go.augendre.info/fatcontext v0.8.0/go.mod h1:oVJfMgwngMsHO+KB2MdgzcO+RvtNdiCEOlWvSFtax/s= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -694,9 +693,7 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= @@ -735,14 +732,12 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= -golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -764,8 +759,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= -golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= +golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -814,20 +809,17 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= @@ -838,13 +830,11 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= -golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -899,13 +889,11 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= -golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU= -golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 0f2ef5fcc50b..a12cb912b569 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -539,6 +539,7 @@ "fieldalignment", "findcall", "framepointer", + "hostport", "httpmux", "httpresponse", "ifaceassert", @@ -637,6 +638,7 @@ "string-of-int", "struct-tag", "superfluous-else", + "time-date", "time-equal", "time-naming", "unchecked-type-assertion", @@ -644,12 +646,14 @@ "unexported-naming", "unexported-return", "unhandled-error", + "unnecessary-format", "unnecessary-stmt", "unreachable-code", "unused-parameter", "unused-receiver", "use-any", "use-errors-new", + "use-fmt-print", "useless-break", "var-declaration", "var-naming", @@ -660,7 +664,8 @@ "enum": [ "identical", "unused", - "opaque" + "opaque", + "unexported" ] }, "tagliatelle-cases": { @@ -717,6 +722,7 @@ "anyOf": [ { "enum": [ + "arangolint", "asasalint", "asciicheck", "bidichk", @@ -732,6 +738,7 @@ "dupl", "dupword", "durationcheck", + "embeddedstructfieldcheck", "errcheck", "errchkjson", "errname", @@ -787,6 +794,7 @@ "nilnil", "nlreturn", "noctx", + "noinlineerr", "nolintlint", "nonamedreturns", "nosprintfhostport", @@ -836,7 +844,8 @@ "gofmt", "gofumpt", "goimports", - "golines" + "golines", + "swaggo" ] }, "settings": { @@ -1085,6 +1094,17 @@ } } }, + "embeddedstructfieldcheckSettings": { + "type": "object", + "additionalProperties": false, + "properties": { + "forbid-mutex": { + "description": "Checks that sync.Mutex and sync.RWMutex are not used as embedded fields.", + "type": "boolean", + "default": false + } + } + }, "errcheckSettings": { "type": "object", "additionalProperties": false, @@ -1111,6 +1131,11 @@ "description": "To disable the errcheck built-in exclude list", "type": "boolean", "default": false + }, + "verbose": { + "description": "Display function signature instead of selector", + "type": "boolean", + "default": false } } }, @@ -1317,6 +1342,11 @@ "description": "Checks if the exported methods of a structure are placed before the non-exported ones.", "type": "boolean", "default": true + }, + "alphabetical": { + "description": "Checks if the constructors and/or structure methods are sorted alphabetically.", + "type": "boolean", + "default": false } } }, @@ -3702,6 +3732,11 @@ "type": "boolean", "default": false }, + "time-date-month": { + "description": "Suggest the use of time.Month in time.Date.", + "type": "boolean", + "default": false + }, "crypto-hash": { "description": "Suggest the use of crypto.Hash.String().", "type": "boolean", @@ -4342,6 +4377,9 @@ "dupl": { "$ref": "#/definitions/settings/definitions/duplSettings" }, + "embeddedstructfieldcheck": { + "$ref": "#/definitions/settings/definitions/embeddedstructfieldcheckSettings" + }, "errcheck": { "$ref": "#/definitions/settings/definitions/errcheckSettings" }, diff --git a/pkg/commands/formatters.go b/pkg/commands/formatters.go index a3fafd1d25c9..22a9914ae2ff 100644 --- a/pkg/commands/formatters.go +++ b/pkg/commands/formatters.go @@ -59,7 +59,8 @@ func newFormattersCommand(logger logutils.Log) *formattersCommand { fs.SortFlags = false // sort them as they are defined here setupConfigFileFlagSet(fs, &c.opts.LoaderOptions) - setupLintersFlagSet(c.viper, fs) + + setupFormattersFlagSet(c.viper, fs) fs.BoolVar(&c.opts.JSON, "json", false, color.GreenString("Display as JSON")) diff --git a/pkg/commands/internal/migrate/migrate_linter_names.go b/pkg/commands/internal/migrate/migrate_linter_names.go index da003e9af77d..bbb178ab3846 100644 --- a/pkg/commands/internal/migrate/migrate_linter_names.go +++ b/pkg/commands/internal/migrate/migrate_linter_names.go @@ -749,11 +749,8 @@ func allEnabled(old versionone.Linters, linters []LinterInfo) []LinterInfo { var results []LinterInfo for _, linter := range linters { - for _, name := range old.Enable { - if linter.isName(name) { - results = append(results, linter) - break - } + if slices.ContainsFunc(old.Enable, linter.isName) { + results = append(results, linter) } } @@ -764,11 +761,8 @@ func allDisabled(old versionone.Linters, linters []LinterInfo) []LinterInfo { var results []LinterInfo for _, linter := range linters { - for _, name := range old.Disable { - if linter.isName(name) { - results = append(results, linter) - break - } + if slices.ContainsFunc(old.Disable, linter.isName) { + results = append(results, linter) } } diff --git a/pkg/commands/migrate.go b/pkg/commands/migrate.go index 7c73209ed180..78e7842bed04 100644 --- a/pkg/commands/migrate.go +++ b/pkg/commands/migrate.go @@ -81,10 +81,6 @@ func newMigrateCommand(log logutils.Log, info BuildInfo) *migrateCommand { } func (c *migrateCommand) execute(_ *cobra.Command, _ []string) error { - if c.cfg.Version != "" { - return fmt.Errorf("configuration version is already set: %s", c.cfg.Version) - } - srcPath := c.viper.ConfigFileUsed() if srcPath == "" { c.log.Warnf("No config file detected") @@ -141,6 +137,10 @@ func (c *migrateCommand) preRunE(cmd *cobra.Command, _ []string) error { return fmt.Errorf("unsupported format: %s", c.opts.format) } + if c.cfg.Version != "" { + return fmt.Errorf("configuration version is already set: %s", c.cfg.Version) + } + if c.opts.skipValidation { return nil } diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 53902eafac24..4e2d3b1b984a 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -376,7 +376,7 @@ func (c *runCommand) runAndPrint(ctx context.Context) error { } // runAnalysis executes the linters that have been enabled in the configuration. -func (c *runCommand) runAnalysis(ctx context.Context) ([]result.Issue, error) { +func (c *runCommand) runAnalysis(ctx context.Context) ([]*result.Issue, error) { lintersToRun, err := c.dbManager.GetOptimizedLinters() if err != nil { return nil, err @@ -408,7 +408,7 @@ func (c *runCommand) setOutputToDevNull() (savedStdout, savedStderr *os.File) { return } -func (c *runCommand) setExitCodeIfIssuesFound(issues []result.Issue) { +func (c *runCommand) setExitCodeIfIssuesFound(issues []*result.Issue) { if len(issues) != 0 { c.exitCode = c.cfg.Run.ExitCodeIfIssuesFound } @@ -433,7 +433,7 @@ func (c *runCommand) printDeprecatedLinterMessages(enabledLinters map[string]*li } } -func (c *runCommand) printStats(issues []result.Issue) { +func (c *runCommand) printStats(issues []*result.Issue) { if !c.cfg.Output.ShowStats { return } diff --git a/pkg/config/linters.go b/pkg/config/linters.go index 590d9448a197..2669f2e64778 100644 --- a/pkg/config/linters.go +++ b/pkg/config/linters.go @@ -49,5 +49,5 @@ func (l *Linters) validateNoFormatters() error { } func getAllFormatterNames() []string { - return []string{"gci", "gofmt", "gofumpt", "goimports", "golines"} + return []string{"gci", "gofmt", "gofumpt", "goimports", "golines", "swaggo"} } diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 16a8bb9501b9..e2838d808acb 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -205,84 +205,85 @@ var defaultLintersSettings = LintersSettings{ type LintersSettings struct { FormatterSettings `mapstructure:"-"` - Asasalint AsasalintSettings `mapstructure:"asasalint"` - BiDiChk BiDiChkSettings `mapstructure:"bidichk"` - CopyLoopVar CopyLoopVarSettings `mapstructure:"copyloopvar"` - Cyclop CyclopSettings `mapstructure:"cyclop"` - Decorder DecorderSettings `mapstructure:"decorder"` - Depguard DepGuardSettings `mapstructure:"depguard"` - Dogsled DogsledSettings `mapstructure:"dogsled"` - Dupl DuplSettings `mapstructure:"dupl"` - DupWord DupWordSettings `mapstructure:"dupword"` - Errcheck ErrcheckSettings `mapstructure:"errcheck"` - ErrChkJSON ErrChkJSONSettings `mapstructure:"errchkjson"` - ErrorLint ErrorLintSettings `mapstructure:"errorlint"` - Exhaustive ExhaustiveSettings `mapstructure:"exhaustive"` - Exhaustruct ExhaustructSettings `mapstructure:"exhaustruct"` - Fatcontext FatcontextSettings `mapstructure:"fatcontext"` - Forbidigo ForbidigoSettings `mapstructure:"forbidigo"` - FuncOrder FuncOrderSettings `mapstructure:"funcorder"` - Funlen FunlenSettings `mapstructure:"funlen"` - GinkgoLinter GinkgoLinterSettings `mapstructure:"ginkgolinter"` - Gocognit GocognitSettings `mapstructure:"gocognit"` - GoChecksumType GoChecksumTypeSettings `mapstructure:"gochecksumtype"` - Goconst GoConstSettings `mapstructure:"goconst"` - Gocritic GoCriticSettings `mapstructure:"gocritic"` - Gocyclo GoCycloSettings `mapstructure:"gocyclo"` - Godot GodotSettings `mapstructure:"godot"` - Godox GodoxSettings `mapstructure:"godox"` - Goheader GoHeaderSettings `mapstructure:"goheader"` - GoModDirectives GoModDirectivesSettings `mapstructure:"gomoddirectives"` - Gomodguard GoModGuardSettings `mapstructure:"gomodguard"` - Gosec GoSecSettings `mapstructure:"gosec"` - Gosmopolitan GosmopolitanSettings `mapstructure:"gosmopolitan"` - Govet GovetSettings `mapstructure:"govet"` - Grouper GrouperSettings `mapstructure:"grouper"` - Iface IfaceSettings `mapstructure:"iface"` - ImportAs ImportAsSettings `mapstructure:"importas"` - Inamedparam INamedParamSettings `mapstructure:"inamedparam"` - InterfaceBloat InterfaceBloatSettings `mapstructure:"interfacebloat"` - Ireturn IreturnSettings `mapstructure:"ireturn"` - Lll LllSettings `mapstructure:"lll"` - LoggerCheck LoggerCheckSettings `mapstructure:"loggercheck"` - MaintIdx MaintIdxSettings `mapstructure:"maintidx"` - Makezero MakezeroSettings `mapstructure:"makezero"` - Misspell MisspellSettings `mapstructure:"misspell"` - Mnd MndSettings `mapstructure:"mnd"` - MustTag MustTagSettings `mapstructure:"musttag"` - Nakedret NakedretSettings `mapstructure:"nakedret"` - Nestif NestifSettings `mapstructure:"nestif"` - NilNil NilNilSettings `mapstructure:"nilnil"` - Nlreturn NlreturnSettings `mapstructure:"nlreturn"` - NoLintLint NoLintLintSettings `mapstructure:"nolintlint"` - NoNamedReturns NoNamedReturnsSettings `mapstructure:"nonamedreturns"` - ParallelTest ParallelTestSettings `mapstructure:"paralleltest"` - PerfSprint PerfSprintSettings `mapstructure:"perfsprint"` - Prealloc PreallocSettings `mapstructure:"prealloc"` - Predeclared PredeclaredSettings `mapstructure:"predeclared"` - Promlinter PromlinterSettings `mapstructure:"promlinter"` - ProtoGetter ProtoGetterSettings `mapstructure:"protogetter"` - Reassign ReassignSettings `mapstructure:"reassign"` - Recvcheck RecvcheckSettings `mapstructure:"recvcheck"` - Revive ReviveSettings `mapstructure:"revive"` - RowsErrCheck RowsErrCheckSettings `mapstructure:"rowserrcheck"` - SlogLint SlogLintSettings `mapstructure:"sloglint"` - Spancheck SpancheckSettings `mapstructure:"spancheck"` - Staticcheck StaticCheckSettings `mapstructure:"staticcheck"` - TagAlign TagAlignSettings `mapstructure:"tagalign"` - Tagliatelle TagliatelleSettings `mapstructure:"tagliatelle"` - Testifylint TestifylintSettings `mapstructure:"testifylint"` - Testpackage TestpackageSettings `mapstructure:"testpackage"` - Thelper ThelperSettings `mapstructure:"thelper"` - Unconvert UnconvertSettings `mapstructure:"unconvert"` - Unparam UnparamSettings `mapstructure:"unparam"` - Unused UnusedSettings `mapstructure:"unused"` - UseStdlibVars UseStdlibVarsSettings `mapstructure:"usestdlibvars"` - UseTesting UseTestingSettings `mapstructure:"usetesting"` - Varnamelen VarnamelenSettings `mapstructure:"varnamelen"` - Whitespace WhitespaceSettings `mapstructure:"whitespace"` - Wrapcheck WrapcheckSettings `mapstructure:"wrapcheck"` - WSL WSLSettings `mapstructure:"wsl"` + Asasalint AsasalintSettings `mapstructure:"asasalint"` + BiDiChk BiDiChkSettings `mapstructure:"bidichk"` + CopyLoopVar CopyLoopVarSettings `mapstructure:"copyloopvar"` + Cyclop CyclopSettings `mapstructure:"cyclop"` + Decorder DecorderSettings `mapstructure:"decorder"` + Depguard DepGuardSettings `mapstructure:"depguard"` + Dogsled DogsledSettings `mapstructure:"dogsled"` + Dupl DuplSettings `mapstructure:"dupl"` + DupWord DupWordSettings `mapstructure:"dupword"` + EmbeddedStructFieldCheck EmbeddedStructFieldCheckSettings `mapstructure:"embeddedstructfieldcheck"` + Errcheck ErrcheckSettings `mapstructure:"errcheck"` + ErrChkJSON ErrChkJSONSettings `mapstructure:"errchkjson"` + ErrorLint ErrorLintSettings `mapstructure:"errorlint"` + Exhaustive ExhaustiveSettings `mapstructure:"exhaustive"` + Exhaustruct ExhaustructSettings `mapstructure:"exhaustruct"` + Fatcontext FatcontextSettings `mapstructure:"fatcontext"` + Forbidigo ForbidigoSettings `mapstructure:"forbidigo"` + FuncOrder FuncOrderSettings `mapstructure:"funcorder"` + Funlen FunlenSettings `mapstructure:"funlen"` + GinkgoLinter GinkgoLinterSettings `mapstructure:"ginkgolinter"` + Gocognit GocognitSettings `mapstructure:"gocognit"` + GoChecksumType GoChecksumTypeSettings `mapstructure:"gochecksumtype"` + Goconst GoConstSettings `mapstructure:"goconst"` + Gocritic GoCriticSettings `mapstructure:"gocritic"` + Gocyclo GoCycloSettings `mapstructure:"gocyclo"` + Godot GodotSettings `mapstructure:"godot"` + Godox GodoxSettings `mapstructure:"godox"` + Goheader GoHeaderSettings `mapstructure:"goheader"` + GoModDirectives GoModDirectivesSettings `mapstructure:"gomoddirectives"` + Gomodguard GoModGuardSettings `mapstructure:"gomodguard"` + Gosec GoSecSettings `mapstructure:"gosec"` + Gosmopolitan GosmopolitanSettings `mapstructure:"gosmopolitan"` + Govet GovetSettings `mapstructure:"govet"` + Grouper GrouperSettings `mapstructure:"grouper"` + Iface IfaceSettings `mapstructure:"iface"` + ImportAs ImportAsSettings `mapstructure:"importas"` + Inamedparam INamedParamSettings `mapstructure:"inamedparam"` + InterfaceBloat InterfaceBloatSettings `mapstructure:"interfacebloat"` + Ireturn IreturnSettings `mapstructure:"ireturn"` + Lll LllSettings `mapstructure:"lll"` + LoggerCheck LoggerCheckSettings `mapstructure:"loggercheck"` + MaintIdx MaintIdxSettings `mapstructure:"maintidx"` + Makezero MakezeroSettings `mapstructure:"makezero"` + Misspell MisspellSettings `mapstructure:"misspell"` + Mnd MndSettings `mapstructure:"mnd"` + MustTag MustTagSettings `mapstructure:"musttag"` + Nakedret NakedretSettings `mapstructure:"nakedret"` + Nestif NestifSettings `mapstructure:"nestif"` + NilNil NilNilSettings `mapstructure:"nilnil"` + Nlreturn NlreturnSettings `mapstructure:"nlreturn"` + NoLintLint NoLintLintSettings `mapstructure:"nolintlint"` + NoNamedReturns NoNamedReturnsSettings `mapstructure:"nonamedreturns"` + ParallelTest ParallelTestSettings `mapstructure:"paralleltest"` + PerfSprint PerfSprintSettings `mapstructure:"perfsprint"` + Prealloc PreallocSettings `mapstructure:"prealloc"` + Predeclared PredeclaredSettings `mapstructure:"predeclared"` + Promlinter PromlinterSettings `mapstructure:"promlinter"` + ProtoGetter ProtoGetterSettings `mapstructure:"protogetter"` + Reassign ReassignSettings `mapstructure:"reassign"` + Recvcheck RecvcheckSettings `mapstructure:"recvcheck"` + Revive ReviveSettings `mapstructure:"revive"` + RowsErrCheck RowsErrCheckSettings `mapstructure:"rowserrcheck"` + SlogLint SlogLintSettings `mapstructure:"sloglint"` + Spancheck SpancheckSettings `mapstructure:"spancheck"` + Staticcheck StaticCheckSettings `mapstructure:"staticcheck"` + TagAlign TagAlignSettings `mapstructure:"tagalign"` + Tagliatelle TagliatelleSettings `mapstructure:"tagliatelle"` + Testifylint TestifylintSettings `mapstructure:"testifylint"` + Testpackage TestpackageSettings `mapstructure:"testpackage"` + Thelper ThelperSettings `mapstructure:"thelper"` + Unconvert UnconvertSettings `mapstructure:"unconvert"` + Unparam UnparamSettings `mapstructure:"unparam"` + Unused UnusedSettings `mapstructure:"unused"` + UseStdlibVars UseStdlibVarsSettings `mapstructure:"usestdlibvars"` + UseTesting UseTestingSettings `mapstructure:"usetesting"` + Varnamelen VarnamelenSettings `mapstructure:"varnamelen"` + Whitespace WhitespaceSettings `mapstructure:"whitespace"` + Wrapcheck WrapcheckSettings `mapstructure:"wrapcheck"` + WSL WSLSettings `mapstructure:"wsl"` Custom map[string]CustomLinterSettings `mapstructure:"custom"` } @@ -367,11 +368,16 @@ type DupWordSettings struct { Ignore []string `mapstructure:"ignore"` } +type EmbeddedStructFieldCheckSettings struct { + ForbidMutex bool `mapstructure:"forbid-mutex"` +} + type ErrcheckSettings struct { DisableDefaultExclusions bool `mapstructure:"disable-default-exclusions"` CheckTypeAssertions bool `mapstructure:"check-type-assertions"` CheckAssignToBlank bool `mapstructure:"check-blank"` ExcludeFunctions []string `mapstructure:"exclude-functions"` + Verbose bool `mapstructure:"verbose"` } type ErrChkJSONSettings struct { @@ -428,6 +434,7 @@ type ForbidigoPattern struct { type FuncOrderSettings struct { Constructor bool `mapstructure:"constructor,omitempty"` StructMethod bool `mapstructure:"struct-method,omitempty"` + Alphabetical bool `mapstructure:"alphabetical,omitempty"` } type FunlenSettings struct { @@ -927,6 +934,7 @@ type UseStdlibVarsSettings struct { SQLIsolationLevel bool `mapstructure:"sql-isolation-level"` TLSSignatureScheme bool `mapstructure:"tls-signature-scheme"` ConstantKind bool `mapstructure:"constant-kind"` + TimeDateMonth bool `mapstructure:"time-date-month"` } type UseTestingSettings struct { diff --git a/pkg/goanalysis/issue.go b/pkg/goanalysis/issue.go index c41702595c55..88a59e53dbc9 100644 --- a/pkg/goanalysis/issue.go +++ b/pkg/goanalysis/issue.go @@ -9,13 +9,13 @@ import ( ) type Issue struct { - result.Issue + *result.Issue Pass *analysis.Pass } -func NewIssue(issue *result.Issue, pass *analysis.Pass) Issue { - return Issue{ - Issue: *issue, +func NewIssue(issue *result.Issue, pass *analysis.Pass) *Issue { + return &Issue{ + Issue: issue, Pass: pass, } } diff --git a/pkg/goanalysis/linter.go b/pkg/goanalysis/linter.go index 80ccfe456408..153e538b5820 100644 --- a/pkg/goanalysis/linter.go +++ b/pkg/goanalysis/linter.go @@ -13,11 +13,6 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -const ( - TheOnlyAnalyzerName = "the_only_name" - TheOnlyanalyzerDoc = "the_only_doc" -) - type LoadMode int func (loadMode LoadMode) String() string { @@ -45,7 +40,7 @@ type Linter struct { name, desc string analyzers []*analysis.Analyzer cfg map[string]map[string]any - issuesReporter func(*linter.Context) []Issue + issuesReporter func(*linter.Context) []*Issue contextSetter func(*linter.Context) loadMode LoadMode needUseOriginalPackages bool @@ -55,7 +50,11 @@ func NewLinter(name, desc string, analyzers []*analysis.Analyzer, cfg map[string return &Linter{name: name, desc: desc, analyzers: analyzers, cfg: cfg} } -func (lnt *Linter) Run(_ context.Context, lintCtx *linter.Context) ([]result.Issue, error) { +func NewLinterFromAnalyzer(analyzer *analysis.Analyzer) *Linter { + return NewLinter(analyzer.Name, analyzer.Doc, []*analysis.Analyzer{analyzer}, nil) +} + +func (lnt *Linter) Run(_ context.Context, lintCtx *linter.Context) ([]*result.Issue, error) { if err := lnt.preRun(lintCtx); err != nil { return nil, err } @@ -71,12 +70,49 @@ func (lnt *Linter) LoadMode() LoadMode { return lnt.loadMode } +func (lnt *Linter) WithDesc(desc string) *Linter { + lnt.desc = desc + + return lnt +} + +func (lnt *Linter) WithVersion(v int) *Linter { + if v == 0 { + return lnt + } + + for _, analyzer := range lnt.analyzers { + if lnt.name != analyzer.Name { + continue + } + + // The analyzer name should be the same as the linter name to avoid displaying the name inside the reports. + analyzer.Name = fmt.Sprintf("%s_v%d", analyzer.Name, v) + } + + lnt.name = fmt.Sprintf("%s_v%d", lnt.name, v) + + return lnt +} + +func (lnt *Linter) WithConfig(cfg map[string]any) *Linter { + if len(cfg) == 0 { + return lnt + } + + lnt.cfg = map[string]map[string]any{ + lnt.name: cfg, + } + + return lnt +} + func (lnt *Linter) WithLoadMode(loadMode LoadMode) *Linter { lnt.loadMode = loadMode return lnt } -func (lnt *Linter) WithIssuesReporter(r func(*linter.Context) []Issue) *Linter { +func (lnt *Linter) WithIssuesReporter(r func(*linter.Context) []*Issue) *Linter { lnt.issuesReporter = r return lnt } @@ -176,7 +212,7 @@ func (lnt *Linter) useOriginalPackages() bool { return lnt.needUseOriginalPackages } -func (lnt *Linter) reportIssues(lintCtx *linter.Context) []Issue { +func (lnt *Linter) reportIssues(lintCtx *linter.Context) []*Issue { if lnt.issuesReporter != nil { return lnt.issuesReporter(lintCtx) } diff --git a/pkg/goanalysis/metalinter.go b/pkg/goanalysis/metalinter.go index 4db143baddb3..b9a210a66fc8 100644 --- a/pkg/goanalysis/metalinter.go +++ b/pkg/goanalysis/metalinter.go @@ -21,7 +21,7 @@ func NewMetaLinter(linters []*Linter) *MetaLinter { return ml } -func (ml MetaLinter) Run(_ context.Context, lintCtx *linter.Context) ([]result.Issue, error) { +func (ml MetaLinter) Run(_ context.Context, lintCtx *linter.Context) ([]*result.Issue, error) { for _, l := range ml.linters { if err := l.preRun(lintCtx); err != nil { return nil, fmt.Errorf("failed to pre-run %s: %w", l.Name(), err) @@ -65,8 +65,8 @@ func (MetaLinter) useOriginalPackages() bool { return false // `unused` can't be run by this metalinter } -func (ml MetaLinter) reportIssues(lintCtx *linter.Context) []Issue { - var ret []Issue +func (ml MetaLinter) reportIssues(lintCtx *linter.Context) []*Issue { + var ret []*Issue for _, lnt := range ml.linters { if lnt.issuesReporter != nil { ret = append(ret, lnt.issuesReporter(lintCtx)...) diff --git a/pkg/goanalysis/pkgerrors/errors.go b/pkg/goanalysis/pkgerrors/errors.go index 587e72720e98..062a8f43aeff 100644 --- a/pkg/goanalysis/pkgerrors/errors.go +++ b/pkg/goanalysis/pkgerrors/errors.go @@ -18,8 +18,8 @@ func (e *IllTypedError) Error() string { return fmt.Sprintf("IllTypedError: errors in package: %v", e.Pkg.Errors) } -func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]result.Issue, error) { - var issues []result.Issue +func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]*result.Issue, error) { + var issues []*result.Issue uniqReportedIssues := map[string]bool{} var other error @@ -43,7 +43,7 @@ func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]resu lintCtx.Log.Errorf("typechecking error: %s", err.Msg) } else { issue.Pkg = ill.Pkg // to save to cache later - issues = append(issues, *issue) + issues = append(issues, issue) } } } diff --git a/pkg/goanalysis/pkgerrors/parse.go b/pkg/goanalysis/pkgerrors/parse.go index 8c49a55929ed..2fe1fb529fa4 100644 --- a/pkg/goanalysis/pkgerrors/parse.go +++ b/pkg/goanalysis/pkgerrors/parse.go @@ -26,7 +26,7 @@ func parseError(srcErr packages.Error) (*result.Issue, error) { } func parseErrorPosition(pos string) (*token.Position, error) { - // file:line(:colon) + // file:line(:column) parts := strings.Split(pos, ":") if len(parts) == 1 { return nil, errors.New("no colons") @@ -39,7 +39,7 @@ func parseErrorPosition(pos string) (*token.Position, error) { } var column int - if len(parts) == 3 { // no column + if len(parts) == 3 { // got column column, err = strconv.Atoi(parts[2]) if err != nil { return nil, fmt.Errorf("failed to parse column from %q: %w", parts[2], err) diff --git a/pkg/goanalysis/runner.go b/pkg/goanalysis/runner.go index 808c9d2ad68c..6cc0a7077109 100644 --- a/pkg/goanalysis/runner.go +++ b/pkg/goanalysis/runner.go @@ -76,7 +76,7 @@ func newRunner(prefix string, logger logutils.Log, pkgCache *cache.Cache, loadGu // It provides most of the logic for the main functions of both the // singlechecker and the multi-analysis commands. // It returns the appropriate exit code. -func (r *runner) run(analyzers []*analysis.Analyzer, initialPackages []*packages.Package) ([]Diagnostic, +func (r *runner) run(analyzers []*analysis.Analyzer, initialPackages []*packages.Package) ([]*Diagnostic, []error, map[*analysis.Pass]*packages.Package, ) { debugf("Analyzing %d packages on load mode %s", len(initialPackages), r.loadMode) @@ -275,7 +275,7 @@ func (r *runner) analyze(pkgs []*packages.Package, analyzers []*analysis.Analyze return rootActions } -func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []error) { +func extractDiagnostics(roots []*action) (retDiags []*Diagnostic, retErrors []error) { extracted := make(map[*action]bool) var extract func(*action) var visitAll func(actions []*action) @@ -322,7 +322,7 @@ func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []err } seen[k] = true - retDiag := Diagnostic{ + retDiag := &Diagnostic{ File: file, Diagnostic: diag, Analyzer: act.Analyzer, diff --git a/pkg/goanalysis/runners.go b/pkg/goanalysis/runners.go index fe8d8fe854d3..bcbc0033ef9a 100644 --- a/pkg/goanalysis/runners.go +++ b/pkg/goanalysis/runners.go @@ -3,6 +3,7 @@ package goanalysis import ( "fmt" "go/token" + "slices" "strings" "golang.org/x/tools/go/analysis" @@ -20,11 +21,11 @@ type runAnalyzersConfig interface { getLinterNameForDiagnostic(*Diagnostic) string getAnalyzers() []*analysis.Analyzer useOriginalPackages() bool - reportIssues(*linter.Context) []Issue + reportIssues(*linter.Context) []*Issue getLoadMode() LoadMode } -func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Issue, error) { +func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]*result.Issue, error) { log := lintCtx.Log.Child(logutils.DebugKeyGoAnalysis) sw := timeutils.NewStopwatch("analyzers", log) @@ -56,18 +57,19 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss } }() - buildAllIssues := func() []result.Issue { - var retIssues []result.Issue + buildAllIssues := func() []*result.Issue { + var retIssues []*result.Issue + reportedIssues := cfg.reportIssues(lintCtx) - for i := range reportedIssues { - issue := &reportedIssues[i].Issue - if issue.Pkg == nil { - issue.Pkg = passToPkg[reportedIssues[i].Pass] + for _, reportedIssue := range reportedIssues { + if reportedIssue.Pkg == nil { + reportedIssue.Pkg = passToPkg[reportedIssue.Pass] } - retIssues = append(retIssues, *issue) + + retIssues = append(retIssues, reportedIssue.Issue) } - retIssues = append(retIssues, buildIssues(diags, cfg.getLinterNameForDiagnostic)...) - return retIssues + + return slices.Concat(retIssues, buildIssues(diags, cfg.getLinterNameForDiagnostic)) } errIssues, err := pkgerrors.BuildIssuesFromIllTypedError(errs, lintCtx) @@ -81,11 +83,10 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss return issues, nil } -func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) string) []result.Issue { - var issues []result.Issue +func buildIssues(diags []*Diagnostic, linterNameBuilder func(diag *Diagnostic) string) []*result.Issue { + var issues []*result.Issue - for i := range diags { - diag := &diags[i] + for _, diag := range diags { linterName := linterNameBuilder(diag) var text string @@ -126,7 +127,7 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st suggestedFixes = append(suggestedFixes, nsf) } - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ FromLinter: linterName, Text: text, Pos: diag.Position, @@ -142,7 +143,7 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st relatedPos = diag.Position } - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ FromLinter: linterName, Text: fmt.Sprintf("%s(related information): %s", diag.Analyzer.Name, info.Message), Pos: relatedPos, diff --git a/pkg/goanalysis/runners_cache.go b/pkg/goanalysis/runners_cache.go index 9673197c9ec9..5cd8a6b1ccd4 100644 --- a/pkg/goanalysis/runners_cache.go +++ b/pkg/goanalysis/runners_cache.go @@ -17,13 +17,12 @@ import ( ) func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.Package]bool, - issues []result.Issue, lintCtx *linter.Context, analyzers []*analysis.Analyzer, + issues []*result.Issue, lintCtx *linter.Context, analyzers []*analysis.Analyzer, ) { startedAt := time.Now() - perPkgIssues := map[*packages.Package][]result.Issue{} - for ind := range issues { - i := &issues[ind] - perPkgIssues[i.Pkg] = append(perPkgIssues[i.Pkg], *i) + perPkgIssues := map[*packages.Package][]*result.Issue{} + for _, issue := range issues { + perPkgIssues[issue.Pkg] = append(perPkgIssues[issue.Pkg], issue) } var savedIssuesCount int64 = 0 @@ -34,23 +33,22 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages. wg.Add(workerCount) pkgCh := make(chan *packages.Package, len(allPkgs)) - for i := 0; i < workerCount; i++ { + for range workerCount { go func() { defer wg.Done() for pkg := range pkgCh { pkgIssues := perPkgIssues[pkg] encodedIssues := make([]EncodingIssue, 0, len(pkgIssues)) - for ind := range pkgIssues { - i := &pkgIssues[ind] + for _, issue := range pkgIssues { encodedIssues = append(encodedIssues, EncodingIssue{ - FromLinter: i.FromLinter, - Text: i.Text, - Severity: i.Severity, - Pos: i.Pos, - LineRange: i.LineRange, - SuggestedFixes: i.SuggestedFixes, - ExpectNoLint: i.ExpectNoLint, - ExpectedNoLintLinter: i.ExpectedNoLintLinter, + FromLinter: issue.FromLinter, + Text: issue.Text, + Severity: issue.Severity, + Pos: issue.Pos, + LineRange: issue.LineRange, + SuggestedFixes: issue.SuggestedFixes, + ExpectNoLint: issue.ExpectNoLint, + ExpectedNoLintLinter: issue.ExpectedNoLintLinter, }) } @@ -81,12 +79,12 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages. func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, analyzers []*analysis.Analyzer, -) (issuesFromCache []result.Issue, pkgsFromCache map[*packages.Package]bool) { +) (issuesFromCache []*result.Issue, pkgsFromCache map[*packages.Package]bool) { startedAt := time.Now() lintResKey := getIssuesCacheKey(analyzers) type cacheRes struct { - issues []result.Issue + issues []*result.Issue loadErr error } pkgToCacheRes := make(map[*packages.Package]*cacheRes, len(pkgs)) @@ -103,7 +101,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, go func() { defer wg.Done() for pkg := range pkgCh { - var pkgIssues []EncodingIssue + var pkgIssues []*EncodingIssue err := lintCtx.PkgCache.Get(pkg, cache.HashModeNeedAllDeps, lintResKey, &pkgIssues) cacheRes := pkgToCacheRes[pkg] cacheRes.loadErr = err @@ -114,10 +112,9 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, continue } - issues := make([]result.Issue, 0, len(pkgIssues)) - for i := range pkgIssues { - issue := &pkgIssues[i] - issues = append(issues, result.Issue{ + issues := make([]*result.Issue, 0, len(pkgIssues)) + for _, issue := range pkgIssues { + issues = append(issues, &result.Issue{ FromLinter: issue.FromLinter, Text: issue.Text, Severity: issue.Severity, diff --git a/pkg/goformat/runner.go b/pkg/goformat/runner.go index fa1d1acc3019..f87626158179 100644 --- a/pkg/goformat/runner.go +++ b/pkg/goformat/runner.go @@ -57,7 +57,7 @@ func (c *Runner) Run(paths []string) error { } if c.opts.stdin { - return c.process("", savedStdout, os.Stdin) + return c.formatStdIn("", savedStdout, os.Stdin) } for _, path := range paths { @@ -121,15 +121,6 @@ func (c *Runner) process(path string, stdout io.Writer, in io.Reader) error { output := c.metaFormatter.Format(path, input) - if c.opts.stdin { - _, err = stdout.Write(output) - if err != nil { - return err - } - - return nil - } - if bytes.Equal(input, output) { return nil } @@ -168,6 +159,38 @@ func (c *Runner) process(path string, stdout io.Writer, in io.Reader) error { return os.WriteFile(path, output, perms) } +func (c *Runner) formatStdIn(path string, stdout io.Writer, in io.Reader) error { + input, err := io.ReadAll(in) + if err != nil { + return err + } + + match, err := c.matcher.IsGeneratedFile(path, input) + if err != nil { + return err + } + + if match { + // If the file is generated, + // the input should be written to the stdout to avoid emptied the file. + _, err = stdout.Write(input) + if err != nil { + return err + } + + return nil + } + + output := c.metaFormatter.Format(path, input) + + _, err = stdout.Write(output) + if err != nil { + return err + } + + return nil +} + func (c *Runner) setOutputToDevNull() { devNull, err := os.Open(os.DevNull) if err != nil { diff --git a/pkg/goformatters/internal/diff.go b/pkg/goformatters/internal/diff.go index 7b9f80bc4228..fcec87bb8bbd 100644 --- a/pkg/goformatters/internal/diff.go +++ b/pkg/goformatters/internal/diff.go @@ -250,10 +250,7 @@ func ExtractDiagnosticFromPatch( } func toDiagnostic(ft *token.File, change Change, adjLine int) analysis.Diagnostic { - from := change.From + adjLine - if from > ft.LineCount() { - from = ft.LineCount() - } + from := min(change.From+adjLine, ft.LineCount()) start := ft.LineStart(from) diff --git a/pkg/goformatters/meta_formatter.go b/pkg/goformatters/meta_formatter.go index 718caaa96003..dbedcd4cba19 100644 --- a/pkg/goformatters/meta_formatter.go +++ b/pkg/goformatters/meta_formatter.go @@ -12,6 +12,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goformatters/gofumpt" "github.com/golangci/golangci-lint/v2/pkg/goformatters/goimports" "github.com/golangci/golangci-lint/v2/pkg/goformatters/golines" + "github.com/golangci/golangci-lint/v2/pkg/goformatters/swaggo" "github.com/golangci/golangci-lint/v2/pkg/logutils" ) @@ -41,6 +42,10 @@ func NewMetaFormatter(log logutils.Log, cfg *config.Formatters, runCfg *config.R m.formatters = append(m.formatters, goimports.New(&cfg.Settings.GoImports)) } + if slices.Contains(cfg.Enable, swaggo.Name) { + m.formatters = append(m.formatters, swaggo.New()) + } + // gci is a last because the only goal of gci is to handle imports. if slices.Contains(cfg.Enable, gci.Name) { formatter, err := gci.New(&cfg.Settings.Gci) @@ -86,5 +91,5 @@ func (m *MetaFormatter) Format(filename string, src []byte) []byte { } func IsFormatter(name string) bool { - return slices.Contains([]string{gofmt.Name, gofumpt.Name, goimports.Name, gci.Name, golines.Name}, name) + return slices.Contains([]string{gofmt.Name, gofumpt.Name, goimports.Name, gci.Name, golines.Name, swaggo.Name}, name) } diff --git a/pkg/goformatters/swaggo/swaggo.go b/pkg/goformatters/swaggo/swaggo.go new file mode 100644 index 000000000000..2479fb35baba --- /dev/null +++ b/pkg/goformatters/swaggo/swaggo.go @@ -0,0 +1,23 @@ +package swaggo + +import "github.com/golangci/swaggoswag" + +const Name = "swaggo" + +type Formatter struct { + formatter *swaggoswag.Formatter +} + +func New() *Formatter { + return &Formatter{ + formatter: swaggoswag.NewFormatter(), + } +} + +func (*Formatter) Name() string { + return Name +} + +func (f *Formatter) Format(path string, src []byte) ([]byte, error) { + return f.formatter.Format(path, src) +} diff --git a/pkg/golinters/arangolint/arangolint.go b/pkg/golinters/arangolint/arangolint.go new file mode 100644 index 000000000000..1598d532a879 --- /dev/null +++ b/pkg/golinters/arangolint/arangolint.go @@ -0,0 +1,13 @@ +package arangolint + +import ( + "go.augendre.info/arangolint/pkg/analyzer" + + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" +) + +func New() *goanalysis.Linter { + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/golinters/arangolint/arangolint_integration_test.go b/pkg/golinters/arangolint/arangolint_integration_test.go new file mode 100644 index 000000000000..db0f1aef0923 --- /dev/null +++ b/pkg/golinters/arangolint/arangolint_integration_test.go @@ -0,0 +1,11 @@ +package arangolint + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} diff --git a/pkg/golinters/arangolint/testdata/arangolint.go b/pkg/golinters/arangolint/testdata/arangolint.go new file mode 100644 index 000000000000..1cc3f28a87c2 --- /dev/null +++ b/pkg/golinters/arangolint/testdata/arangolint.go @@ -0,0 +1,35 @@ +//golangcitest:args -Earangolint +package arangolint + +import ( + "context" + + "github.com/arangodb/go-driver/v2/arangodb" +) + +func _() { + ctx := context.Background() + arangoClient := arangodb.NewClient(nil) + db, _ := arangoClient.GetDatabase(ctx, "name", nil) + + // direct nil + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, nil) // want "missing AllowImplicit option" + trx, _ := db.BeginTransaction(ctx, arangodb.TransactionCollections{}, nil) // want "missing AllowImplicit option" + _ = trx + + // direct missing + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{LockTimeout: 0}) // want "missing AllowImplicit option" + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{LockTimeout: 0}) // want "missing AllowImplicit option" + + // direct false + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: false}) + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: false}) + + // direct true + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true}) + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true}) + + // direct with other fields + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true, LockTimeout: 0}) + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true, LockTimeout: 0}) +} diff --git a/pkg/golinters/arangolint/testdata/arangolint_cgo.go b/pkg/golinters/arangolint/testdata/arangolint_cgo.go new file mode 100644 index 000000000000..3bc9bc7fefb8 --- /dev/null +++ b/pkg/golinters/arangolint/testdata/arangolint_cgo.go @@ -0,0 +1,52 @@ +//golangcitest:args -Earangolint +package arangolint + +/* + #include + #include + + void myprint(char* s) { + printf("%d\n", s); + } +*/ +import "C" + +import ( + "context" + "unsafe" + + "github.com/arangodb/go-driver/v2/arangodb" +) + +func _() { + cs := C.CString("Hello from stdio\n") + C.myprint(cs) + C.free(unsafe.Pointer(cs)) +} + +func _() { + ctx := context.Background() + arangoClient := arangodb.NewClient(nil) + db, _ := arangoClient.GetDatabase(ctx, "name", nil) + + // direct nil + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, nil) // want "missing AllowImplicit option" + trx, _ := db.BeginTransaction(ctx, arangodb.TransactionCollections{}, nil) // want "missing AllowImplicit option" + _ = trx + + // direct missing + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{LockTimeout: 0}) // want "missing AllowImplicit option" + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{LockTimeout: 0}) // want "missing AllowImplicit option" + + // direct false + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: false}) + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: false}) + + // direct true + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true}) + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true}) + + // direct with other fields + db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true, LockTimeout: 0}) + trx, _ = db.BeginTransaction(ctx, arangodb.TransactionCollections{}, &arangodb.BeginTransactionOptions{AllowImplicit: true, LockTimeout: 0}) +} diff --git a/pkg/golinters/arangolint/testdata/go.mod b/pkg/golinters/arangolint/testdata/go.mod new file mode 100644 index 000000000000..0fb1fc8b4a4e --- /dev/null +++ b/pkg/golinters/arangolint/testdata/go.mod @@ -0,0 +1,19 @@ +module arangolint + +go 1.23.0 + +require github.com/arangodb/go-driver/v2 v2.1.3 + +require ( + github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e // indirect + github.com/dchest/siphash v1.2.3 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/kkdai/maglev v0.2.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/rs/zerolog v1.34.0 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect +) diff --git a/pkg/golinters/arangolint/testdata/go.sum b/pkg/golinters/arangolint/testdata/go.sum new file mode 100644 index 000000000000..69d72038590d --- /dev/null +++ b/pkg/golinters/arangolint/testdata/go.sum @@ -0,0 +1,47 @@ +github.com/arangodb/go-driver/v2 v2.1.3 h1:PpLSe8E2RalFuqTGi2yfHDe3ltOomfFCIToB66p1lr8= +github.com/arangodb/go-driver/v2 v2.1.3/go.mod h1:aoDzrsO7PQEFat3Q9pp4zfv6W+WotA7GcCeJQJfX+tc= +github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e h1:Xg+hGrY2LcQBbxd0ZFdbGSyRKTYMZCfBbw/pMJFOk1g= +github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e/go.mod h1:mq7Shfa/CaixoDxiyAAc5jZ6CVBAyPaNQCGS7mkj4Ho= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dchest/siphash v1.2.2/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4= +github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= +github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kkdai/maglev v0.2.0 h1:w6DCW0kAA6fstZqXkrBrlgIC3jeIRXkjOYea/m6EK/Y= +github.com/kkdai/maglev v0.2.0/go.mod h1:d+mt8Lmt3uqi9aRb/BnPjzD0fy+ETs1vVXiGRnqHVZ4= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/golinters/asasalint/asasalint.go b/pkg/golinters/asasalint/asasalint.go index 5f33428c2224..0261e109d8aa 100644 --- a/pkg/golinters/asasalint/asasalint.go +++ b/pkg/golinters/asasalint/asasalint.go @@ -2,7 +2,6 @@ package asasalint import ( "github.com/alingse/asasalint" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -19,15 +18,12 @@ func New(settings *config.AsasalintSettings) *goanalysis.Linter { cfg.IgnoreTest = false } - a, err := asasalint.NewAnalyzer(cfg) + analyzer, err := asasalint.NewAnalyzer(cfg) if err != nil { internal.LinterLogger.Fatalf("asasalint: create analyzer: %v", err) } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/asciicheck/asciicheck.go b/pkg/golinters/asciicheck/asciicheck.go index b5cdaa80bbeb..4872770365c6 100644 --- a/pkg/golinters/asciicheck/asciicheck.go +++ b/pkg/golinters/asciicheck/asciicheck.go @@ -2,18 +2,12 @@ package asciicheck import ( "github.com/tdakkota/asciicheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := asciicheck.NewAnalyzer() - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(asciicheck.NewAnalyzer()). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/bidichk/bidichk.go b/pkg/golinters/bidichk/bidichk.go index 2d2a8d664fa4..c35daafbfb77 100644 --- a/pkg/golinters/bidichk/bidichk.go +++ b/pkg/golinters/bidichk/bidichk.go @@ -4,16 +4,14 @@ import ( "strings" "github.com/breml/bidichk/pkg/bidichk" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.BiDiChkSettings) *goanalysis.Linter { - a := bidichk.NewAnalyzer() + var cfg map[string]any - cfg := map[string]map[string]any{} if settings != nil { var opts []string @@ -45,15 +43,13 @@ func New(settings *config.BiDiChkSettings) *goanalysis.Linter { opts = append(opts, "POP-DIRECTIONAL-ISOLATE") } - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "disallowed-runes": strings.Join(opts, ","), } } - return goanalysis.NewLinter( - a.Name, - "Checks for dangerous unicode character sequences", - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(bidichk.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/bodyclose/bodyclose.go b/pkg/golinters/bodyclose/bodyclose.go index 0c86fbe76513..f68c4d0a9e6a 100644 --- a/pkg/golinters/bodyclose/bodyclose.go +++ b/pkg/golinters/bodyclose/bodyclose.go @@ -2,18 +2,12 @@ package bodyclose import ( "github.com/timakin/bodyclose/passes/bodyclose" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := bodyclose.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(bodyclose.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/canonicalheader/canonicalheader.go b/pkg/golinters/canonicalheader/canonicalheader.go index bda1dfbd20d3..24e95f143e9d 100644 --- a/pkg/golinters/canonicalheader/canonicalheader.go +++ b/pkg/golinters/canonicalheader/canonicalheader.go @@ -2,18 +2,12 @@ package canonicalheader import ( "github.com/lasiar/canonicalheader" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := canonicalheader.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(canonicalheader.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/containedctx/containedctx.go b/pkg/golinters/containedctx/containedctx.go index 6bdb08350dd7..6d17b8e46fcf 100644 --- a/pkg/golinters/containedctx/containedctx.go +++ b/pkg/golinters/containedctx/containedctx.go @@ -2,18 +2,12 @@ package containedctx import ( "github.com/sivchari/containedctx" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := containedctx.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(containedctx.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/contextcheck/contextcheck.go b/pkg/golinters/contextcheck/contextcheck.go index 9d01fb7a2038..88c71d2d3eb2 100644 --- a/pkg/golinters/contextcheck/contextcheck.go +++ b/pkg/golinters/contextcheck/contextcheck.go @@ -2,7 +2,6 @@ package contextcheck import ( "github.com/kkHAIKE/contextcheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/lint/linter" @@ -11,12 +10,10 @@ import ( func New() *goanalysis.Linter { analyzer := contextcheck.NewAnalyzer(contextcheck.Configuration{}) - return goanalysis.NewLinter( - analyzer.Name, - analyzer.Doc, - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - analyzer.Run = contextcheck.NewRun(lintCtx.Packages, false) - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + analyzer.Run = contextcheck.NewRun(lintCtx.Packages, false) + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/copyloopvar/copyloopvar.go b/pkg/golinters/copyloopvar/copyloopvar.go index f6ca96f99567..9dc81de58af2 100644 --- a/pkg/golinters/copyloopvar/copyloopvar.go +++ b/pkg/golinters/copyloopvar/copyloopvar.go @@ -2,28 +2,22 @@ package copyloopvar import ( "github.com/karamaru-alpha/copyloopvar" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.CopyLoopVarSettings) *goanalysis.Linter { - a := copyloopvar.NewAnalyzer() + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - "check-alias": settings.CheckAlias, - }, + cfg = map[string]any{ + "check-alias": settings.CheckAlias, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(copyloopvar.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/cyclop/cyclop.go b/pkg/golinters/cyclop/cyclop.go index 41db272cd4e3..0a0e2dbc635b 100644 --- a/pkg/golinters/cyclop/cyclop.go +++ b/pkg/golinters/cyclop/cyclop.go @@ -2,37 +2,29 @@ package cyclop import ( "github.com/bkielbasa/cyclop/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.CyclopSettings) *goanalysis.Linter { - a := analyzer.NewAnalyzer() + cfg := map[string]any{} - var cfg map[string]map[string]any if settings != nil { - d := map[string]any{ - // Should be managed with `linters.exclusions.rules`. - "skipTests": false, - } + // Should be managed with `linters.exclusions.rules`. + cfg["skipTests"] = false if settings.MaxComplexity != 0 { - d["maxComplexity"] = settings.MaxComplexity + cfg["maxComplexity"] = settings.MaxComplexity } if settings.PackageAverage != 0 { - d["packageAverage"] = settings.PackageAverage + cfg["packageAverage"] = settings.PackageAverage } - - cfg = map[string]map[string]any{a.Name: d} } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/decorder/decorder.go b/pkg/golinters/decorder/decorder.go index 03a7853c27e2..a67bdfade155 100644 --- a/pkg/golinters/decorder/decorder.go +++ b/pkg/golinters/decorder/decorder.go @@ -4,15 +4,12 @@ import ( "strings" "gitlab.com/bosi/decorder" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.DecorderSettings) *goanalysis.Linter { - a := decorder.Analyzer - // disable all rules/checks by default cfg := map[string]any{ "ignore-underscore-vars": false, @@ -35,10 +32,8 @@ func New(settings *config.DecorderSettings) *goanalysis.Linter { cfg["disable-init-func-first-check"] = settings.DisableInitFuncFirstCheck } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - map[string]map[string]any{a.Name: cfg}, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(decorder.Analyzer). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/depguard/depguard.go b/pkg/golinters/depguard/depguard.go index c1f66b0c81cc..cc01f4f47ab5 100644 --- a/pkg/golinters/depguard/depguard.go +++ b/pkg/golinters/depguard/depguard.go @@ -4,7 +4,6 @@ import ( "strings" "github.com/OpenPeeDeeP/depguard/v2" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -41,17 +40,15 @@ func New(settings *config.DepGuardSettings, replacer *strings.Replacer) *goanaly } } - a := depguard.NewUncompiledAnalyzer(&conf) - - return goanalysis.NewLinter( - a.Analyzer.Name, - a.Analyzer.Doc, - []*analysis.Analyzer{a.Analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - err := a.Compile() - if err != nil { - lintCtx.Log.Errorf("create analyzer: %v", err) - } - }).WithLoadMode(goanalysis.LoadModeSyntax) + analyzer := depguard.NewUncompiledAnalyzer(&conf) + + return goanalysis. + NewLinterFromAnalyzer(analyzer.Analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + err := analyzer.Compile() + if err != nil { + lintCtx.Log.Errorf("create analyzer: %v", err) + } + }). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/dogsled/dogsled.go b/pkg/golinters/dogsled/dogsled.go index 23d48ba57274..c5e872182cc7 100644 --- a/pkg/golinters/dogsled/dogsled.go +++ b/pkg/golinters/dogsled/dogsled.go @@ -11,24 +11,17 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "dogsled" - func New(settings *config.DogsledSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - return run(pass, settings.MaxBlankIdentifiers) - }, - Requires: []*analysis.Analyzer{inspect.Analyzer}, - } - - return goanalysis.NewLinter( - linterName, - "Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "dogsled", + Doc: "Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())", + Run: func(pass *analysis.Pass) (any, error) { + return run(pass, settings.MaxBlankIdentifiers) + }, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func run(pass *analysis.Pass, maxBlanks int) (any, error) { diff --git a/pkg/golinters/dupl/dupl.go b/pkg/golinters/dupl/dupl.go index 993bfd6f2326..0b6b3a162c2e 100644 --- a/pkg/golinters/dupl/dupl.go +++ b/pkg/golinters/dupl/dupl.go @@ -20,40 +20,36 @@ const linterName = "dupl" func New(settings *config.DuplSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues, err := runDupl(pass, settings) - if err != nil { - return nil, err - } - - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } + var resIssues []*goanalysis.Issue + + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Detects duplicate fragments of code.", + Run: func(pass *analysis.Pass) (any, error) { + issues, err := runDupl(pass, settings) + if err != nil { + return nil, err + } + + if len(issues) == 0 { + return nil, nil + } + + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return goanalysis.NewLinter( - linterName, - "Detects duplicate fragments of code.", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } -func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.Issue, error) { +func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]*goanalysis.Issue, error) { issues, err := duplAPI.Run(internal.GetGoFileNames(pass), settings.Threshold) if err != nil { return nil, err @@ -63,7 +59,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I return nil, nil } - res := make([]goanalysis.Issue, 0, len(issues)) + res := make([]*goanalysis.Issue, 0, len(issues)) for _, i := range issues { toFilename, err := fsutils.ShortestRelPath(i.To.Filename(), "") @@ -74,7 +70,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I dupl := fmt.Sprintf("%s:%d-%d", toFilename, i.To.LineStart(), i.To.LineEnd()) text := fmt.Sprintf("%d-%d lines are duplicate of %s", i.From.LineStart(), i.From.LineEnd(), - internal.FormatCode(dupl, nil)) + internal.FormatCode(dupl)) res = append(res, goanalysis.NewIssue(&result.Issue{ Pos: token.Position{ diff --git a/pkg/golinters/dupword/dupword.go b/pkg/golinters/dupword/dupword.go index 62851475f608..7b989bc22a8f 100644 --- a/pkg/golinters/dupword/dupword.go +++ b/pkg/golinters/dupword/dupword.go @@ -4,27 +4,24 @@ import ( "strings" "github.com/Abirdcfly/dupword" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.DupWordSettings) *goanalysis.Linter { - a := dupword.NewAnalyzer() + var cfg map[string]any - cfg := map[string]map[string]any{} if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "keyword": strings.Join(settings.Keywords, ","), "ignore": strings.Join(settings.Ignore, ","), } } - return goanalysis.NewLinter( - a.Name, - "checks for duplicate words in the source code", - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(dupword.NewAnalyzer()). + WithDesc("Checks for duplicate words in the source code"). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/durationcheck/durationcheck.go b/pkg/golinters/durationcheck/durationcheck.go index d3e74231f5b3..b6723fa12574 100644 --- a/pkg/golinters/durationcheck/durationcheck.go +++ b/pkg/golinters/durationcheck/durationcheck.go @@ -2,18 +2,12 @@ package durationcheck import ( "github.com/charithe/durationcheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := durationcheck.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(durationcheck.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck.go b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck.go new file mode 100644 index 000000000000..c9df5038c064 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck.go @@ -0,0 +1,23 @@ +package embeddedstructfieldcheck + +import ( + "github.com/manuelarte/embeddedstructfieldcheck/analyzer" + + "github.com/golangci/golangci-lint/v2/pkg/config" + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" +) + +func New(settings *config.EmbeddedStructFieldCheckSettings) *goanalysis.Linter { + var cfg map[string]any + + if settings != nil { + cfg = map[string]any{ + analyzer.ForbidMutexName: settings.ForbidMutex, + } + } + + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go new file mode 100644 index 000000000000..ba4258467733 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go @@ -0,0 +1,19 @@ +package embeddedstructfieldcheck + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} + +func TestFix(t *testing.T) { + integration.RunFix(t) +} + +func TestFixPathPrefix(t *testing.T) { + integration.RunFixPathPrefix(t) +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go new file mode 100644 index 000000000000..8dd119ede62a --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go @@ -0,0 +1,27 @@ +//golangcitest:args -Eembeddedstructfieldcheck +package testdata + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + // version Single line comment + // very long comment + version int +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_mutex.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_mutex.go new file mode 100644 index 000000000000..e0a586ef6f02 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_mutex.go @@ -0,0 +1,29 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:config_path testdata/embeddedstructfieldcheck_mutex.yml +package testdata + +import "sync" + +type MutextEmbedded struct { + sync.Mutex // want `sync.Mutex should not be embedded` +} + +type MutextNotEmbedded struct { + mu sync.Mutex +} + +type PointerMutextEmbedded struct { + *sync.Mutex // want `sync.Mutex should not be embedded` +} + +type RWMutextEmbedded struct { + sync.RWMutex // want `sync.RWMutex should not be embedded` +} + +type RWMutextNotEmbedded struct { + mu sync.RWMutex +} + +type PointerRWMutextEmbedded struct { + *sync.RWMutex // want `sync.RWMutex should not be embedded` +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_mutex.yml b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_mutex.yml new file mode 100644 index 000000000000..ff5e68bc81e3 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_mutex.yml @@ -0,0 +1,6 @@ +version: "2" + +linters: + settings: + embeddedstructfieldcheck: + forbid-mutex: true diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go new file mode 100644 index 000000000000..da13d29c95f7 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedstructfieldcheck +package testdata + +import ( + "context" + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} + +type NotSortedStruct struct { + version int + + time.Time // want `embedded fields should be listed before regular fields` +} + +type MixedEmbeddedAndNotEmbedded struct { + context.Context + + name string + + time.Time // want `embedded fields should be listed before regular fields` + + age int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go new file mode 100644 index 000000000000..b9ae5f3e187c --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go @@ -0,0 +1,11 @@ +//golangcitest:args -Eembeddedstructfieldcheck +package testdata + +import "time" + +func myFunction() { + type myType struct { + version int + time.Time // want `embedded fields should be listed before regular fields` + } +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go new file mode 100644 index 000000000000..5cd45dc171b7 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + // very long comment + version int +} + +type A struct { + // comment + ValidStructWithSingleLineComments + // C is foo + StructWithSingleLineComments // want `there must be an empty line separating embedded fields from regular fields` + + D string +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go new file mode 100644 index 000000000000..578ddc0d170e --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go @@ -0,0 +1,23 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import ( + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go new file mode 100644 index 000000000000..5cd45dc171b7 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + // very long comment + version int +} + +type A struct { + // comment + ValidStructWithSingleLineComments + // C is foo + StructWithSingleLineComments // want `there must be an empty line separating embedded fields from regular fields` + + D string +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go new file mode 100644 index 000000000000..a35f19ff4a15 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go @@ -0,0 +1,25 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import ( + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + version int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + + version int +} diff --git a/pkg/golinters/err113/err113.go b/pkg/golinters/err113/err113.go index 78ef99d6a1a9..d3b3a4c1cca7 100644 --- a/pkg/golinters/err113/err113.go +++ b/pkg/golinters/err113/err113.go @@ -2,18 +2,13 @@ package err113 import ( "github.com/Djarvur/go-err113" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := err113.NewAnalyzer() - - return goanalysis.NewLinter( - a.Name, - "Go linter to check the errors handling expressions", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(err113.NewAnalyzer()). + WithDesc("Check errors handling expressions"). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/errcheck/errcheck.go b/pkg/golinters/errcheck/errcheck.go index 56d00c350b4f..6bd473845c3f 100644 --- a/pkg/golinters/errcheck/errcheck.go +++ b/pkg/golinters/errcheck/errcheck.go @@ -21,43 +21,42 @@ const linterName = "errcheck" func New(settings *config.ErrcheckSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue analyzer := &analysis.Analyzer{ Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: goanalysis.DummyRun, + Doc: "errcheck is a program for checking for unchecked errors in Go code. " + + "These unchecked errors can be critical bugs in some cases", + Run: goanalysis.DummyRun, } - return goanalysis.NewLinter( - linterName, - "errcheck is a program for checking for unchecked errors in Go code. "+ - "These unchecked errors can be critical bugs in some cases", - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - checker := getChecker(settings) - checker.Tags = lintCtx.Cfg.Run.BuildTags + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + checker := getChecker(settings) + checker.Tags = lintCtx.Cfg.Run.BuildTags - analyzer.Run = func(pass *analysis.Pass) (any, error) { - issues := runErrCheck(lintCtx, pass, checker) + analyzer.Run = func(pass *analysis.Pass) (any, error) { + issues := runErrCheck(pass, checker, settings.Verbose) - if len(issues) == 0 { - return nil, nil - } + if len(issues) == 0 { + return nil, nil + } - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + return nil, nil + } + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Issue { +func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker, verbose bool) []*goanalysis.Issue { pkg := &packages.Package{ Fset: pass.Fset, Syntax: pass.Files, @@ -70,15 +69,18 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck return nil } - issues := make([]goanalysis.Issue, len(lintIssues.UncheckedErrors)) + issues := make([]*goanalysis.Issue, len(lintIssues.UncheckedErrors)) for i, err := range lintIssues.UncheckedErrors { text := "Error return value is not checked" if err.FuncName != "" { code := cmp.Or(err.SelectorName, err.FuncName) + if verbose { + code = err.FuncName + } - text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code, lintCtx.Cfg)) + text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code)) } issues[i] = goanalysis.NewIssue( diff --git a/pkg/golinters/errchkjson/errchkjson.go b/pkg/golinters/errchkjson/errchkjson.go index a705406e49f5..02510ab49901 100644 --- a/pkg/golinters/errchkjson/errchkjson.go +++ b/pkg/golinters/errchkjson/errchkjson.go @@ -2,30 +2,25 @@ package errchkjson import ( "github.com/breml/errchkjson" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.ErrChkJSONSettings) *goanalysis.Linter { - a := errchkjson.NewAnalyzer() - - cfg := map[string]map[string]any{} - cfg[a.Name] = map[string]any{ + cfg := map[string]any{ "omit-safe": true, } + if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "omit-safe": !settings.CheckErrorFreeEncoding, "report-no-exported": settings.ReportNoExported, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(errchkjson.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/errname/errname.go b/pkg/golinters/errname/errname.go index 36d6f12356fd..a66f3211f4e9 100644 --- a/pkg/golinters/errname/errname.go +++ b/pkg/golinters/errname/errname.go @@ -2,18 +2,12 @@ package errname import ( "github.com/Antonboom/errname/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := analyzer.New() - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.New()). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/errorlint/errorlint.go b/pkg/golinters/errorlint/errorlint.go index 7560bc0af90b..f32217796920 100644 --- a/pkg/golinters/errorlint/errorlint.go +++ b/pkg/golinters/errorlint/errorlint.go @@ -2,7 +2,6 @@ package errorlint import ( "github.com/polyfloyd/go-errorlint/errorlint" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -23,12 +22,10 @@ func New(settings *config.ErrorLintSettings) *goanalysis.Linter { } } - a := errorlint.NewAnalyzer(opts...) - - cfg := map[string]map[string]any{} + var cfg map[string]any if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "errorf": settings.Errorf, "errorf-multi": settings.ErrorfMulti, "asserts": settings.Asserts, @@ -36,13 +33,11 @@ func New(settings *config.ErrorLintSettings) *goanalysis.Linter { } } - return goanalysis.NewLinter( - a.Name, - "errorlint is a linter for that can be used to find code "+ - "that will cause problems with the error wrapping scheme introduced in Go 1.13.", - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(errorlint.NewAnalyzer(opts...)). + WithDesc("Find code that can cause problems with the error wrapping scheme introduced in Go 1.13."). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } func toAllowPairs(data []config.ErrorLintAllowPair) []errorlint.AllowPair { diff --git a/pkg/golinters/exhaustive/exhaustive.go b/pkg/golinters/exhaustive/exhaustive.go index be77e54a4bc6..ec240739d69e 100644 --- a/pkg/golinters/exhaustive/exhaustive.go +++ b/pkg/golinters/exhaustive/exhaustive.go @@ -2,37 +2,31 @@ package exhaustive import ( "github.com/nishanths/exhaustive" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.ExhaustiveSettings) *goanalysis.Linter { - a := exhaustive.Analyzer + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - exhaustive.CheckFlag: settings.Check, - exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive, - exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers, - exhaustive.IgnoreEnumTypesFlag: settings.IgnoreEnumTypes, - exhaustive.PackageScopeOnlyFlag: settings.PackageScopeOnly, - exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap, - exhaustive.ExplicitExhaustiveSwitchFlag: settings.ExplicitExhaustiveSwitch, - exhaustive.DefaultCaseRequiredFlag: settings.DefaultCaseRequired, - // Should be managed with `linters.exclusions.generated`. - exhaustive.CheckGeneratedFlag: true, - }, + cfg = map[string]any{ + exhaustive.CheckFlag: settings.Check, + exhaustive.DefaultSignifiesExhaustiveFlag: settings.DefaultSignifiesExhaustive, + exhaustive.IgnoreEnumMembersFlag: settings.IgnoreEnumMembers, + exhaustive.IgnoreEnumTypesFlag: settings.IgnoreEnumTypes, + exhaustive.PackageScopeOnlyFlag: settings.PackageScopeOnly, + exhaustive.ExplicitExhaustiveMapFlag: settings.ExplicitExhaustiveMap, + exhaustive.ExplicitExhaustiveSwitchFlag: settings.ExplicitExhaustiveSwitch, + exhaustive.DefaultCaseRequiredFlag: settings.DefaultCaseRequired, + // Should be managed with `linters.exclusions.generated`. + exhaustive.CheckGeneratedFlag: true, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(exhaustive.Analyzer). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/exhaustruct/exhaustruct.go b/pkg/golinters/exhaustruct/exhaustruct.go index 9b742129969d..290878e1c404 100644 --- a/pkg/golinters/exhaustruct/exhaustruct.go +++ b/pkg/golinters/exhaustruct/exhaustruct.go @@ -1,8 +1,7 @@ package exhaustruct import ( - "github.com/GaijinEntertainment/go-exhaustruct/v3/analyzer" - "golang.org/x/tools/go/analysis" + exhaustruct "github.com/GaijinEntertainment/go-exhaustruct/v3/analyzer" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -11,20 +10,18 @@ import ( func New(settings *config.ExhaustructSettings) *goanalysis.Linter { var include, exclude []string + if settings != nil { include = settings.Include exclude = settings.Exclude } - a, err := analyzer.NewAnalyzer(include, exclude) + analyzer, err := exhaustruct.NewAnalyzer(include, exclude) if err != nil { internal.LinterLogger.Fatalf("exhaustruct configuration: %v", err) } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/exptostd/exptostd.go b/pkg/golinters/exptostd/exptostd.go index 731a4a0ccad7..dbd78dce91cb 100644 --- a/pkg/golinters/exptostd/exptostd.go +++ b/pkg/golinters/exptostd/exptostd.go @@ -2,18 +2,12 @@ package exptostd import ( "github.com/ldez/exptostd" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := exptostd.NewAnalyzer() - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(exptostd.NewAnalyzer()). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/exptostd/testdata/go.mod b/pkg/golinters/exptostd/testdata/go.mod index 5261142a3036..3bd4f2c04ce5 100644 --- a/pkg/golinters/exptostd/testdata/go.mod +++ b/pkg/golinters/exptostd/testdata/go.mod @@ -1,5 +1,5 @@ module exptostd -go 1.22.0 +go 1.23.0 -require golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 +require golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 diff --git a/pkg/golinters/exptostd/testdata/go.sum b/pkg/golinters/exptostd/testdata/go.sum index c487fae960b3..2fbef45b9043 100644 --- a/pkg/golinters/exptostd/testdata/go.sum +++ b/pkg/golinters/exptostd/testdata/go.sum @@ -1,2 +1,2 @@ -golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo= -golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= +golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI= +golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ= diff --git a/pkg/golinters/fatcontext/fatcontext.go b/pkg/golinters/fatcontext/fatcontext.go index e0506259bee9..58933c660588 100644 --- a/pkg/golinters/fatcontext/fatcontext.go +++ b/pkg/golinters/fatcontext/fatcontext.go @@ -2,27 +2,22 @@ package fatcontext import ( "go.augendre.info/fatcontext/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.FatcontextSettings) *goanalysis.Linter { - a := analyzer.NewAnalyzer() - - cfg := map[string]map[string]any{} + var cfg map[string]any if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ analyzer.FlagCheckStructPointers: settings.CheckStructPointers, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/forbidigo/forbidigo.go b/pkg/golinters/forbidigo/forbidigo.go index 45f9088fa97d..796faf3a6ef0 100644 --- a/pkg/golinters/forbidigo/forbidigo.go +++ b/pkg/golinters/forbidigo/forbidigo.go @@ -3,7 +3,7 @@ package forbidigo import ( "fmt" - "github.com/ashanbrown/forbidigo/forbidigo" + "github.com/ashanbrown/forbidigo/v2/forbidigo" "golang.org/x/tools/go/analysis" "gopkg.in/yaml.v3" @@ -15,28 +15,23 @@ import ( const linterName = "forbidigo" func New(settings *config.ForbidigoSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - err := runForbidigo(pass, settings) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - // Without AnalyzeTypes, LoadModeSyntax is enough. // But we cannot make this depend on the settings and have to mirror the mode chosen in GetAllSupportedLinterConfigs, - // therefore we have to use LoadModeTypesInfo in all cases. - return goanalysis.NewLinter( - linterName, - "Forbids identifiers", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + // therefore, we have to use LoadModeTypesInfo in all cases. + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Forbids identifiers", + Run: func(pass *analysis.Pass) (any, error) { + err := runForbidigo(pass, settings) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) error { diff --git a/pkg/golinters/forcetypeassert/forcetypeassert.go b/pkg/golinters/forcetypeassert/forcetypeassert.go index e82355380c25..19a0e3450b37 100644 --- a/pkg/golinters/forcetypeassert/forcetypeassert.go +++ b/pkg/golinters/forcetypeassert/forcetypeassert.go @@ -2,18 +2,13 @@ package forcetypeassert import ( "github.com/gostaticanalysis/forcetypeassert" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := forcetypeassert.Analyzer - - return goanalysis.NewLinter( - a.Name, - "finds forced type assertions", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(forcetypeassert.Analyzer). + WithDesc("Find forced type assertions"). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/funcorder/funcorder.go b/pkg/golinters/funcorder/funcorder.go index 7b8e9689e587..06400753ebdb 100644 --- a/pkg/golinters/funcorder/funcorder.go +++ b/pkg/golinters/funcorder/funcorder.go @@ -2,28 +2,24 @@ package funcorder import ( "github.com/manuelarte/funcorder/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.FuncOrderSettings) *goanalysis.Linter { - a := analyzer.NewAnalyzer() - - cfg := map[string]map[string]any{} + var cfg map[string]any if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ analyzer.ConstructorCheckName: settings.Constructor, analyzer.StructMethodCheckName: settings.StructMethod, + analyzer.AlphabeticalCheckName: settings.Alphabetical, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/funlen/funlen.go b/pkg/golinters/funlen/funlen.go index 541d4fd36041..6e0f93b51303 100644 --- a/pkg/golinters/funlen/funlen.go +++ b/pkg/golinters/funlen/funlen.go @@ -2,7 +2,6 @@ package funlen import ( "github.com/ultraware/funlen" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -22,12 +21,7 @@ func New(settings *config.FunlenSettings) *goanalysis.Linter { cfg.ignoreComments = settings.IgnoreComments } - a := funlen.NewAnalyzer(cfg.lineLimit, cfg.stmtLimit, cfg.ignoreComments) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(funlen.NewAnalyzer(cfg.lineLimit, cfg.stmtLimit, cfg.ignoreComments)). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gci/gci.go b/pkg/golinters/gci/gci.go index 627a4e6849f2..4357a3b15fc1 100644 --- a/pkg/golinters/gci/gci.go +++ b/pkg/golinters/gci/gci.go @@ -1,8 +1,6 @@ package gci import ( - "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/goformatters" @@ -18,16 +16,13 @@ func New(settings *config.GciSettings) *goanalysis.Linter { internal.LinterLogger.Fatalf("%s: create analyzer: %v", linterName, err) } - a := goformatters.NewAnalyzer( - internal.LinterLogger.Child(linterName), - "Checks if code and import statements are formatted, with additional rules.", - formatter, - ) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer( + goformatters.NewAnalyzer( + internal.LinterLogger.Child(linterName), + "Check if code and import statements are formatted, with additional rules.", + formatter, + ), + ). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/ginkgolinter/ginkgolinter.go b/pkg/golinters/ginkgolinter/ginkgolinter.go index f4521cdaf81f..519e968e5d8b 100644 --- a/pkg/golinters/ginkgolinter/ginkgolinter.go +++ b/pkg/golinters/ginkgolinter/ginkgolinter.go @@ -3,7 +3,6 @@ package ginkgolinter import ( "github.com/nunnatsa/ginkgolinter" "github.com/nunnatsa/ginkgolinter/types" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -29,12 +28,8 @@ func New(settings *config.GinkgoLinterSettings) *goanalysis.Linter { } } - a := ginkgolinter.NewAnalyzerWithConfig(cfg) - - return goanalysis.NewLinter( - a.Name, - "enforces standards of using ginkgo and gomega", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(ginkgolinter.NewAnalyzerWithConfig(cfg)). + WithDesc("enforces standards of using ginkgo and gomega"). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/ginkgolinter/testdata/go.mod b/pkg/golinters/ginkgolinter/testdata/go.mod index b9c242a0ded4..078968acadbb 100644 --- a/pkg/golinters/ginkgolinter/testdata/go.mod +++ b/pkg/golinters/ginkgolinter/testdata/go.mod @@ -3,18 +3,19 @@ module ginkgolinter go 1.23.0 require ( - github.com/onsi/ginkgo/v2 v2.23.3 + github.com/onsi/ginkgo/v2 v2.23.4 github.com/onsi/gomega v1.37.0 ) require ( - github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/logr v1.4.3 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.7.0 // indirect - github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect - golang.org/x/net v0.37.0 // indirect - golang.org/x/sys v0.31.0 // indirect - golang.org/x/text v0.23.0 // indirect - golang.org/x/tools v0.30.0 // indirect + github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect + go.uber.org/automaxprocs v1.6.0 // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect + golang.org/x/tools v0.33.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/pkg/golinters/ginkgolinter/testdata/go.sum b/pkg/golinters/ginkgolinter/testdata/go.sum index 4a6722c54bc5..29f1ee9e9a59 100644 --- a/pkg/golinters/ginkgolinter/testdata/go.sum +++ b/pkg/golinters/ginkgolinter/testdata/go.sum @@ -1,32 +1,41 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= -github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0= -github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus= +github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8= github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y= github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= -golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= -golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= -golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= -golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= +go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= +go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/golinters/gocheckcompilerdirectives/gocheckcompilerdirectives.go b/pkg/golinters/gocheckcompilerdirectives/gocheckcompilerdirectives.go index 97534848d802..71f4be8c41db 100644 --- a/pkg/golinters/gocheckcompilerdirectives/gocheckcompilerdirectives.go +++ b/pkg/golinters/gocheckcompilerdirectives/gocheckcompilerdirectives.go @@ -2,18 +2,12 @@ package gocheckcompilerdirectives import ( "4d63.com/gocheckcompilerdirectives/checkcompilerdirectives" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := checkcompilerdirectives.Analyzer() - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(checkcompilerdirectives.Analyzer()). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gochecknoglobals/gochecknoglobals.go b/pkg/golinters/gochecknoglobals/gochecknoglobals.go index 8d850a2de59f..2fd3f3c3bee1 100644 --- a/pkg/golinters/gochecknoglobals/gochecknoglobals.go +++ b/pkg/golinters/gochecknoglobals/gochecknoglobals.go @@ -2,18 +2,13 @@ package gochecknoglobals import ( "4d63.com/gochecknoglobals/checknoglobals" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := checknoglobals.Analyzer() - - return goanalysis.NewLinter( - a.Name, - "Check that no global variables exist.", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(checknoglobals.Analyzer()). + WithDesc("Check that no global variables exist."). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/gochecknoinits/gochecknoinits.go b/pkg/golinters/gochecknoinits/gochecknoinits.go index b5fa6f0d4117..9158ee07da55 100644 --- a/pkg/golinters/gochecknoinits/gochecknoinits.go +++ b/pkg/golinters/gochecknoinits/gochecknoinits.go @@ -11,22 +11,15 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) -const linterName = "gochecknoinits" - func New() *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: run, - Requires: []*analysis.Analyzer{inspect.Analyzer}, - } - - return goanalysis.NewLinter( - linterName, - "Checks that no init functions are present in Go code", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "gochecknoinits", + Doc: "Checks that no init functions are present in Go code", + Run: run, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func run(pass *analysis.Pass) (any, error) { @@ -47,7 +40,7 @@ func run(pass *analysis.Pass) (any, error) { fnName := funcDecl.Name.Name if fnName == "init" && funcDecl.Recv.NumFields() == 0 { - pass.Reportf(funcDecl.Pos(), "don't use %s function", internal.FormatCode(fnName, nil)) + pass.Reportf(funcDecl.Pos(), "don't use %s function", internal.FormatCode(fnName)) } }) diff --git a/pkg/golinters/gochecksumtype/gochecksumtype.go b/pkg/golinters/gochecksumtype/gochecksumtype.go index 78cbd574d20b..825975f14570 100644 --- a/pkg/golinters/gochecksumtype/gochecksumtype.go +++ b/pkg/golinters/gochecksumtype/gochecksumtype.go @@ -18,41 +18,37 @@ const linterName = "gochecksumtype" func New(settings *config.GoChecksumTypeSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue + + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: `Run exhaustiveness checks on Go "sum types"`, + Run: func(pass *analysis.Pass) (any, error) { + issues, err := runGoCheckSumType(pass, settings) + if err != nil { + return nil, err + } + + if len(issues) == 0 { + return nil, nil + } + + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues, err := runGoCheckSumType(pass, settings) - if err != nil { - return nil, err - } - - if len(issues) == 0 { return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - `Run exhaustiveness checks on Go "sum types"`, - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(_ *linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + }, + }). + WithIssuesReporter(func(_ *linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runGoCheckSumType(pass *analysis.Pass, settings *config.GoChecksumTypeSettings) ([]goanalysis.Issue, error) { - var resIssues []goanalysis.Issue +func runGoCheckSumType(pass *analysis.Pass, settings *config.GoChecksumTypeSettings) ([]*goanalysis.Issue, error) { + var resIssues []*goanalysis.Issue pkg := &packages.Package{ Fset: pass.Fset, diff --git a/pkg/golinters/gocognit/gocognit.go b/pkg/golinters/gocognit/gocognit.go index 689a70a12383..b17912c0a649 100644 --- a/pkg/golinters/gocognit/gocognit.go +++ b/pkg/golinters/gocognit/gocognit.go @@ -19,37 +19,33 @@ const linterName = "gocognit" func New(settings *config.GocognitSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue - analyzer := &analysis.Analyzer{ - Name: goanalysis.TheOnlyAnalyzerName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runGocognit(pass, settings) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Computes and checks the cognitive complexity of functions", + Run: func(pass *analysis.Pass) (any, error) { + issues := runGocognit(pass, settings) - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + if len(issues) == 0 { + return nil, nil + } - return nil, nil - }, - } + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return goanalysis.NewLinter( - linterName, - "Computes and checks the cognitive complexity of functions", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } -func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goanalysis.Issue { +func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []*goanalysis.Issue { var stats []gocognit.Stat for _, f := range pass.Files { stats = gocognit.ComplexityStats(f, pass.Fset, stats) @@ -62,7 +58,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana return stats[i].Complexity > stats[j].Complexity }) - issues := make([]goanalysis.Issue, 0, len(stats)) + issues := make([]*goanalysis.Issue, 0, len(stats)) for _, s := range stats { if s.Complexity <= settings.MinComplexity { break // Break as the stats is already sorted from greatest to least @@ -71,7 +67,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: s.Pos, Text: fmt.Sprintf("cognitive complexity %d of func %s is high (> %d)", - s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity), + s.Complexity, internal.FormatCode(s.FuncName), settings.MinComplexity), FromLinter: linterName, }, pass)) } diff --git a/pkg/golinters/goconst/goconst.go b/pkg/golinters/goconst/goconst.go index f3af64625243..b58d860c6eda 100644 --- a/pkg/golinters/goconst/goconst.go +++ b/pkg/golinters/goconst/goconst.go @@ -18,40 +18,36 @@ const linterName = "goconst" func New(settings *config.GoConstSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue - - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues, err := runGoconst(pass, settings) - if err != nil { - return nil, err - } + var resIssues []*goanalysis.Issue + + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Finds repeated strings that could be replaced by a constant", + Run: func(pass *analysis.Pass) (any, error) { + issues, err := runGoconst(pass, settings) + if err != nil { + return nil, err + } + + if len(issues) == 0 { + return nil, nil + } + + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - if len(issues) == 0 { return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Finds repeated strings that could be replaced by a constant", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanalysis.Issue, error) { +func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]*goanalysis.Issue, error) { cfg := goconstAPI.Config{ IgnoreStrings: settings.IgnoreStringValues, MatchWithConstants: settings.MatchWithConstants, @@ -81,7 +77,7 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal return nil, nil } - res := make([]goanalysis.Issue, 0, len(lintIssues)) + res := make([]*goanalysis.Issue, 0, len(lintIssues)) for i := range lintIssues { issue := &lintIssues[i] @@ -89,17 +85,17 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal switch { case issue.OccurrencesCount > 0: - text = fmt.Sprintf("string %s has %d occurrences", internal.FormatCode(issue.Str, nil), issue.OccurrencesCount) + text = fmt.Sprintf("string %s has %d occurrences", internal.FormatCode(issue.Str), issue.OccurrencesCount) if issue.MatchingConst == "" { text += ", make it a constant" } else { - text += fmt.Sprintf(", but such constant %s already exists", internal.FormatCode(issue.MatchingConst, nil)) + text += fmt.Sprintf(", but such constant %s already exists", internal.FormatCode(issue.MatchingConst)) } case issue.DuplicateConst != "": text = fmt.Sprintf("This constant is a duplicate of %s at %s", - internal.FormatCode(issue.DuplicateConst, nil), + internal.FormatCode(issue.DuplicateConst), issue.DuplicatePos.String()) default: diff --git a/pkg/golinters/gocritic/gocritic.go b/pkg/golinters/gocritic/gocritic.go index 486303dab0c6..cd7337590cfd 100644 --- a/pkg/golinters/gocritic/gocritic.go +++ b/pkg/golinters/gocritic/gocritic.go @@ -33,27 +33,21 @@ func New(settings *config.GoCriticSettings, replacer *strings.Replacer) *goanaly sizes: types.SizesFor("gc", runtime.GOARCH), } - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - err := wrapper.run(pass) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - `Provides diagnostics that check for bugs, performance and style issues. + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: `Provides diagnostics that check for bugs, performance and style issues. Extensible without recompilation through dynamic rules. Dynamic rules are written declaratively with AST patterns, filters, report message and optional suggestion.`, - []*analysis.Analyzer{analyzer}, - nil, - ). + Run: func(pass *analysis.Pass) (any, error) { + err := wrapper.run(pass) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). WithContextSetter(func(context *linter.Context) { wrapper.init(context.Log, settings, replacer) }). diff --git a/pkg/golinters/gocyclo/gocyclo.go b/pkg/golinters/gocyclo/gocyclo.go index 05691695d2aa..de0374607c06 100644 --- a/pkg/golinters/gocyclo/gocyclo.go +++ b/pkg/golinters/gocyclo/gocyclo.go @@ -18,37 +18,33 @@ const linterName = "gocyclo" func New(settings *config.GoCycloSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runGoCyclo(pass, settings) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Computes and checks the cyclomatic complexity of functions", + Run: func(pass *analysis.Pass) (any, error) { + issues := runGoCyclo(pass, settings) - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + if len(issues) == 0 { + return nil, nil + } - return nil, nil - }, - } + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return goanalysis.NewLinter( - linterName, - "Computes and checks the cyclomatic complexity of functions", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } -func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []goanalysis.Issue { +func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []*goanalysis.Issue { var stats gocyclo.Stats for _, f := range pass.Files { stats = gocyclo.AnalyzeASTFile(f, pass.Fset, stats) @@ -59,11 +55,11 @@ func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []goanaly stats = stats.SortAndFilter(-1, settings.MinComplexity) - issues := make([]goanalysis.Issue, 0, len(stats)) + issues := make([]*goanalysis.Issue, 0, len(stats)) for _, s := range stats { text := fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)", - s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity) + s.Complexity, internal.FormatCode(s.FuncName), settings.MinComplexity) issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: s.Pos, diff --git a/pkg/golinters/godot/godot.go b/pkg/golinters/godot/godot.go index 04e86211de33..e83495128e4c 100644 --- a/pkg/golinters/godot/godot.go +++ b/pkg/golinters/godot/godot.go @@ -10,8 +10,6 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "godot" - func New(settings *config.GodotSettings) *goanalysis.Linter { var dotSettings godot.Settings @@ -26,25 +24,20 @@ func New(settings *config.GodotSettings) *goanalysis.Linter { dotSettings.Scope = cmp.Or(dotSettings.Scope, godot.DeclScope) - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - err := runGodot(pass, dotSettings) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Check if comments end in a period", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "godot", + Doc: "Check if comments end in a period", + Run: func(pass *analysis.Pass) (any, error) { + err := runGodot(pass, dotSettings) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func runGodot(pass *analysis.Pass, settings godot.Settings) error { diff --git a/pkg/golinters/godot/testdata/fix/in/godot.go b/pkg/golinters/godot/testdata/fix/in/godot.go index 13b8da1c0ea9..d662c7ca53de 100644 --- a/pkg/golinters/godot/testdata/fix/in/godot.go +++ b/pkg/golinters/godot/testdata/fix/in/godot.go @@ -11,3 +11,10 @@ func godot(a, b int) int { // Nothing to do here return a + b } + +// Foo Lorem ipsum dolor sit amet, consectetur adipiscing elit. +// Aenean rhoncus odio enim, et pulvinar libero ultrices quis. +// Nulla at erat tellus. Maecenas id dapibus velit, ut porttitor ipsum +func Foo() { + // nothing to do here +} diff --git a/pkg/golinters/godot/testdata/fix/out/godot.go b/pkg/golinters/godot/testdata/fix/out/godot.go index 6960f06c044c..11d633e280c1 100644 --- a/pkg/golinters/godot/testdata/fix/out/godot.go +++ b/pkg/golinters/godot/testdata/fix/out/godot.go @@ -11,3 +11,10 @@ func godot(a, b int) int { // Nothing to do here return a + b } + +// Foo Lorem ipsum dolor sit amet, consectetur adipiscing elit. +// Aenean rhoncus odio enim, et pulvinar libero ultrices quis. +// Nulla at erat tellus. Maecenas id dapibus velit, ut porttitor ipsum. +func Foo() { + // nothing to do here +} diff --git a/pkg/golinters/godot/testdata/godot.go b/pkg/golinters/godot/testdata/godot.go index 93a904894691..c81134687b2a 100644 --- a/pkg/golinters/godot/testdata/godot.go +++ b/pkg/golinters/godot/testdata/godot.go @@ -7,3 +7,12 @@ package testdata func Godot() { // nothing to do here } + +// want +4 "Comment should end in a period" + +// Foo Lorem ipsum dolor sit amet, consectetur adipiscing elit. +// Aenean rhoncus odio enim, et pulvinar libero ultrices quis. +// Nulla at erat tellus. Maecenas id dapibus velit, ut porttitor ipsum +func Foo() { + // nothing to do here +} diff --git a/pkg/golinters/godox/godox.go b/pkg/golinters/godox/godox.go index e734c691b3da..8ab144e754a1 100644 --- a/pkg/golinters/godox/godox.go +++ b/pkg/golinters/godox/godox.go @@ -11,23 +11,16 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "godox" - func New(settings *config.GodoxSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - return run(pass, settings), nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Detects usage of FIXME, TODO and other keywords inside comments", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "godox", + Doc: "Detects usage of FIXME, TODO and other keywords inside comments", + Run: func(pass *analysis.Pass) (any, error) { + return run(pass, settings), nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func run(pass *analysis.Pass, settings *config.GodoxSettings) error { diff --git a/pkg/golinters/gofmt/gofmt.go b/pkg/golinters/gofmt/gofmt.go index 63b690018ecd..04de51efc0f1 100644 --- a/pkg/golinters/gofmt/gofmt.go +++ b/pkg/golinters/gofmt/gofmt.go @@ -1,8 +1,6 @@ package gofmt import ( - "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/goformatters" @@ -10,19 +8,14 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) -const linterName = "gofmt" - func New(settings *config.GoFmtSettings) *goanalysis.Linter { - a := goformatters.NewAnalyzer( - internal.LinterLogger.Child(linterName), - "Checks if the code is formatted according to 'gofmt' command.", - gofmtbase.New(settings), - ) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer( + goformatters.NewAnalyzer( + internal.LinterLogger.Child(gofmtbase.Name), + "Check if the code is formatted according to 'gofmt' command.", + gofmtbase.New(settings), + ), + ). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gofumpt/gofumpt.go b/pkg/golinters/gofumpt/gofumpt.go index d799be7a39fd..1ee7c833a321 100644 --- a/pkg/golinters/gofumpt/gofumpt.go +++ b/pkg/golinters/gofumpt/gofumpt.go @@ -1,8 +1,6 @@ package gofumpt import ( - "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/goformatters" @@ -10,19 +8,14 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) -const linterName = "gofumpt" - func New(settings *config.GoFumptSettings) *goanalysis.Linter { - a := goformatters.NewAnalyzer( - internal.LinterLogger.Child(linterName), - "Checks if code and import statements are formatted, with additional rules.", - gofumptbase.New(settings, settings.LangVersion), - ) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer( + goformatters.NewAnalyzer( + internal.LinterLogger.Child(gofumptbase.Name), + "Check if code and import statements are formatted, with additional rules.", + gofumptbase.New(settings, settings.LangVersion), + ), + ). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/goheader/goheader.go b/pkg/golinters/goheader/goheader.go index e03d3277d2c7..0634dbd4288f 100644 --- a/pkg/golinters/goheader/goheader.go +++ b/pkg/golinters/goheader/goheader.go @@ -23,25 +23,20 @@ func New(settings *config.GoHeaderSettings, replacer *strings.Replacer) *goanaly } } - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - err := runGoHeader(pass, conf) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Checks if file header matches to pattern", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Check if file header matches to pattern", + Run: func(pass *analysis.Pass) (any, error) { + err := runGoHeader(pass, conf) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func runGoHeader(pass *analysis.Pass, conf *goheader.Configuration) error { diff --git a/pkg/golinters/goimports/goimports.go b/pkg/golinters/goimports/goimports.go index 3aa8cde56a94..b3b9b5800b8d 100644 --- a/pkg/golinters/goimports/goimports.go +++ b/pkg/golinters/goimports/goimports.go @@ -1,8 +1,6 @@ package goimports import ( - "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/goformatters" @@ -10,19 +8,14 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) -const linterName = "goimports" - func New(settings *config.GoImportsSettings) *goanalysis.Linter { - a := goformatters.NewAnalyzer( - internal.LinterLogger.Child(linterName), - "Checks if the code and import statements are formatted according to the 'goimports' command.", - goimportsbase.New(settings), - ) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer( + goformatters.NewAnalyzer( + internal.LinterLogger.Child(goimportsbase.Name), + "Checks if the code and import statements are formatted according to the 'goimports' command.", + goimportsbase.New(settings), + ), + ). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/golines/golines.go b/pkg/golinters/golines/golines.go index 0b3acc53bb40..0a32971dee1d 100644 --- a/pkg/golinters/golines/golines.go +++ b/pkg/golinters/golines/golines.go @@ -1,8 +1,6 @@ package golines import ( - "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/goformatters" @@ -10,19 +8,14 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) -const linterName = "golines" - func New(settings *config.GoLinesSettings) *goanalysis.Linter { - a := goformatters.NewAnalyzer( - internal.LinterLogger.Child(linterName), - "Checks if code is formatted, and fixes long lines", - golinesbase.New(settings), - ) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer( + goformatters.NewAnalyzer( + internal.LinterLogger.Child(golinesbase.Name), + "Checks if code is formatted, and fixes long lines", + golinesbase.New(settings), + ), + ). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gomoddirectives/gomoddirectives.go b/pkg/golinters/gomoddirectives/gomoddirectives.go index 86f94e2560ea..dd6656fb6cb6 100644 --- a/pkg/golinters/gomoddirectives/gomoddirectives.go +++ b/pkg/golinters/gomoddirectives/gomoddirectives.go @@ -17,7 +17,7 @@ import ( const linterName = "gomoddirectives" func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter { - var issues []goanalysis.Issue + var issues []*goanalysis.Issue var once sync.Once var opts gomoddirectives.Options @@ -50,38 +50,37 @@ func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter { } analyzer := &analysis.Analyzer{ - Name: goanalysis.TheOnlyAnalyzerName, - Doc: goanalysis.TheOnlyanalyzerDoc, + Name: linterName, + Doc: "Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.", Run: goanalysis.DummyRun, } - return goanalysis.NewLinter( - linterName, - "Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.", - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - analyzer.Run = func(pass *analysis.Pass) (any, error) { - once.Do(func() { - results, err := gomoddirectives.AnalyzePass(pass, opts) - if err != nil { - lintCtx.Log.Warnf("running %s failed: %s: "+ - "if you are not using go modules it is suggested to disable this linter", linterName, err) - return - } + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + analyzer.Run = func(pass *analysis.Pass) (any, error) { + once.Do(func() { + results, err := gomoddirectives.AnalyzePass(pass, opts) + if err != nil { + lintCtx.Log.Warnf("running %s failed: %s: "+ + "if you are not using go modules it is suggested to disable this linter", linterName, err) + return + } - for _, p := range results { - issues = append(issues, goanalysis.NewIssue(&result.Issue{ - FromLinter: linterName, - Pos: p.Start, - Text: p.Reason, - }, pass)) - } - }) + for _, p := range results { + issues = append(issues, goanalysis.NewIssue(&result.Issue{ + FromLinter: linterName, + Pos: p.Start, + Text: p.Reason, + }, pass)) + } + }) - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return issues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + } + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return issues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gomodguard/gomodguard.go b/pkg/golinters/gomodguard/gomodguard.go index e38a6c9b90e4..7d16f57b3a5c 100644 --- a/pkg/golinters/gomodguard/gomodguard.go +++ b/pkg/golinters/gomodguard/gomodguard.go @@ -13,15 +13,10 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -const ( - name = "gomodguard" - desc = "Allow and block list linter for direct Go module dependencies. " + - "This is different from depguard where there are different block " + - "types for example version constraints and module recommendations." -) +const linterName = "gomodguard" func New(settings *config.GoModGuardSettings) *goanalysis.Linter { - var issues []goanalysis.Issue + var issues []*goanalysis.Issue var mu sync.Mutex processorCfg := &gomodguard.Configuration{} @@ -54,41 +49,41 @@ func New(settings *config.GoModGuardSettings) *goanalysis.Linter { } analyzer := &analysis.Analyzer{ - Name: goanalysis.TheOnlyAnalyzerName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: goanalysis.DummyRun, + Name: linterName, + Doc: "Allow and blocklist linter for direct Go module dependencies. " + + "This is different from depguard where there are different block " + + "types for example version constraints and module recommendations.", + Run: goanalysis.DummyRun, } - return goanalysis.NewLinter( - name, - desc, - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - processor, err := gomodguard.NewProcessor(processorCfg) - if err != nil { - lintCtx.Log.Warnf("running gomodguard failed: %s: if you are not using go modules "+ - "it is suggested to disable this linter", err) - return - } + return goanalysis.NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + processor, err := gomodguard.NewProcessor(processorCfg) + if err != nil { + lintCtx.Log.Warnf("running gomodguard failed: %s: if you are not using go modules "+ + "it is suggested to disable this linter", err) + return + } - analyzer.Run = func(pass *analysis.Pass) (any, error) { - gomodguardIssues := processor.ProcessFiles(internal.GetGoFileNames(pass)) + analyzer.Run = func(pass *analysis.Pass) (any, error) { + gomodguardIssues := processor.ProcessFiles(internal.GetGoFileNames(pass)) - mu.Lock() - defer mu.Unlock() + mu.Lock() + defer mu.Unlock() - for _, gomodguardIssue := range gomodguardIssues { - issues = append(issues, goanalysis.NewIssue(&result.Issue{ - FromLinter: name, - Pos: gomodguardIssue.Position, - Text: gomodguardIssue.Reason, - }, pass)) - } + for _, gomodguardIssue := range gomodguardIssues { + issues = append(issues, goanalysis.NewIssue(&result.Issue{ + FromLinter: linterName, + Pos: gomodguardIssue.Position, + Text: gomodguardIssue.Reason, + }, pass)) + } - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return issues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + } + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return issues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gomodguard/testdata/go.mod b/pkg/golinters/gomodguard/testdata/go.mod index ab174ed19807..c5512cba7f95 100644 --- a/pkg/golinters/gomodguard/testdata/go.mod +++ b/pkg/golinters/gomodguard/testdata/go.mod @@ -1,8 +1,8 @@ module gomodguard -go 1.22.0 +go 1.23.0 require ( - golang.org/x/mod v0.22.0 + golang.org/x/mod v0.24.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/pkg/golinters/gomodguard/testdata/go.sum b/pkg/golinters/gomodguard/testdata/go.sum index 7c483c93b9e0..5dce74976ef5 100644 --- a/pkg/golinters/gomodguard/testdata/go.sum +++ b/pkg/golinters/gomodguard/testdata/go.sum @@ -1,5 +1,7 @@ golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= +golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/golinters/goprintffuncname/goprintffuncname.go b/pkg/golinters/goprintffuncname/goprintffuncname.go index b1436347806c..a56dce8e05df 100644 --- a/pkg/golinters/goprintffuncname/goprintffuncname.go +++ b/pkg/golinters/goprintffuncname/goprintffuncname.go @@ -2,18 +2,12 @@ package goprintffuncname import ( "github.com/golangci/go-printf-func-name/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := analyzer.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(analyzer.Analyzer). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/gosec/gosec.go b/pkg/golinters/gosec/gosec.go index 95b445e87038..66d229295a3f 100644 --- a/pkg/golinters/gosec/gosec.go +++ b/pkg/golinters/gosec/gosec.go @@ -26,7 +26,7 @@ const linterName = "gosec" func New(settings *config.GoSecSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue conf := gosec.NewConfig() @@ -50,37 +50,36 @@ func New(settings *config.GoSecSettings) *goanalysis.Linter { analyzer := &analysis.Analyzer{ Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, + Doc: "Inspects source code for security problems", Run: goanalysis.DummyRun, } - return goanalysis.NewLinter( - linterName, - "Inspects source code for security problems", - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - analyzer.Run = func(pass *analysis.Pass) (any, error) { - // The `gosecAnalyzer` is here because of concurrency issue. - gosecAnalyzer := gosec.NewAnalyzer(conf, true, false, false, settings.Concurrency, logger) + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + analyzer.Run = func(pass *analysis.Pass) (any, error) { + // The `gosecAnalyzer` is here because of concurrency issue. + gosecAnalyzer := gosec.NewAnalyzer(conf, true, false, false, settings.Concurrency, logger) - gosecAnalyzer.LoadRules(ruleDefinitions.RulesInfo()) - gosecAnalyzer.LoadAnalyzers(analyzerDefinitions.AnalyzersInfo()) + gosecAnalyzer.LoadRules(ruleDefinitions.RulesInfo()) + gosecAnalyzer.LoadAnalyzers(analyzerDefinitions.AnalyzersInfo()) - issues := runGoSec(lintCtx, pass, settings, gosecAnalyzer) + issues := runGoSec(lintCtx, pass, settings, gosecAnalyzer) - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + return nil, nil + } + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoSecSettings, analyzer *gosec.Analyzer) []goanalysis.Issue { +func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoSecSettings, analyzer *gosec.Analyzer) []*goanalysis.Issue { pkg := &packages.Package{ Fset: pass.Fset, Syntax: pass.Files, @@ -108,7 +107,7 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS secIssues = filterIssues(secIssues, severity, confidence) - issues := make([]goanalysis.Issue, 0, len(secIssues)) + issues := make([]*goanalysis.Issue, 0, len(secIssues)) for _, i := range secIssues { text := fmt.Sprintf("%s: %s", i.RuleID, i.What) diff --git a/pkg/golinters/gosmopolitan/gosmopolitan.go b/pkg/golinters/gosmopolitan/gosmopolitan.go index 6c574403f694..76261abe1450 100644 --- a/pkg/golinters/gosmopolitan/gosmopolitan.go +++ b/pkg/golinters/gosmopolitan/gosmopolitan.go @@ -4,18 +4,16 @@ import ( "strings" "github.com/xen0n/gosmopolitan" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.GosmopolitanSettings) *goanalysis.Linter { - a := gosmopolitan.NewAnalyzer() + var cfg map[string]any - cfg := map[string]map[string]any{} if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "allowtimelocal": settings.AllowTimeLocal, "escapehatches": strings.Join(settings.EscapeHatches, ","), "watchforscripts": strings.Join(settings.WatchForScripts, ","), @@ -25,10 +23,8 @@ func New(settings *config.GosmopolitanSettings) *goanalysis.Linter { } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(gosmopolitan.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/govet/govet.go b/pkg/golinters/govet/govet.go index 4f3380841382..e4de5b0f4459 100644 --- a/pkg/golinters/govet/govet.go +++ b/pkg/golinters/govet/govet.go @@ -24,6 +24,7 @@ import ( "golang.org/x/tools/go/analysis/passes/fieldalignment" "golang.org/x/tools/go/analysis/passes/findcall" "golang.org/x/tools/go/analysis/passes/framepointer" + "golang.org/x/tools/go/analysis/passes/hostport" "golang.org/x/tools/go/analysis/passes/httpmux" "golang.org/x/tools/go/analysis/passes/httpresponse" "golang.org/x/tools/go/analysis/passes/ifaceassert" @@ -78,6 +79,7 @@ var ( fieldalignment.Analyzer, findcall.Analyzer, framepointer.Analyzer, + hostport.Analyzer, httpmux.Analyzer, httpresponse.Analyzer, ifaceassert.Analyzer, diff --git a/pkg/golinters/govet/govet_test.go b/pkg/golinters/govet/govet_test.go index ec7072795f74..794ef6ece9db 100644 --- a/pkg/golinters/govet/govet_test.go +++ b/pkg/golinters/govet/govet_test.go @@ -18,7 +18,7 @@ import ( func TestGovet(t *testing.T) { // Checking that every default analyzer is in "all analyzers" list. - checkList := append([]*analysis.Analyzer{}, defaultAnalyzers...) + checkList := slices.Clone(defaultAnalyzers) checkList = append(checkList, shadow.Analyzer) // special case, used in analyzersFromConfig for _, defaultAnalyzer := range checkList { diff --git a/pkg/golinters/grouper/grouper.go b/pkg/golinters/grouper/grouper.go index 853e2d3e7f70..ed3601617d9a 100644 --- a/pkg/golinters/grouper/grouper.go +++ b/pkg/golinters/grouper/grouper.go @@ -2,18 +2,16 @@ package grouper import ( grouper "github.com/leonklingele/grouper/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.GrouperSettings) *goanalysis.Linter { - a := grouper.New() + var cfg map[string]any - cfg := map[string]map[string]any{} if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "const-require-single-const": settings.ConstRequireSingleConst, "const-require-grouping": settings.ConstRequireGrouping, "import-require-single-import": settings.ImportRequireSingleImport, @@ -24,11 +22,9 @@ func New(settings *config.GrouperSettings) *goanalysis.Linter { "var-require-grouping": settings.VarRequireGrouping, } } - - return goanalysis.NewLinter( - a.Name, - "Analyze expression groups.", - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(grouper.New()). + WithDesc("Analyze expression groups."). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/iface/iface.go b/pkg/golinters/iface/iface.go index a3c2816d4385..0a4a38abc931 100644 --- a/pkg/golinters/iface/iface.go +++ b/pkg/golinters/iface/iface.go @@ -5,6 +5,7 @@ import ( "github.com/uudashr/iface/identical" "github.com/uudashr/iface/opaque" + "github.com/uudashr/iface/unexported" "github.com/uudashr/iface/unused" "golang.org/x/tools/go/analysis" @@ -28,9 +29,10 @@ func New(settings *config.IfaceSettings) *goanalysis.Linter { func analyzersFromSettings(settings *config.IfaceSettings) []*analysis.Analyzer { allAnalyzers := map[string]*analysis.Analyzer{ - "identical": identical.Analyzer, - "unused": unused.Analyzer, - "opaque": opaque.Analyzer, + "identical": identical.Analyzer, + "unused": unused.Analyzer, + "opaque": opaque.Analyzer, + "unexported": unexported.Analyzer, } if settings == nil || len(settings.Enable) == 0 { diff --git a/pkg/golinters/iface/testdata/iface_all.go b/pkg/golinters/iface/testdata/iface_all.go index 3a6f912a1d2a..3dd95cdc24bf 100644 --- a/pkg/golinters/iface/testdata/iface_all.go +++ b/pkg/golinters/iface/testdata/iface_all.go @@ -6,11 +6,11 @@ import "fmt" // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } @@ -28,7 +28,7 @@ func (s server) Serve() error { return nil } -func NewServer(addr string) Server { // want "opaque: NewServer function return Server interface at the 1st result, abstract a single concrete implementation of \\*server" +func NewServer(addr string) Server { // want "opaque: 'NewServer' function return 'Server' interface at the 1st result, abstract a single concrete implementation of '\\*server'" return &server{addr: addr} } @@ -39,7 +39,7 @@ type User struct { Name string } -type UserRepository interface { // want "unused: interface UserRepository is declared but not used within the package" +type UserRepository interface { // want "unused: interface 'UserRepository' is declared but not used within the package" UserOf(id string) (*User, error) } diff --git a/pkg/golinters/iface/testdata/iface_cgo.go b/pkg/golinters/iface/testdata/iface_cgo.go index 43ef0216a036..16a9944854f0 100644 --- a/pkg/golinters/iface/testdata/iface_cgo.go +++ b/pkg/golinters/iface/testdata/iface_cgo.go @@ -24,11 +24,11 @@ func _() { // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } diff --git a/pkg/golinters/iface/testdata/iface_default.go b/pkg/golinters/iface/testdata/iface_default.go index 34117389738b..d0344b36c58f 100644 --- a/pkg/golinters/iface/testdata/iface_default.go +++ b/pkg/golinters/iface/testdata/iface_default.go @@ -5,11 +5,11 @@ import "fmt" // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } diff --git a/pkg/golinters/iface/testdata/iface_identical.go b/pkg/golinters/iface/testdata/iface_identical.go index 821aff7bd41e..c8a2de4818bb 100644 --- a/pkg/golinters/iface/testdata/iface_identical.go +++ b/pkg/golinters/iface/testdata/iface_identical.go @@ -6,11 +6,11 @@ import "fmt" // identical -type Pinger interface { // want "identical: interface Pinger contains identical methods or type constraints from another interface, causing redundancy" +type Pinger interface { // want "identical: interface 'Pinger' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } -type Healthcheck interface { // want "identical: interface Healthcheck contains identical methods or type constraints from another interface, causing redundancy" +type Healthcheck interface { // want "identical: interface 'Healthcheck' contains identical methods or type constraints with another interface, causing redundancy" Ping() error } diff --git a/pkg/golinters/iface/testdata/iface_opaque.go b/pkg/golinters/iface/testdata/iface_opaque.go index b7ebeddc600f..8610a3fa05c1 100644 --- a/pkg/golinters/iface/testdata/iface_opaque.go +++ b/pkg/golinters/iface/testdata/iface_opaque.go @@ -28,7 +28,7 @@ func (s server) Serve() error { return nil } -func NewServer(addr string) Server { // want "opaque: NewServer function return Server interface at the 1st result, abstract a single concrete implementation of \\*server" +func NewServer(addr string) Server { // want "opaque: 'NewServer' function return 'Server' interface at the 1st result, abstract a single concrete implementation of '\\*server'" return &server{addr: addr} } diff --git a/pkg/golinters/iface/testdata/iface_unexported.go b/pkg/golinters/iface/testdata/iface_unexported.go new file mode 100644 index 000000000000..01a4f210f9f7 --- /dev/null +++ b/pkg/golinters/iface/testdata/iface_unexported.go @@ -0,0 +1,84 @@ +//golangcitest:args -Eiface +//golangcitest:config_path testdata/iface_unexported.yml +package testdata + +import "fmt" + +// identical + +type Pinger interface { + Ping() error +} + +type Healthcheck interface { + Ping() error +} + +// opaque + +type Server interface { + Serve() error +} + +type server struct { + addr string +} + +func (s server) Serve() error { + return nil +} + +func NewServer(addr string) Server { + return &server{addr: addr} +} + +// unused + +type User struct { + ID string + Name string +} + +type UserRepository interface { + UserOf(id string) (*User, error) +} + +type UserRepositorySQL struct { +} + +func (r *UserRepositorySQL) UserOf(id string) (*User, error) { + return nil, nil +} + +type Granter interface { + Grant(permission string) error +} + +func AllowAll(g Granter) error { + return g.Grant("all") +} + +type Allower interface { + Allow(permission string) error +} + +func Allow(x any) { + _ = x.(Allower) + fmt.Println("allow") +} + +// unexported + +type unexportedReader interface { + Read([]byte) (int, error) +} + +func ReadAll(r unexportedReader) ([]byte, error) { // want "unexported interface 'unexportedReader' used as parameter in exported function 'ReadAll'" + buf := make([]byte, 1024) + _, err := r.Read(buf) + return buf, err +} + +func NewUnexportedReader() unexportedReader { // want "unexported interface 'unexportedReader' used as return value in exported function 'NewUnexportedReader'" + return nil // stub +} diff --git a/pkg/golinters/iface/testdata/iface_unexported.yml b/pkg/golinters/iface/testdata/iface_unexported.yml new file mode 100644 index 000000000000..cc0a84c0aa1e --- /dev/null +++ b/pkg/golinters/iface/testdata/iface_unexported.yml @@ -0,0 +1,7 @@ +version: "2" + +linters: + settings: + iface: + enable: + - unexported diff --git a/pkg/golinters/iface/testdata/iface_unused.go b/pkg/golinters/iface/testdata/iface_unused.go index b75fdc8964c6..58e5ffdbaf25 100644 --- a/pkg/golinters/iface/testdata/iface_unused.go +++ b/pkg/golinters/iface/testdata/iface_unused.go @@ -6,11 +6,11 @@ import "fmt" // identical -type Pinger interface { // want "unused: interface Pinger is declared but not used within the package" +type Pinger interface { // want "unused: interface 'Pinger' is declared but not used within the package" Ping() error } -type Healthcheck interface { // want "unused: interface Healthcheck is declared but not used within the package" +type Healthcheck interface { // want "unused: interface 'Healthcheck' is declared but not used within the package" Ping() error } @@ -39,7 +39,7 @@ type User struct { Name string } -type UserRepository interface { // want "unused: interface UserRepository is declared but not used within the package" +type UserRepository interface { // want "unused: interface 'UserRepository' is declared but not used within the package" UserOf(id string) (*User, error) } diff --git a/pkg/golinters/importas/importas.go b/pkg/golinters/importas/importas.go index a86db68ce04e..fa7a54300e29 100644 --- a/pkg/golinters/importas/importas.go +++ b/pkg/golinters/importas/importas.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/julz/importas" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -16,55 +15,53 @@ import ( func New(settings *config.ImportAsSettings) *goanalysis.Linter { analyzer := importas.Analyzer - return goanalysis.NewLinter( - analyzer.Name, - analyzer.Doc, - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - if settings == nil { - return - } - if len(settings.Alias) == 0 { - lintCtx.Log.Infof("importas settings found, but no aliases listed. List aliases under alias: key.") - } - - if err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)); err != nil { - lintCtx.Log.Errorf("failed to parse configuration: %v", err) - } - - if err := analyzer.Flags.Set("no-extra-aliases", strconv.FormatBool(settings.NoExtraAliases)); err != nil { - lintCtx.Log.Errorf("failed to parse configuration: %v", err) - } - - uniqPackages := make(map[string]config.ImportAsAlias) - uniqAliases := make(map[string]config.ImportAsAlias) - for _, a := range settings.Alias { - if a.Pkg == "" { - lintCtx.Log.Errorf("invalid configuration, empty package: pkg=%s alias=%s", a.Pkg, a.Alias) - continue + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + if settings == nil { + return } - - if v, ok := uniqPackages[a.Pkg]; ok { - lintCtx.Log.Errorf("invalid configuration, multiple aliases for the same package: pkg=%s aliases=[%s,%s]", a.Pkg, a.Alias, v.Alias) - } else { - uniqPackages[a.Pkg] = a + if len(settings.Alias) == 0 { + lintCtx.Log.Infof("importas settings found, but no aliases listed. List aliases under alias: key.") } - // Skips the duplication check when: - // - the alias is empty. - // - the alias is a regular expression replacement pattern (ie. contains `$`). - v, ok := uniqAliases[a.Alias] - if ok && a.Alias != "" && !strings.Contains(a.Alias, "$") { - lintCtx.Log.Errorf("invalid configuration, multiple packages with the same alias: alias=%s packages=[%s,%s]", a.Alias, a.Pkg, v.Pkg) - } else { - uniqAliases[a.Alias] = a + if err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)); err != nil { + lintCtx.Log.Errorf("failed to parse configuration: %v", err) } - err := analyzer.Flags.Set("alias", fmt.Sprintf("%s:%s", a.Pkg, a.Alias)) - if err != nil { + if err := analyzer.Flags.Set("no-extra-aliases", strconv.FormatBool(settings.NoExtraAliases)); err != nil { lintCtx.Log.Errorf("failed to parse configuration: %v", err) } - } - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + + uniqPackages := make(map[string]config.ImportAsAlias) + uniqAliases := make(map[string]config.ImportAsAlias) + for _, a := range settings.Alias { + if a.Pkg == "" { + lintCtx.Log.Errorf("invalid configuration, empty package: pkg=%s alias=%s", a.Pkg, a.Alias) + continue + } + + if v, ok := uniqPackages[a.Pkg]; ok { + lintCtx.Log.Errorf("invalid configuration, multiple aliases for the same package: pkg=%s aliases=[%s,%s]", a.Pkg, a.Alias, v.Alias) + } else { + uniqPackages[a.Pkg] = a + } + + // Skips the duplication check when: + // - the alias is empty. + // - the alias is a regular expression replacement pattern (ie. contains `$`). + v, ok := uniqAliases[a.Alias] + if ok && a.Alias != "" && !strings.Contains(a.Alias, "$") { + lintCtx.Log.Errorf("invalid configuration, multiple packages with the same alias: alias=%s packages=[%s,%s]", a.Alias, a.Pkg, v.Pkg) + } else { + uniqAliases[a.Alias] = a + } + + err := analyzer.Flags.Set("alias", fmt.Sprintf("%s:%s", a.Pkg, a.Alias)) + if err != nil { + lintCtx.Log.Errorf("failed to parse configuration: %v", err) + } + } + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/inamedparam/inamedparam.go b/pkg/golinters/inamedparam/inamedparam.go index 0a67c970deca..ecb6f7e5024f 100644 --- a/pkg/golinters/inamedparam/inamedparam.go +++ b/pkg/golinters/inamedparam/inamedparam.go @@ -2,29 +2,22 @@ package inamedparam import ( "github.com/macabu/inamedparam" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.INamedParamSettings) *goanalysis.Linter { - a := inamedparam.Analyzer - - var cfg map[string]map[string]any + var cfg map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - "skip-single-param": settings.SkipSingleParam, - }, + cfg = map[string]any{ + "skip-single-param": settings.SkipSingleParam, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(inamedparam.Analyzer). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/ineffassign/ineffassign.go b/pkg/golinters/ineffassign/ineffassign.go index bbe01ba1f37a..2c0119f1032f 100644 --- a/pkg/golinters/ineffassign/ineffassign.go +++ b/pkg/golinters/ineffassign/ineffassign.go @@ -2,18 +2,13 @@ package ineffassign import ( "github.com/gordonklaus/ineffassign/pkg/ineffassign" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := ineffassign.Analyzer - - return goanalysis.NewLinter( - a.Name, - "Detects when assignments to existing variables are not used", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(ineffassign.Analyzer). + WithDesc("Detects when assignments to existing variables are not used"). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/interfacebloat/interfacebloat.go b/pkg/golinters/interfacebloat/interfacebloat.go index fbafb3ac7343..f2e187423278 100644 --- a/pkg/golinters/interfacebloat/interfacebloat.go +++ b/pkg/golinters/interfacebloat/interfacebloat.go @@ -2,28 +2,22 @@ package interfacebloat import ( "github.com/sashamelentyev/interfacebloat/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.InterfaceBloatSettings) *goanalysis.Linter { - a := analyzer.New() + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - analyzer.InterfaceMaxMethodsFlag: settings.Max, - }, + cfg = map[string]any{ + analyzer.InterfaceMaxMethodsFlag: settings.Max, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(analyzer.New()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/internal/util.go b/pkg/golinters/internal/util.go index 2e5fb29f91c9..86137cf66081 100644 --- a/pkg/golinters/internal/util.go +++ b/pkg/golinters/internal/util.go @@ -6,11 +6,10 @@ import ( "golang.org/x/tools/go/analysis" - "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -func FormatCode(code string, _ *config.Config) string { +func FormatCode(code string) string { if strings.Contains(code, "`") { return code // TODO: properly escape or remove } diff --git a/pkg/golinters/intrange/intrange.go b/pkg/golinters/intrange/intrange.go index c75be9b63446..1ff02964cbe5 100644 --- a/pkg/golinters/intrange/intrange.go +++ b/pkg/golinters/intrange/intrange.go @@ -2,18 +2,12 @@ package intrange import ( "github.com/ckaznocha/intrange" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := intrange.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(intrange.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/ireturn/ireturn.go b/pkg/golinters/ireturn/ireturn.go index 44c28700b370..b9cce0001842 100644 --- a/pkg/golinters/ireturn/ireturn.go +++ b/pkg/golinters/ireturn/ireturn.go @@ -4,28 +4,24 @@ import ( "strings" "github.com/butuzov/ireturn/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.IreturnSettings) *goanalysis.Linter { - a := analyzer.NewAnalyzer() + var cfg map[string]any - cfg := map[string]map[string]any{} if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "allow": strings.Join(settings.Allow, ","), "reject": strings.Join(settings.Reject, ","), "nonolint": true, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/lll/lll.go b/pkg/golinters/lll/lll.go index eb435baa754c..c8e6717dea82 100644 --- a/pkg/golinters/lll/lll.go +++ b/pkg/golinters/lll/lll.go @@ -15,30 +15,23 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "lll" - const goCommentDirectivePrefix = "//go:" func New(settings *config.LllSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - err := runLll(pass, settings) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Reports long lines", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "lll", + Doc: "Reports long lines", + Run: func(pass *analysis.Pass) (any, error) { + err := runLll(pass, settings) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func runLll(pass *analysis.Pass, settings *config.LllSettings) error { diff --git a/pkg/golinters/loggercheck/loggercheck.go b/pkg/golinters/loggercheck/loggercheck.go index a5dd4da48cd6..b9a6efa75fad 100644 --- a/pkg/golinters/loggercheck/loggercheck.go +++ b/pkg/golinters/loggercheck/loggercheck.go @@ -2,7 +2,6 @@ package loggercheck import ( "github.com/timonwong/loggercheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -37,11 +36,7 @@ func New(settings *config.LoggerCheckSettings) *goanalysis.Linter { } } - analyzer := loggercheck.NewAnalyzer(opts...) - return goanalysis.NewLinter( - analyzer.Name, - analyzer.Doc, - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(loggercheck.NewAnalyzer(opts...)). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/loggercheck/testdata/go.mod b/pkg/golinters/loggercheck/testdata/go.mod index 985fff765d4b..0df788c08b62 100644 --- a/pkg/golinters/loggercheck/testdata/go.mod +++ b/pkg/golinters/loggercheck/testdata/go.mod @@ -4,7 +4,7 @@ go 1.21.0 require ( github.com/go-kit/log v0.2.1 - github.com/go-logr/logr v1.4.2 + github.com/go-logr/logr v1.4.3 go.uber.org/zap v1.27.0 k8s.io/klog/v2 v2.130.1 ) diff --git a/pkg/golinters/loggercheck/testdata/go.sum b/pkg/golinters/loggercheck/testdata/go.sum index 5a316ccca990..dd912496e496 100644 --- a/pkg/golinters/loggercheck/testdata/go.sum +++ b/pkg/golinters/loggercheck/testdata/go.sum @@ -4,8 +4,8 @@ github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= diff --git a/pkg/golinters/maintidx/maintidx.go b/pkg/golinters/maintidx/maintidx.go index 4e541f888dfa..f2076c8ab030 100644 --- a/pkg/golinters/maintidx/maintidx.go +++ b/pkg/golinters/maintidx/maintidx.go @@ -2,29 +2,22 @@ package maintidx import ( "github.com/yagipy/maintidx" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.MaintIdxSettings) *goanalysis.Linter { - analyzer := maintidx.Analyzer - - cfg := map[string]map[string]any{ - analyzer.Name: {"under": 20}, + cfg := map[string]any{ + "under": 20, } if settings != nil { - cfg[analyzer.Name] = map[string]any{ - "under": settings.Under, - } + cfg["under"] = settings.Under } - return goanalysis.NewLinter( - analyzer.Name, - analyzer.Doc, - []*analysis.Analyzer{analyzer}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(maintidx.Analyzer). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/makezero/makezero.go b/pkg/golinters/makezero/makezero.go index 04b4fe93dadf..5ee298d99f4e 100644 --- a/pkg/golinters/makezero/makezero.go +++ b/pkg/golinters/makezero/makezero.go @@ -3,35 +3,28 @@ package makezero import ( "fmt" - "github.com/ashanbrown/makezero/makezero" + "github.com/ashanbrown/makezero/v2/makezero" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "makezero" - func New(settings *config.MakezeroSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - err := runMakeZero(pass, settings) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Finds slice declarations with non-zero initial length", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "makezero", + Doc: "Find slice declarations with non-zero initial length", + Run: func(pass *analysis.Pass) (any, error) { + err := runMakeZero(pass, settings) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } func runMakeZero(pass *analysis.Pass, settings *config.MakezeroSettings) error { diff --git a/pkg/golinters/mirror/mirror.go b/pkg/golinters/mirror/mirror.go index 9badb0c1ed68..07cfe25e4e44 100644 --- a/pkg/golinters/mirror/mirror.go +++ b/pkg/golinters/mirror/mirror.go @@ -2,29 +2,22 @@ package mirror import ( "github.com/butuzov/mirror" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := mirror.NewAnalyzer() - // mirror only lints test files if the `--with-tests` flag is passed, // so we pass the `with-tests` flag as true to the analyzer before running it. // This can be turned off by using the regular golangci-lint flags such as `--tests` or `--skip-files` // or can be disabled per linter via exclude rules. // (see https://github.com/golangci/golangci-lint/issues/2527#issuecomment-1023707262) - linterCfg := map[string]map[string]any{ - a.Name: { - "with-tests": true, - }, + cfg := map[string]any{ + "with-tests": true, } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - linterCfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(mirror.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/misspell/misspell.go b/pkg/golinters/misspell/misspell.go index 9a170c9537b7..cbf378505b47 100644 --- a/pkg/golinters/misspell/misspell.go +++ b/pkg/golinters/misspell/misspell.go @@ -23,27 +23,22 @@ func New(settings *config.MisspellSettings) *goanalysis.Linter { internal.LinterLogger.Fatalf("%s: %v", linterName, err) } - a := &analysis.Analyzer{ - Name: linterName, - Doc: "Finds commonly misspelled English words", - Run: func(pass *analysis.Pass) (any, error) { - for _, file := range pass.Files { - err := runMisspellOnFile(pass, file, replacer, settings.Mode) - if err != nil { - return nil, err + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Finds commonly misspelled English words", + Run: func(pass *analysis.Pass) (any, error) { + for _, file := range pass.Files { + err := runMisspellOnFile(pass, file, replacer, settings.Mode) + if err != nil { + return nil, err + } } - } - return nil, nil - }, - } - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func createMisspellReplacer(settings *config.MisspellSettings) (*misspell.Replacer, error) { diff --git a/pkg/golinters/mnd/mnd.go b/pkg/golinters/mnd/mnd.go index 52521e92dd15..07174c899f57 100644 --- a/pkg/golinters/mnd/mnd.go +++ b/pkg/golinters/mnd/mnd.go @@ -2,18 +2,15 @@ package mnd import ( mnd "github.com/tommy-muehle/go-mnd/v2" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.MndSettings) *goanalysis.Linter { - a := mnd.Analyzer + cfg := map[string]any{} - var linterCfg map[string]map[string]any if settings != nil { - cfg := make(map[string]any) if len(settings.Checks) > 0 { cfg["checks"] = settings.Checks } @@ -26,16 +23,11 @@ func New(settings *config.MndSettings) *goanalysis.Linter { if len(settings.IgnoredFunctions) > 0 { cfg["ignored-functions"] = settings.IgnoredFunctions } - - linterCfg = map[string]map[string]any{ - a.Name: cfg, - } } - return goanalysis.NewLinter( - a.Name, - "An analyzer to detect magic numbers.", - []*analysis.Analyzer{a}, - linterCfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(mnd.Analyzer). + WithDesc("An analyzer to detect magic numbers."). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/musttag/musttag.go b/pkg/golinters/musttag/musttag.go index 030707327b7f..d17df9c2b8d9 100644 --- a/pkg/golinters/musttag/musttag.go +++ b/pkg/golinters/musttag/musttag.go @@ -2,7 +2,6 @@ package musttag import ( "go-simpler.org/musttag" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -21,9 +20,7 @@ func New(settings *config.MustTagSettings) *goanalysis.Linter { } } - a := musttag.New(funcs...) - return goanalysis. - NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil). + NewLinterFromAnalyzer(musttag.New(funcs...)). WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/nakedret/nakedret.go b/pkg/golinters/nakedret/nakedret.go index 1b769acd8c8d..90053a1aab98 100644 --- a/pkg/golinters/nakedret/nakedret.go +++ b/pkg/golinters/nakedret/nakedret.go @@ -2,7 +2,6 @@ package nakedret import ( "github.com/alexkohler/nakedret/v2" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -16,12 +15,7 @@ func New(settings *config.NakedretSettings) *goanalysis.Linter { cfg.MaxLength = settings.MaxFuncLines } - a := nakedret.NakedReturnAnalyzer(cfg) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(nakedret.NakedReturnAnalyzer(cfg)). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/nestif/nestif.go b/pkg/golinters/nestif/nestif.go index 1a6b55cafc22..e5823723c83a 100644 --- a/pkg/golinters/nestif/nestif.go +++ b/pkg/golinters/nestif/nestif.go @@ -8,25 +8,18 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "nestif" - func New(settings *config.NestifSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - runNestIf(pass, settings) - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Reports deeply nested if statements", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "nestif", + Doc: "Reports deeply nested if statements", + Run: func(pass *analysis.Pass) (any, error) { + runNestIf(pass, settings) + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func runNestIf(pass *analysis.Pass, settings *config.NestifSettings) { diff --git a/pkg/golinters/nilerr/nilerr.go b/pkg/golinters/nilerr/nilerr.go index 9345b945be11..fa5dcdc259fc 100644 --- a/pkg/golinters/nilerr/nilerr.go +++ b/pkg/golinters/nilerr/nilerr.go @@ -2,18 +2,13 @@ package nilerr import ( "github.com/gostaticanalysis/nilerr" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := nilerr.Analyzer - - return goanalysis.NewLinter( - a.Name, - "Finds the code that returns nil even if it checks that the error is not nil.", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(nilerr.Analyzer). + WithDesc("Find the code that returns nil even if it checks that the error is not nil."). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/nilnesserr/nilnesserr.go b/pkg/golinters/nilnesserr/nilnesserr.go index b54992e29bb5..95eaf94abe25 100644 --- a/pkg/golinters/nilnesserr/nilnesserr.go +++ b/pkg/golinters/nilnesserr/nilnesserr.go @@ -2,22 +2,18 @@ package nilnesserr import ( "github.com/alingse/nilnesserr" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) func New() *goanalysis.Linter { - a, err := nilnesserr.NewAnalyzer(nilnesserr.LinterSetting{}) + analyzer, err := nilnesserr.NewAnalyzer(nilnesserr.LinterSetting{}) if err != nil { internal.LinterLogger.Fatalf("nilnesserr: create analyzer: %v", err) } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/nilnil/nilnil.go b/pkg/golinters/nilnil/nilnil.go index 5f42e24c96fc..4936a6b84c8f 100644 --- a/pkg/golinters/nilnil/nilnil.go +++ b/pkg/golinters/nilnil/nilnil.go @@ -2,33 +2,28 @@ package nilnil import ( "github.com/Antonboom/nilnil/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.NilNilSettings) *goanalysis.Linter { - a := analyzer.New() + var cfg map[string]any - cfg := make(map[string]map[string]any) if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "detect-opposite": settings.DetectOpposite, } if b := settings.OnlyTwo; b != nil { - cfg[a.Name]["only-two"] = *b + cfg["only-two"] = *b } if len(settings.CheckedTypes) != 0 { - cfg[a.Name]["checked-types"] = settings.CheckedTypes + cfg["checked-types"] = settings.CheckedTypes } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ). + return goanalysis. + NewLinterFromAnalyzer(analyzer.New()). + WithConfig(cfg). WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/nlreturn/nlreturn.go b/pkg/golinters/nlreturn/nlreturn.go index ce2130c52c81..7b7ab745ad7b 100644 --- a/pkg/golinters/nlreturn/nlreturn.go +++ b/pkg/golinters/nlreturn/nlreturn.go @@ -2,26 +2,22 @@ package nlreturn import ( "github.com/ssgreg/nlreturn/v2/pkg/nlreturn" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.NlreturnSettings) *goanalysis.Linter { - a := nlreturn.NewAnalyzer() + var cfg map[string]any - cfg := map[string]map[string]any{} if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "block-size": settings.BlockSize, } } - - return goanalysis.NewLinter( - a.Name, - "nlreturn checks for a new line before return and branch statements to increase code clarity", - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(nlreturn.NewAnalyzer()). + WithDesc("Checks for a new line before return and branch statements to increase code clarity"). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/noctx/noctx.go b/pkg/golinters/noctx/noctx.go index b0c5f9b50040..c3e5be104262 100644 --- a/pkg/golinters/noctx/noctx.go +++ b/pkg/golinters/noctx/noctx.go @@ -2,18 +2,13 @@ package noctx import ( "github.com/sonatard/noctx" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := noctx.Analyzer - - return goanalysis.NewLinter( - a.Name, - "Finds sending http request without context.Context", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(noctx.Analyzer). + WithDesc("Detects function and method with missing usage of context.Context"). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/noctx/testdata/noctx.go b/pkg/golinters/noctx/testdata/noctx.go index 8b077a566206..8a34443e2029 100644 --- a/pkg/golinters/noctx/testdata/noctx.go +++ b/pkg/golinters/noctx/testdata/noctx.go @@ -3,73 +3,58 @@ package testdata import ( "context" + "database/sql" "net/http" ) var newRequestPkg = http.NewRequest -func Noctx() { - const url = "http://example.com" +func _() { + const url = "https://example.com" + cli := &http.Client{} ctx := context.Background() - http.Get(url) // want `net/http\.Get must not be called` - _ = http.Get // OK - f := http.Get // OK - f(url) // want `net/http\.Get must not be called` - - http.Head(url) // want `net/http\.Head must not be called` - http.Post(url, "", nil) // want `net/http\.Post must not be called` - http.PostForm(url, nil) // want `net/http\.PostForm must not be called` - - cli.Get(url) // want `\(\*net/http\.Client\)\.Get must not be called` - _ = cli.Get // OK - m := cli.Get // OK - m(url) // want `\(\*net/http\.Client\)\.Get must not be called` - - cli.Head(url) // want `\(\*net/http\.Client\)\.Head must not be called` - cli.Post(url, "", nil) // want `\(\*net/http\.Client\)\.Post must not be called` - cli.PostForm(url, nil) // want `\(\*net/http\.Client\)\.PostForm must not be called` - req, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` cli.Do(req) req2, _ := http.NewRequestWithContext(ctx, http.MethodPost, url, nil) // OK cli.Do(req2) - req3, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req3, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req3 = req3.WithContext(ctx) cli.Do(req3) f2 := func(req *http.Request, ctx context.Context) *http.Request { return req } - req4, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req4, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req4 = f2(req4, ctx) - req41, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req41, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req41 = req41.WithContext(ctx) req41 = f2(req41, ctx) newRequest := http.NewRequest - req5, _ := newRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req5, _ := newRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` cli.Do(req5) - req51, _ := newRequest(http.MethodPost, url, nil) // OK + req51, _ := newRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req51 = req51.WithContext(ctx) cli.Do(req51) - req52, _ := newRequestPkg(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req52, _ := newRequestPkg(http.MethodPost, url, nil) // TODO: false negative `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` cli.Do(req52) type MyRequest = http.Request f3 := func(req *MyRequest, ctx context.Context) *MyRequest { return req } - req6, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req6, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req6 = f3(req6, ctx) - req61, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req61, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req61 = req61.WithContext(ctx) req61 = f3(req61, ctx) @@ -77,22 +62,22 @@ func Noctx() { f4 := func(req *MyRequest2, ctx context.Context) *MyRequest2 { return req } - req7, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req7, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req71 := MyRequest2(*req7) f4(&req71, ctx) - req72, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req72, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req72 = req72.WithContext(ctx) req73 := MyRequest2(*req7) f4(&req73, ctx) req8, _ := func() (*http.Request, error) { - return http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + return http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` }() cli.Do(req8) req82, _ := func() (*http.Request, error) { - req82, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req82, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req82 = req82.WithContext(ctx) return req82, nil }() @@ -101,34 +86,99 @@ func Noctx() { f5 := func(req, req2 *http.Request, ctx context.Context) (*http.Request, *http.Request) { return req, req2 } - req9, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req9, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req9, _ = f5(req9, req9, ctx) - req91, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req91, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req91 = req91.WithContext(ctx) req9, _ = f5(req91, req91, ctx) - req10, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req11, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req10, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req11, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req10, req11 = f5(req10, req11, ctx) - req101, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req111, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req101, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req111, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req111 = req111.WithContext(ctx) req101, req111 = f5(req101, req111, ctx) func() (*http.Request, *http.Request) { - req12, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req13, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req12, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req13, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` return req12, req13 }() func() (*http.Request, *http.Request) { - req14, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req15, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req14, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req15, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req15 = req15.WithContext(ctx) return req14, req15 }() + + req121, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req121.AddCookie(&http.Cookie{Name: "k", Value: "v"}) + req121 = req121.WithContext(context.WithValue(req121.Context(), struct{}{}, 0)) + cli.Do(req121) +} + +func _() { + const url = "http://example.com" + cli := &http.Client{} + + http.Get(url) // want `net/http\.Get must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + _ = http.Get // OK + f := http.Get // OK + f(url) // want `net/http\.Get must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + + http.Head(url) // want `net/http\.Head must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + http.Post(url, "", nil) // want `net/http\.Post must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + http.PostForm(url, nil) // want `net/http\.PostForm must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + + cli.Get(url) // want `\(\*net/http\.Client\)\.Get must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + _ = cli.Get // OK + m := cli.Get // OK + m(url) // want `\(\*net/http\.Client\)\.Get must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + + cli.Head(url) // want `\(\*net/http\.Client\)\.Head must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + cli.Post(url, "", nil) // want `\(\*net/http\.Client\)\.Post must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + cli.PostForm(url, nil) // want `\(\*net/http\.Client\)\.PostForm must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` } +func _() { + ctx := context.Background() + + db, _ := sql.Open("noctx", "noctx://") + + db.Exec("select * from testdata") // want `\(\*database/sql\.DB\)\.Exec must not be called. use \(\*database/sql\.DB\)\.ExecContext` + db.ExecContext(ctx, "select * from testdata") + + db.Ping() // want `\(\*database/sql\.DB\)\.Ping must not be called. use \(\*database/sql\.DB\)\.PingContext` + db.PingContext(ctx) + + db.Prepare("select * from testdata") // want `\(\*database/sql\.DB\)\.Prepare must not be called. use \(\*database/sql\.DB\)\.PrepareContext` + db.PrepareContext(ctx, "select * from testdata") + + db.Query("select * from testdata") // want `\(\*database/sql\.DB\)\.Query must not be called. use \(\*database/sql\.DB\)\.QueryContext` + db.QueryContext(ctx, "select * from testdata") + + db.QueryRow("select * from testdata") // want `\(\*database/sql\.DB\)\.QueryRow must not be called. use \(\*database/sql\.DB\)\.QueryRowContext` + db.QueryRowContext(ctx, "select * from testdata") + + // transactions + + tx, _ := db.Begin() + tx.Exec("select * from testdata") // want `\(\*database/sql\.Tx\)\.Exec must not be called. use \(\*database/sql\.Tx\)\.ExecContext` + tx.ExecContext(ctx, "select * from testdata") + + tx.Prepare("select * from testdata") // want `\(\*database/sql\.Tx\)\.Prepare must not be called. use \(\*database/sql\.Tx\)\.PrepareContext` + tx.PrepareContext(ctx, "select * from testdata") + + tx.Query("select * from testdata") // want `\(\*database/sql\.Tx\)\.Query must not be called. use \(\*database/sql\.Tx\)\.QueryContext` + tx.QueryContext(ctx, "select * from testdata") + + tx.QueryRow("select * from testdata") // want `\(\*database/sql\.Tx\)\.QueryRow must not be called. use \(\*database/sql\.Tx\)\.QueryRowContext` + tx.QueryRowContext(ctx, "select * from testdata") + + _ = tx.Commit() +} diff --git a/pkg/golinters/noctx/testdata/noctx_cgo.go b/pkg/golinters/noctx/testdata/noctx_cgo.go index 64f5ea6c0d49..63b15477d8c3 100644 --- a/pkg/golinters/noctx/testdata/noctx_cgo.go +++ b/pkg/golinters/noctx/testdata/noctx_cgo.go @@ -13,6 +13,7 @@ import "C" import ( "context" + "database/sql" "net/http" "unsafe" ) @@ -26,67 +27,51 @@ func _() { var newRequestPkg = http.NewRequest func _() { - const url = "http://example.com" + const url = "https://example.com" + cli := &http.Client{} ctx := context.Background() - http.Get(url) // want `net/http\.Get must not be called` - _ = http.Get // OK - f := http.Get // OK - f(url) // want `net/http\.Get must not be called` - - http.Head(url) // want `net/http\.Head must not be called` - http.Post(url, "", nil) // want `net/http\.Post must not be called` - http.PostForm(url, nil) // want `net/http\.PostForm must not be called` - cli.Get(url) // want `\(\*net/http\.Client\)\.Get must not be called` - _ = cli.Get // OK - m := cli.Get // OK - m(url) // want `\(\*net/http\.Client\)\.Get must not be called` - - cli.Head(url) // want `\(\*net/http\.Client\)\.Head must not be called` - cli.Post(url, "", nil) // want `\(\*net/http\.Client\)\.Post must not be called` - cli.PostForm(url, nil) // want `\(\*net/http\.Client\)\.PostForm must not be called` - - req, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` cli.Do(req) req2, _ := http.NewRequestWithContext(ctx, http.MethodPost, url, nil) // OK cli.Do(req2) - req3, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req3, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req3 = req3.WithContext(ctx) cli.Do(req3) f2 := func(req *http.Request, ctx context.Context) *http.Request { return req } - req4, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req4, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req4 = f2(req4, ctx) - req41, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req41, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req41 = req41.WithContext(ctx) req41 = f2(req41, ctx) newRequest := http.NewRequest - req5, _ := newRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req5, _ := newRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` cli.Do(req5) - req51, _ := newRequest(http.MethodPost, url, nil) // OK + req51, _ := newRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req51 = req51.WithContext(ctx) cli.Do(req51) - req52, _ := newRequestPkg(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req52, _ := newRequestPkg(http.MethodPost, url, nil) // TODO: false negative `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` cli.Do(req52) type MyRequest = http.Request f3 := func(req *MyRequest, ctx context.Context) *MyRequest { return req } - req6, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req6, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req6 = f3(req6, ctx) - req61, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req61, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req61 = req61.WithContext(ctx) req61 = f3(req61, ctx) @@ -94,22 +79,22 @@ func _() { f4 := func(req *MyRequest2, ctx context.Context) *MyRequest2 { return req } - req7, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req7, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req71 := MyRequest2(*req7) f4(&req71, ctx) - req72, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req72, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req72 = req72.WithContext(ctx) req73 := MyRequest2(*req7) f4(&req73, ctx) req8, _ := func() (*http.Request, error) { - return http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + return http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` }() cli.Do(req8) req82, _ := func() (*http.Request, error) { - req82, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req82, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req82 = req82.WithContext(ctx) return req82, nil }() @@ -118,33 +103,99 @@ func _() { f5 := func(req, req2 *http.Request, ctx context.Context) (*http.Request, *http.Request) { return req, req2 } - req9, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req9, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req9, _ = f5(req9, req9, ctx) - req91, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req91, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req91 = req91.WithContext(ctx) req9, _ = f5(req91, req91, ctx) - req10, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req11, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req10, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req11, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req10, req11 = f5(req10, req11, ctx) - req101, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req111, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req101, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req111, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req111 = req111.WithContext(ctx) req101, req111 = f5(req101, req111, ctx) func() (*http.Request, *http.Request) { - req12, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req13, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` + req12, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req13, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` return req12, req13 }() func() (*http.Request, *http.Request) { - req14, _ := http.NewRequest(http.MethodPost, url, nil) // want `should rewrite http.NewRequestWithContext or add \(\*Request\).WithContext` - req15, _ := http.NewRequest(http.MethodPost, url, nil) // OK + req14, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req15, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` req15 = req15.WithContext(ctx) return req14, req15 }() + + req121, _ := http.NewRequest(http.MethodPost, url, nil) // want `net/http\.NewRequest must not be called. use net/http\.NewRequestWithContext` + req121.AddCookie(&http.Cookie{Name: "k", Value: "v"}) + req121 = req121.WithContext(context.WithValue(req121.Context(), struct{}{}, 0)) + cli.Do(req121) +} + +func _() { + const url = "http://example.com" + cli := &http.Client{} + + http.Get(url) // want `net/http\.Get must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + _ = http.Get // OK + f := http.Get // OK + f(url) // want `net/http\.Get must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + + http.Head(url) // want `net/http\.Head must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + http.Post(url, "", nil) // want `net/http\.Post must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + http.PostForm(url, nil) // want `net/http\.PostForm must not be called. use net/http\.NewRequestWithContext and \(\*net/http.Client\)\.Do\(\*http.Request\)` + + cli.Get(url) // want `\(\*net/http\.Client\)\.Get must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + _ = cli.Get // OK + m := cli.Get // OK + m(url) // want `\(\*net/http\.Client\)\.Get must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + + cli.Head(url) // want `\(\*net/http\.Client\)\.Head must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + cli.Post(url, "", nil) // want `\(\*net/http\.Client\)\.Post must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` + cli.PostForm(url, nil) // want `\(\*net/http\.Client\)\.PostForm must not be called. use \(\*net/http.Client\)\.Do\(\*http.Request\)` +} + +func _() { + ctx := context.Background() + + db, _ := sql.Open("noctx", "noctx://") + + db.Exec("select * from testdata") // want `\(\*database/sql\.DB\)\.Exec must not be called. use \(\*database/sql\.DB\)\.ExecContext` + db.ExecContext(ctx, "select * from testdata") + + db.Ping() // want `\(\*database/sql\.DB\)\.Ping must not be called. use \(\*database/sql\.DB\)\.PingContext` + db.PingContext(ctx) + + db.Prepare("select * from testdata") // want `\(\*database/sql\.DB\)\.Prepare must not be called. use \(\*database/sql\.DB\)\.PrepareContext` + db.PrepareContext(ctx, "select * from testdata") + + db.Query("select * from testdata") // want `\(\*database/sql\.DB\)\.Query must not be called. use \(\*database/sql\.DB\)\.QueryContext` + db.QueryContext(ctx, "select * from testdata") + + db.QueryRow("select * from testdata") // want `\(\*database/sql\.DB\)\.QueryRow must not be called. use \(\*database/sql\.DB\)\.QueryRowContext` + db.QueryRowContext(ctx, "select * from testdata") + + // transactions + + tx, _ := db.Begin() + tx.Exec("select * from testdata") // want `\(\*database/sql\.Tx\)\.Exec must not be called. use \(\*database/sql\.Tx\)\.ExecContext` + tx.ExecContext(ctx, "select * from testdata") + + tx.Prepare("select * from testdata") // want `\(\*database/sql\.Tx\)\.Prepare must not be called. use \(\*database/sql\.Tx\)\.PrepareContext` + tx.PrepareContext(ctx, "select * from testdata") + + tx.Query("select * from testdata") // want `\(\*database/sql\.Tx\)\.Query must not be called. use \(\*database/sql\.Tx\)\.QueryContext` + tx.QueryContext(ctx, "select * from testdata") + + tx.QueryRow("select * from testdata") // want `\(\*database/sql\.Tx\)\.QueryRow must not be called. use \(\*database/sql\.Tx\)\.QueryRowContext` + tx.QueryRowContext(ctx, "select * from testdata") + + _ = tx.Commit() } diff --git a/pkg/golinters/noinlineerr/noinlineerr.go b/pkg/golinters/noinlineerr/noinlineerr.go new file mode 100644 index 000000000000..4f9f82eb4d0c --- /dev/null +++ b/pkg/golinters/noinlineerr/noinlineerr.go @@ -0,0 +1,13 @@ +package noinlineerr + +import ( + "github.com/AlwxSin/noinlineerr" + + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" +) + +func New() *goanalysis.Linter { + return goanalysis. + NewLinterFromAnalyzer(noinlineerr.NewAnalyzer()). + WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/golinters/noinlineerr/noinlineerr_integration_test.go b/pkg/golinters/noinlineerr/noinlineerr_integration_test.go new file mode 100644 index 000000000000..3b14450932a1 --- /dev/null +++ b/pkg/golinters/noinlineerr/noinlineerr_integration_test.go @@ -0,0 +1,19 @@ +package noinlineerr + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} + +func TestFix(t *testing.T) { + integration.RunFix(t) +} + +func TestFixPathPrefix(t *testing.T) { + integration.RunFixPathPrefix(t) +} diff --git a/pkg/golinters/noinlineerr/testdata/fix/in/noinlineerr.go b/pkg/golinters/noinlineerr/testdata/fix/in/noinlineerr.go new file mode 100644 index 000000000000..62c90bd98017 --- /dev/null +++ b/pkg/golinters/noinlineerr/testdata/fix/in/noinlineerr.go @@ -0,0 +1,59 @@ +//golangcitest:args -Enoinlineerr +//golangcitest:expected_exitcode 0 +package testdata + +type MyAliasErr error + +type MyCustomError struct{} + +func (mc *MyCustomError) Error() string { + return "error" +} + +func doSomething() error { + return nil +} + +func doSmthManyArgs(a, b, c, d int) error { + return nil +} + +func doSmthMultipleReturn() (bool, error) { + return false, nil +} + +func doMyAliasErr() MyAliasErr { + return nil +} + +func doMyCustomErr() *MyCustomError { + return &MyCustomError{} +} + +func invalid() error { + err := doSomething() + if err != nil { + return err + } + + err = doSmthManyArgs(0, + 0, + 0, + 0, + ) + if err != nil { + return err + } + + err = doMyAliasErr() + if err != nil { + return err + } + + err = doMyCustomErr() + if err != nil { + return err + } + + return nil +} diff --git a/pkg/golinters/noinlineerr/testdata/fix/out/noinlineerr.go b/pkg/golinters/noinlineerr/testdata/fix/out/noinlineerr.go new file mode 100644 index 000000000000..62c90bd98017 --- /dev/null +++ b/pkg/golinters/noinlineerr/testdata/fix/out/noinlineerr.go @@ -0,0 +1,59 @@ +//golangcitest:args -Enoinlineerr +//golangcitest:expected_exitcode 0 +package testdata + +type MyAliasErr error + +type MyCustomError struct{} + +func (mc *MyCustomError) Error() string { + return "error" +} + +func doSomething() error { + return nil +} + +func doSmthManyArgs(a, b, c, d int) error { + return nil +} + +func doSmthMultipleReturn() (bool, error) { + return false, nil +} + +func doMyAliasErr() MyAliasErr { + return nil +} + +func doMyCustomErr() *MyCustomError { + return &MyCustomError{} +} + +func invalid() error { + err := doSomething() + if err != nil { + return err + } + + err = doSmthManyArgs(0, + 0, + 0, + 0, + ) + if err != nil { + return err + } + + err = doMyAliasErr() + if err != nil { + return err + } + + err = doMyCustomErr() + if err != nil { + return err + } + + return nil +} diff --git a/pkg/golinters/noinlineerr/testdata/noinlineerr.go b/pkg/golinters/noinlineerr/testdata/noinlineerr.go new file mode 100644 index 000000000000..3bf739b7d1c3 --- /dev/null +++ b/pkg/golinters/noinlineerr/testdata/noinlineerr.go @@ -0,0 +1,87 @@ +//golangcitest:args -Enoinlineerr +package testdata + +import ( + "fmt" + "strconv" +) + +type MyAliasErr error + +type MyCustomError struct {} + +func (mc *MyCustomError) Error() string { + return "error" +} + +func doSomething() error { + return nil +} + +func doSmthManyArgs(a, b, c, d int) error { + return nil +} + +func doSmthMultipleReturn() (bool, error) { + return false, nil +} + +func doMyAliasErr() MyAliasErr { + return nil +} + +func doMyCustomErr() *MyCustomError { + return &MyCustomError{} +} + +func valid() error { + err := doSomething() // ok + if err != nil { + return err + } + + err = doSmthManyArgs(0, 0, 0, 0) // ok + if err != nil { + return err + } + + _, err = doSmthMultipleReturn() // ok + if err != nil { + return err + } + + if ok, _ := strconv.ParseBool("1"); ok { + fmt.Println("ok") + } + + return nil +} + +func invalid() error { + if err := doSomething(); err != nil { // want "avoid inline error handling using `if err := ...; err != nil`; use plain assignment `err := ...`" + return err + } + + if err := doSmthManyArgs(0, // want "avoid inline error handling using `if err := ...; err != nil`; use plain assignment `err := ...`" + 0, + 0, + 0, + ); err != nil { + return err + } + + if _, err := doSmthMultipleReturn(); err != nil { // want "avoid inline error handling using `if err := ...; err != nil`; use plain assignment `err := ...`" + _ = false + return err + } + + if err := doMyAliasErr(); err != nil { // want "avoid inline error handling using `if err := ...; err != nil`; use plain assignment `err := ...`" + return err + } + + if err := doMyCustomErr(); err != nil { // want "avoid inline error handling using `if err := ...; err != nil`; use plain assignment `err := ...`" + return err + } + + return nil +} diff --git a/pkg/golinters/nolintlint/internal/nolintlint.go b/pkg/golinters/nolintlint/internal/nolintlint.go index 2be7c5c144ea..a20161405f1c 100644 --- a/pkg/golinters/nolintlint/internal/nolintlint.go +++ b/pkg/golinters/nolintlint/internal/nolintlint.go @@ -55,8 +55,8 @@ var ( ) //nolint:funlen,gocyclo // the function is going to be refactored in the future -func (l Linter) Run(pass *analysis.Pass) ([]goanalysis.Issue, error) { - var issues []goanalysis.Issue +func (l Linter) Run(pass *analysis.Pass) ([]*goanalysis.Issue, error) { + var issues []*goanalysis.Issue for _, file := range pass.Files { for _, c := range file.Comments { diff --git a/pkg/golinters/nolintlint/internal/nolintlint_test.go b/pkg/golinters/nolintlint/internal/nolintlint_test.go index 788d6b5a84dd..b534fbf89511 100644 --- a/pkg/golinters/nolintlint/internal/nolintlint_test.go +++ b/pkg/golinters/nolintlint/internal/nolintlint_test.go @@ -19,7 +19,7 @@ func TestLinter_Run(t *testing.T) { needs Needs excludes []string contents string - expected []result.Issue + expected []*result.Issue }{ { desc: "when no explanation is provided", @@ -36,7 +36,7 @@ func foo() { other() //nolintother } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `//nolint` should provide explanation such as `//nolint // this is why`", @@ -69,7 +69,7 @@ func foo() { //nolint:dupl func foo() {} `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why`", Pos: token.Position{Filename: "testing.go", Offset: 47, Line: 5, Column: 1}, @@ -97,7 +97,7 @@ func foo() { bad() //nolint // because } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `//nolint` should mention specific linter such as `//nolint:my-linter`", @@ -120,7 +120,7 @@ func foo() { good() //nolint } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `// nolint` should be written without leading space as `//nolint`", @@ -158,7 +158,7 @@ func foo() { good() //nolint: linter1, linter2 } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:linter1 linter2` should match `//nolint[:] [// ]`", Pos: token.Position{Filename: "testing.go", Offset: 71, Line: 5, Column: 9}, @@ -183,7 +183,7 @@ func foo() { bad() //nolint } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint` is unused", Pos: token.Position{Filename: "testing.go", Offset: 34, Line: 4, Column: 9}, @@ -205,7 +205,7 @@ func foo() { bad() //nolint:somelinter } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:somelinter` is unused for linter \"somelinter\"", Pos: token.Position{Filename: "testing.go", Offset: 34, Line: 4, Column: 9}, @@ -229,7 +229,7 @@ func foo() { bad() } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:somelinter` is unused for linter \"somelinter\"", Pos: token.Position{Filename: "testing.go", Offset: 13, Line: 3, Column: 1}, @@ -252,7 +252,7 @@ func foo() { bad() //nolint:linter1,linter2 } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `//nolint:linter1,linter2` is unused for linter \"linter1\"", @@ -289,7 +289,7 @@ func foo() { analysisIssues, err := linter.Run(pass) require.NoError(t, err) - var issues []result.Issue + var issues []*result.Issue for _, i := range analysisIssues { issues = append(issues, i.Issue) } diff --git a/pkg/golinters/nolintlint/nolintlint.go b/pkg/golinters/nolintlint/nolintlint.go index f19b8324c295..6f3d373063f8 100644 --- a/pkg/golinters/nolintlint/nolintlint.go +++ b/pkg/golinters/nolintlint/nolintlint.go @@ -17,7 +17,7 @@ const LinterName = nolintlint.LinterName func New(settings *config.NoLintLintSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue var needs nolintlint.Needs if settings.RequireExplanation { @@ -35,33 +35,29 @@ func New(settings *config.NoLintLintSettings) *goanalysis.Linter { internal.LinterLogger.Fatalf("%s: create analyzer: %v", nolintlint.LinterName, err) } - analyzer := &analysis.Analyzer{ - Name: nolintlint.LinterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues, err := lnt.Run(pass) - if err != nil { - return nil, fmt.Errorf("linter failed to run: %w", err) - } + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: nolintlint.LinterName, + Doc: "Reports ill-formed or insufficient nolint directives", + Run: func(pass *analysis.Pass) (any, error) { + issues, err := lnt.Run(pass) + if err != nil { + return nil, fmt.Errorf("linter failed to run: %w", err) + } - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + if len(issues) == 0 { + return nil, nil + } - return nil, nil - }, - } + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return goanalysis.NewLinter( - nolintlint.LinterName, - "Reports ill-formed or insufficient nolint directives", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/nonamedreturns/nonamedreturns.go b/pkg/golinters/nonamedreturns/nonamedreturns.go index 91354f6a4492..4149ef818e20 100644 --- a/pkg/golinters/nonamedreturns/nonamedreturns.go +++ b/pkg/golinters/nonamedreturns/nonamedreturns.go @@ -2,28 +2,22 @@ package nonamedreturns import ( "github.com/firefart/nonamedreturns/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.NoNamedReturnsSettings) *goanalysis.Linter { - a := analyzer.Analyzer + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - analyzer.FlagReportErrorInDefer: settings.ReportErrorInDefer, - }, + cfg = map[string]any{ + analyzer.FlagReportErrorInDefer: settings.ReportErrorInDefer, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.Analyzer). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/nosprintfhostport/nosprintfhostport.go b/pkg/golinters/nosprintfhostport/nosprintfhostport.go index cca70680cf6c..f8ca26b738c9 100644 --- a/pkg/golinters/nosprintfhostport/nosprintfhostport.go +++ b/pkg/golinters/nosprintfhostport/nosprintfhostport.go @@ -2,18 +2,12 @@ package nosprintfhostport import ( "github.com/stbenjam/no-sprintf-host-port/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := analyzer.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(analyzer.Analyzer). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/paralleltest/paralleltest.go b/pkg/golinters/paralleltest/paralleltest.go index 8c811ca511af..f3eac2e05afb 100644 --- a/pkg/golinters/paralleltest/paralleltest.go +++ b/pkg/golinters/paralleltest/paralleltest.go @@ -2,33 +2,28 @@ package paralleltest import ( "github.com/kunwardeep/paralleltest/pkg/paralleltest" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.ParallelTestSettings) *goanalysis.Linter { - a := paralleltest.NewAnalyzer() + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - d := map[string]any{ + cfg = map[string]any{ "i": settings.IgnoreMissing, "ignoremissingsubtests": settings.IgnoreMissingSubtests, } if config.IsGoGreaterThanOrEqual(settings.Go, "1.22") { - d["ignoreloopVar"] = true + cfg["ignoreloopVar"] = true } - - cfg = map[string]map[string]any{a.Name: d} } - return goanalysis.NewLinter( - a.Name, - "Detects missing usage of t.Parallel() method in your Go test", - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(paralleltest.NewAnalyzer()). + WithDesc("Detects missing usage of t.Parallel() method in your Go test"). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/perfsprint/perfsprint.go b/pkg/golinters/perfsprint/perfsprint.go index f870ee00115a..9684c27c6639 100644 --- a/pkg/golinters/perfsprint/perfsprint.go +++ b/pkg/golinters/perfsprint/perfsprint.go @@ -2,41 +2,36 @@ package perfsprint import ( "github.com/catenacyber/perfsprint/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.PerfSprintSettings) *goanalysis.Linter { - a := analyzer.New() - - cfg := map[string]map[string]any{ - a.Name: {"fiximports": false}, + cfg := map[string]any{ + "fiximports": false, } if settings != nil { // NOTE: The option `ignore-tests` is not handled because it should be managed with `linters.exclusions.rules` - cfg[a.Name]["integer-format"] = settings.IntegerFormat - cfg[a.Name]["int-conversion"] = settings.IntConversion + cfg["integer-format"] = settings.IntegerFormat + cfg["int-conversion"] = settings.IntConversion - cfg[a.Name]["error-format"] = settings.ErrorFormat - cfg[a.Name]["err-error"] = settings.ErrError - cfg[a.Name]["errorf"] = settings.ErrorF + cfg["error-format"] = settings.ErrorFormat + cfg["err-error"] = settings.ErrError + cfg["errorf"] = settings.ErrorF - cfg[a.Name]["string-format"] = settings.StringFormat - cfg[a.Name]["sprintf1"] = settings.SprintF1 - cfg[a.Name]["strconcat"] = settings.StrConcat + cfg["string-format"] = settings.StringFormat + cfg["sprintf1"] = settings.SprintF1 + cfg["strconcat"] = settings.StrConcat - cfg[a.Name]["bool-format"] = settings.BoolFormat - cfg[a.Name]["hex-format"] = settings.HexFormat + cfg["bool-format"] = settings.BoolFormat + cfg["hex-format"] = settings.HexFormat } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.New()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/prealloc/prealloc.go b/pkg/golinters/prealloc/prealloc.go index 1ceba6007ce0..c750df990459 100644 --- a/pkg/golinters/prealloc/prealloc.go +++ b/pkg/golinters/prealloc/prealloc.go @@ -11,25 +11,18 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" ) -const linterName = "prealloc" - func New(settings *config.PreallocSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - runPreAlloc(pass, settings) - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Finds slice declarations that could potentially be pre-allocated", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "prealloc", + Doc: "Find slice declarations that could potentially be pre-allocated", + Run: func(pass *analysis.Pass) (any, error) { + runPreAlloc(pass, settings) + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeSyntax) } func runPreAlloc(pass *analysis.Pass, settings *config.PreallocSettings) { @@ -38,7 +31,7 @@ func runPreAlloc(pass *analysis.Pass, settings *config.PreallocSettings) { for _, hint := range hints { pass.Report(analysis.Diagnostic{ Pos: hint.Pos, - Message: fmt.Sprintf("Consider pre-allocating %s", internal.FormatCode(hint.DeclaredSliceName, nil)), + Message: fmt.Sprintf("Consider pre-allocating %s", internal.FormatCode(hint.DeclaredSliceName)), }) } } diff --git a/pkg/golinters/predeclared/predeclared.go b/pkg/golinters/predeclared/predeclared.go index 9bde9d2f3baa..8f2be53c4fc1 100644 --- a/pkg/golinters/predeclared/predeclared.go +++ b/pkg/golinters/predeclared/predeclared.go @@ -4,25 +4,23 @@ import ( "strings" "github.com/nishanths/predeclared/passes/predeclared" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.PredeclaredSettings) *goanalysis.Linter { - a := predeclared.Analyzer + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - predeclared.IgnoreFlag: strings.Join(settings.Ignore, ","), - predeclared.QualifiedFlag: settings.Qualified, - }, + cfg = map[string]any{ + predeclared.IgnoreFlag: strings.Join(settings.Ignore, ","), + predeclared.QualifiedFlag: settings.Qualified, } } - return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, cfg). + return goanalysis. + NewLinterFromAnalyzer(predeclared.Analyzer). + WithConfig(cfg). WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/promlinter/promlinter.go b/pkg/golinters/promlinter/promlinter.go index ab2c9c569dea..491409f4ef7a 100644 --- a/pkg/golinters/promlinter/promlinter.go +++ b/pkg/golinters/promlinter/promlinter.go @@ -17,7 +17,7 @@ const linterName = "promlinter" func New(settings *config.PromlinterSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue var promSettings promlinter.Setting if settings != nil { @@ -27,42 +27,38 @@ func New(settings *config.PromlinterSettings) *goanalysis.Linter { } } - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runPromLinter(pass, promSettings) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Check Prometheus metrics naming via promlint", + Run: func(pass *analysis.Pass) (any, error) { + issues := runPromLinter(pass, promSettings) - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + if len(issues) == 0 { + return nil, nil + } - return nil, nil - }, - } + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return goanalysis.NewLinter( - linterName, - "Check Prometheus metrics naming via promlint", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + return nil, nil + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } -func runPromLinter(pass *analysis.Pass, promSettings promlinter.Setting) []goanalysis.Issue { +func runPromLinter(pass *analysis.Pass, promSettings promlinter.Setting) []*goanalysis.Issue { lintIssues := promlinter.RunLint(pass.Fset, pass.Files, promSettings) if len(lintIssues) == 0 { return nil } - issues := make([]goanalysis.Issue, len(lintIssues)) + issues := make([]*goanalysis.Issue, len(lintIssues)) for k, i := range lintIssues { issue := result.Issue{ Pos: i.Pos, diff --git a/pkg/golinters/protogetter/protogetter.go b/pkg/golinters/protogetter/protogetter.go index c13c98af5792..bee5da263915 100644 --- a/pkg/golinters/protogetter/protogetter.go +++ b/pkg/golinters/protogetter/protogetter.go @@ -2,7 +2,6 @@ package protogetter import ( "github.com/ghostiam/protogetter" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -10,6 +9,7 @@ import ( func New(settings *config.ProtoGetterSettings) *goanalysis.Linter { var cfg protogetter.Config + if settings != nil { cfg = protogetter.Config{ SkipGeneratedBy: settings.SkipGeneratedBy, @@ -19,12 +19,7 @@ func New(settings *config.ProtoGetterSettings) *goanalysis.Linter { } } - a := protogetter.NewAnalyzer(&cfg) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(protogetter.NewAnalyzer(&cfg)). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/protogetter/testdata/go.mod b/pkg/golinters/protogetter/testdata/go.mod index 64d3739fe4e5..ac7bf891a2f6 100644 --- a/pkg/golinters/protogetter/testdata/go.mod +++ b/pkg/golinters/protogetter/testdata/go.mod @@ -3,13 +3,13 @@ module protogetter go 1.23.0 require ( - google.golang.org/grpc v1.71.1 + google.golang.org/grpc v1.72.2 google.golang.org/protobuf v1.36.6 ) require ( - golang.org/x/net v0.38.0 // indirect - golang.org/x/sys v0.31.0 // indirect - golang.org/x/text v0.23.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect + golang.org/x/net v0.40.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.25.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect ) diff --git a/pkg/golinters/protogetter/testdata/go.sum b/pkg/golinters/protogetter/testdata/go.sum index 98076ebf7ddb..88c148026714 100644 --- a/pkg/golinters/protogetter/testdata/go.sum +++ b/pkg/golinters/protogetter/testdata/go.sum @@ -20,15 +20,15 @@ go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= -golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= -golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= -golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50= -google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI= -google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ= +google.golang.org/grpc v1.72.2 h1:TdbGzwb82ty4OusHWepvFWGLgIbNo1/SUynEN0ssqv8= +google.golang.org/grpc v1.72.2/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= diff --git a/pkg/golinters/reassign/reassign.go b/pkg/golinters/reassign/reassign.go index 7d9f84285b89..35e661cae84b 100644 --- a/pkg/golinters/reassign/reassign.go +++ b/pkg/golinters/reassign/reassign.go @@ -5,28 +5,22 @@ import ( "strings" "github.com/curioswitch/go-reassign" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.ReassignSettings) *goanalysis.Linter { - a := reassign.NewAnalyzer() + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil && len(settings.Patterns) > 0 { - cfg = map[string]map[string]any{ - a.Name: { - reassign.FlagPattern: fmt.Sprintf("^(%s)$", strings.Join(settings.Patterns, "|")), - }, + cfg = map[string]any{ + reassign.FlagPattern: fmt.Sprintf("^(%s)$", strings.Join(settings.Patterns, "|")), } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(reassign.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/recvcheck/recvcheck.go b/pkg/golinters/recvcheck/recvcheck.go index ed1eb0b78765..76db48f93979 100644 --- a/pkg/golinters/recvcheck/recvcheck.go +++ b/pkg/golinters/recvcheck/recvcheck.go @@ -2,7 +2,6 @@ package recvcheck import ( "github.com/raeperd/recvcheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -16,12 +15,7 @@ func New(settings *config.RecvcheckSettings) *goanalysis.Linter { cfg.Exclusions = settings.Exclusions } - a := recvcheck.NewAnalyzer(cfg) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(recvcheck.NewAnalyzer(cfg)). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index 5f9b3a90ace1..3e13c516fa12 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -35,45 +35,44 @@ var ( func New(settings *config.ReviveSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue analyzer := &analysis.Analyzer{ - Name: goanalysis.TheOnlyAnalyzerName, - Doc: goanalysis.TheOnlyanalyzerDoc, + Name: linterName, + Doc: "Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.", Run: goanalysis.DummyRun, } - return goanalysis.NewLinter( - linterName, - "Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.", - []*analysis.Analyzer{analyzer}, - nil, - ).WithContextSetter(func(lintCtx *linter.Context) { - w, err := newWrapper(settings) - if err != nil { - lintCtx.Log.Errorf("setup revive: %v", err) - return - } - - analyzer.Run = func(pass *analysis.Pass) (any, error) { - issues, err := w.run(pass) + return goanalysis. + NewLinterFromAnalyzer(analyzer). + WithContextSetter(func(lintCtx *linter.Context) { + w, err := newWrapper(settings) if err != nil { - return nil, err + lintCtx.Log.Errorf("setup revive: %v", err) + return } - if len(issues) == 0 { - return nil, nil - } + analyzer.Run = func(pass *analysis.Pass) (any, error) { + issues, err := w.run(pass) + if err != nil { + return nil, err + } - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + if len(issues) == 0 { + return nil, nil + } - return nil, nil - } - }).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeSyntax) + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() + + return nil, nil + } + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeSyntax) } type wrapper struct { @@ -107,7 +106,7 @@ func newWrapper(settings *config.ReviveSettings) (*wrapper, error) { }, nil } -func (w *wrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) { +func (w *wrapper) run(pass *analysis.Pass) ([]*goanalysis.Issue, error) { packages := [][]string{internal.GetGoFileNames(pass)} failures, err := w.revive.Lint(packages, w.lintingRules, *w.conf) @@ -115,7 +114,7 @@ func (w *wrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) { return nil, err } - var issues []goanalysis.Issue + var issues []*goanalysis.Issue for failure := range failures { if failure.Confidence < w.conf.Confidence { continue @@ -127,7 +126,7 @@ func (w *wrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) { return issues, nil } -func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) goanalysis.Issue { +func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) *goanalysis.Issue { lineRangeTo := failure.Position.End.Line if failure.RuleName == (&rule.ExportedRule{}).Name() { lineRangeTo = failure.Position.Start.Line @@ -153,7 +152,7 @@ func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) goanalysis f := pass.Fset.File(token.Pos(failure.Position.Start.Offset)) // Skip cgo files because the positions are wrong. - if failure.GetFilename() == f.Name() { + if failure.Filename() == f.Name() { issue.SuggestedFixes = []analysis.SuggestedFix{{ TextEdits: []analysis.TextEdit{{ Pos: f.LineStart(failure.Position.Start.Line), @@ -270,7 +269,7 @@ func safeTomlSlice(r []any) []any { } // This element is not exported by revive, so we need copy the code. -// Extracted from https://github.com/mgechev/revive/blob/v1.6.0/config/config.go#L16 +// Extracted from https://github.com/mgechev/revive/blob/v1.10.0/config/config.go#L16 var defaultRules = []lint.Rule{ &rule.VarDeclarationsRule{}, &rule.PackageCommentsRule{}, @@ -298,66 +297,70 @@ var defaultRules = []lint.Rule{ } var allRules = append([]lint.Rule{ + &rule.AddConstantRule{}, &rule.ArgumentsLimitRule{}, - &rule.CyclomaticRule{}, - &rule.FileHeaderRule{}, + &rule.AtomicRule{}, + &rule.BannedCharsRule{}, + &rule.BareReturnRule{}, + &rule.BoolLiteralRule{}, + &rule.CallToGCRule{}, + &rule.CognitiveComplexityRule{}, + &rule.CommentsDensityRule{}, + &rule.CommentSpacingsRule{}, &rule.ConfusingNamingRule{}, - &rule.GetReturnRule{}, - &rule.ModifiesParamRule{}, &rule.ConfusingResultsRule{}, - &rule.DeepExitRule{}, - &rule.AddConstantRule{}, - &rule.FlagParamRule{}, - &rule.UnnecessaryStmtRule{}, - &rule.StructTagRule{}, - &rule.ModifiesValRecRule{}, &rule.ConstantLogicalExprRule{}, - &rule.BoolLiteralRule{}, - &rule.ImportsBlocklistRule{}, - &rule.FunctionResultsLimitRule{}, - &rule.MaxPublicStructsRule{}, - &rule.RangeValInClosureRule{}, - &rule.RangeValAddress{}, - &rule.WaitGroupByValueRule{}, - &rule.AtomicRule{}, - &rule.EmptyLinesRule{}, - &rule.LineLengthLimitRule{}, - &rule.CallToGCRule{}, + &rule.CyclomaticRule{}, + &rule.DataRaceRule{}, + &rule.DeepExitRule{}, + &rule.DeferRule{}, &rule.DuplicatedImportsRule{}, - &rule.ImportShadowingRule{}, - &rule.BareReturnRule{}, - &rule.UnusedReceiverRule{}, - &rule.UnhandledErrorRule{}, - &rule.CognitiveComplexityRule{}, - &rule.StringOfIntRule{}, - &rule.StringFormatRule{}, &rule.EarlyReturnRule{}, - &rule.UnconditionalRecursionRule{}, - &rule.IdenticalBranchesRule{}, - &rule.DeferRule{}, - &rule.UnexportedNamingRule{}, - &rule.FunctionLength{}, - &rule.NestedStructs{}, - &rule.UselessBreak{}, - &rule.UncheckedTypeAssertionRule{}, - &rule.TimeEqualRule{}, - &rule.BannedCharsRule{}, - &rule.OptimizeOperandsOrderRule{}, - &rule.UseAnyRule{}, - &rule.DataRaceRule{}, - &rule.CommentSpacingsRule{}, - &rule.IfReturnRule{}, - &rule.RedundantImportAlias{}, - &rule.ImportAliasNamingRule{}, + &rule.EmptyLinesRule{}, &rule.EnforceMapStyleRule{}, &rule.EnforceRepeatedArgTypeStyleRule{}, &rule.EnforceSliceStyleRule{}, - &rule.MaxControlNestingRule{}, - &rule.CommentsDensityRule{}, + &rule.FileHeaderRule{}, &rule.FileLengthLimitRule{}, &rule.FilenameFormatRule{}, + &rule.FlagParamRule{}, + &rule.FunctionLength{}, + &rule.FunctionResultsLimitRule{}, + &rule.GetReturnRule{}, + &rule.IdenticalBranchesRule{}, + &rule.IfReturnRule{}, + &rule.ImportAliasNamingRule{}, + &rule.ImportsBlocklistRule{}, + &rule.ImportShadowingRule{}, + &rule.LineLengthLimitRule{}, + &rule.MaxControlNestingRule{}, + &rule.MaxPublicStructsRule{}, + &rule.ModifiesParamRule{}, + &rule.ModifiesValRecRule{}, + &rule.NestedStructs{}, + &rule.OptimizeOperandsOrderRule{}, + &rule.RangeValAddress{}, + &rule.RangeValInClosureRule{}, &rule.RedundantBuildTagRule{}, + &rule.RedundantImportAlias{}, + &rule.RedundantTestMainExitRule{}, + &rule.StringFormatRule{}, + &rule.StringOfIntRule{}, + &rule.StructTagRule{}, + &rule.TimeDateRule{}, + &rule.TimeEqualRule{}, + &rule.UncheckedTypeAssertionRule{}, + &rule.UnconditionalRecursionRule{}, + &rule.UnexportedNamingRule{}, + &rule.UnhandledErrorRule{}, + &rule.UnnecessaryFormatRule{}, + &rule.UnnecessaryStmtRule{}, + &rule.UnusedReceiverRule{}, + &rule.UseAnyRule{}, &rule.UseErrorsNewRule{}, + &rule.UseFmtPrintRule{}, + &rule.UselessBreak{}, + &rule.WaitGroupByValueRule{}, }, defaultRules...) const defaultConfidence = 0.8 @@ -433,7 +436,7 @@ func displayRules(conf *lint.Config) { slices.Sort(enabledRules) debugf("All available rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", ")) - debugf("Default rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", ")) + debugf("Default rules (%d): %s.", len(defaultRules), strings.Join(extractRulesName(defaultRules), ", ")) debugf("Enabled by config rules (%d): %s.", len(enabledRules), strings.Join(enabledRules, ", ")) debugf("revive configuration: %#v", conf) diff --git a/pkg/golinters/rowserrcheck/rowserrcheck.go b/pkg/golinters/rowserrcheck/rowserrcheck.go index 2bd975ddf28f..de0fe4da917e 100644 --- a/pkg/golinters/rowserrcheck/rowserrcheck.go +++ b/pkg/golinters/rowserrcheck/rowserrcheck.go @@ -2,7 +2,6 @@ package rowserrcheck import ( "github.com/jingyugao/rowserrcheck/passes/rowserr" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -10,16 +9,13 @@ import ( func New(settings *config.RowsErrCheckSettings) *goanalysis.Linter { var pkgs []string + if settings != nil { pkgs = settings.Packages } - a := rowserr.NewAnalyzer(pkgs...) - - return goanalysis.NewLinter( - a.Name, - "checks whether Rows.Err of rows is checked successfully", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(rowserr.NewAnalyzer(pkgs...)). + WithDesc("checks whether Rows.Err of rows is checked successfully"). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/sloglint/sloglint.go b/pkg/golinters/sloglint/sloglint.go index 021157dd66b7..891f1fcfdbdf 100644 --- a/pkg/golinters/sloglint/sloglint.go +++ b/pkg/golinters/sloglint/sloglint.go @@ -2,7 +2,6 @@ package sloglint import ( "go-simpler.org/sloglint" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -10,6 +9,7 @@ import ( func New(settings *config.SlogLintSettings) *goanalysis.Linter { var opts *sloglint.Options + if settings != nil { opts = &sloglint.Options{ NoMixedArgs: settings.NoMixedArgs, @@ -26,9 +26,7 @@ func New(settings *config.SlogLintSettings) *goanalysis.Linter { } } - a := sloglint.New(opts) - return goanalysis. - NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil). + NewLinterFromAnalyzer(sloglint.New(opts)). WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/spancheck/spancheck.go b/pkg/golinters/spancheck/spancheck.go index 264623058b1e..345c36277447 100644 --- a/pkg/golinters/spancheck/spancheck.go +++ b/pkg/golinters/spancheck/spancheck.go @@ -2,7 +2,6 @@ package spancheck import ( "github.com/jjti/go-spancheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -25,9 +24,7 @@ func New(settings *config.SpancheckSettings) *goanalysis.Linter { } } - a := spancheck.NewAnalyzerWithConfig(cfg) - return goanalysis. - NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil). + NewLinterFromAnalyzer(spancheck.NewAnalyzerWithConfig(cfg)). WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/spancheck/testdata/go.mod b/pkg/golinters/spancheck/testdata/go.mod index df3444491ace..256ae9e1b2a9 100644 --- a/pkg/golinters/spancheck/testdata/go.mod +++ b/pkg/golinters/spancheck/testdata/go.mod @@ -3,13 +3,13 @@ module spancheck go 1.23.0 require ( - go.opentelemetry.io/otel v1.35.0 - go.opentelemetry.io/otel/trace v1.35.0 + go.opentelemetry.io/otel v1.36.0 + go.opentelemetry.io/otel/trace v1.36.0 ) require ( - github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect - go.opentelemetry.io/otel/metric v1.35.0 // indirect + go.opentelemetry.io/otel/metric v1.36.0 // indirect ) diff --git a/pkg/golinters/spancheck/testdata/go.sum b/pkg/golinters/spancheck/testdata/go.sum index 98e72be93493..da8e1100881e 100644 --- a/pkg/golinters/spancheck/testdata/go.sum +++ b/pkg/golinters/spancheck/testdata/go.sum @@ -1,8 +1,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -13,11 +13,11 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= -go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= -go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= -go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= -go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= -go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= +go.opentelemetry.io/otel v1.36.0 h1:UumtzIklRBY6cI/lllNZlALOF5nNIzJVb16APdvgTXg= +go.opentelemetry.io/otel v1.36.0/go.mod h1:/TcFMXYjyRNh8khOAO9ybYkqaDBb/70aVwkNML4pP8E= +go.opentelemetry.io/otel/metric v1.36.0 h1:MoWPKVhQvJ+eeXWHFBOPoBOi20jh6Iq2CcCREuTYufE= +go.opentelemetry.io/otel/metric v1.36.0/go.mod h1:zC7Ks+yeyJt4xig9DEw9kuUFe5C3zLbVjV2PzT6qzbs= +go.opentelemetry.io/otel/trace v1.36.0 h1:ahxWNuqZjpdiFAyrIoQ4GIiAIhxAunQR6MUoKrsNd4w= +go.opentelemetry.io/otel/trace v1.36.0/go.mod h1:gQ+OnDZzrybY4k4seLzPAWNwVBBVlF2szhehOBB/tGA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/golinters/sqlclosecheck/sqlclosecheck.go b/pkg/golinters/sqlclosecheck/sqlclosecheck.go index 7f7e70c71401..4c970cc5295d 100644 --- a/pkg/golinters/sqlclosecheck/sqlclosecheck.go +++ b/pkg/golinters/sqlclosecheck/sqlclosecheck.go @@ -2,18 +2,12 @@ package sqlclosecheck import ( "github.com/ryanrolds/sqlclosecheck/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := analyzer.NewAnalyzer() - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/staticcheck/staticcheck.go b/pkg/golinters/staticcheck/staticcheck.go index 1ec39244c100..7aae52870cbb 100644 --- a/pkg/golinters/staticcheck/staticcheck.go +++ b/pkg/golinters/staticcheck/staticcheck.go @@ -15,6 +15,12 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" + "github.com/golangci/golangci-lint/v2/pkg/logutils" +) + +var ( + debugf = logutils.Debug(logutils.DebugKeyStaticcheck) + isDebug = logutils.HaveDebugTag(logutils.DebugKeyStaticcheck) ) func New(settings *config.StaticCheckSettings) *goanalysis.Linter { @@ -29,6 +35,21 @@ func New(settings *config.StaticCheckSettings) *goanalysis.Linter { analyzers := setupAnalyzers(allAnalyzers, cfg.Checks) + if isDebug { + allAnalyzerNames := extractAnalyzerNames(allAnalyzers) + slices.Sort(allAnalyzerNames) + debugf("All available checks (%d): %s", len(allAnalyzers), strings.Join(allAnalyzerNames, ",")) + + var cfgAnalyzerNames []string + for _, a := range analyzers { + cfgAnalyzerNames = append(cfgAnalyzerNames, a.Name) + } + slices.Sort(cfgAnalyzerNames) + debugf("Enabled by config checks (%d): %s", len(analyzers), strings.Join(cfgAnalyzerNames, ",")) + + debugf("staticcheck configuration: %#v", cfg) + } + return goanalysis.NewLinter( "staticcheck", "It's the set of rules from staticcheck.", @@ -107,12 +128,7 @@ func normalizeList(list []string) []string { } func setupAnalyzers(src []*lint.Analyzer, checks []string) []*analysis.Analyzer { - var names []string - for _, a := range src { - names = append(names, a.Analyzer.Name) - } - - filter := filterAnalyzerNames(names, checks) + filter := filterAnalyzerNames(extractAnalyzerNames(src), checks) var ret []*analysis.Analyzer for _, a := range src { @@ -124,6 +140,14 @@ func setupAnalyzers(src []*lint.Analyzer, checks []string) []*analysis.Analyzer return ret } +func extractAnalyzerNames(analyzers []*lint.Analyzer) []string { + var names []string + for _, a := range analyzers { + names = append(names, a.Analyzer.Name) + } + return names +} + // https://github.com/dominikh/go-tools/blob/9bf17c0388a65710524ba04c2d821469e639fdc2/lintcmd/lint.go#L437-L477 // //nolint:gocritic // Keep the original source code. diff --git a/pkg/golinters/swaggo/swaggo.go b/pkg/golinters/swaggo/swaggo.go new file mode 100644 index 000000000000..98f7a6bef4dc --- /dev/null +++ b/pkg/golinters/swaggo/swaggo.go @@ -0,0 +1,20 @@ +package swaggo + +import ( + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" + "github.com/golangci/golangci-lint/v2/pkg/goformatters" + "github.com/golangci/golangci-lint/v2/pkg/goformatters/swaggo" + "github.com/golangci/golangci-lint/v2/pkg/golinters/internal" +) + +func New() *goanalysis.Linter { + return goanalysis. + NewLinterFromAnalyzer( + goformatters.NewAnalyzer( + internal.LinterLogger.Child(swaggo.Name), + "Check if swaggo comments are formatted", + swaggo.New(), + ), + ). + WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/pkg/golinters/swaggo/swaggo_integration_test.go b/pkg/golinters/swaggo/swaggo_integration_test.go new file mode 100644 index 000000000000..23fd3f1ff788 --- /dev/null +++ b/pkg/golinters/swaggo/swaggo_integration_test.go @@ -0,0 +1,19 @@ +package swaggo + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} + +func TestFix(t *testing.T) { + integration.RunFix(t) +} + +func TestFixPathPrefix(t *testing.T) { + integration.RunFixPathPrefix(t) +} diff --git a/pkg/golinters/swaggo/testdata/fix/in/swaggo.go b/pkg/golinters/swaggo/testdata/fix/in/swaggo.go new file mode 100644 index 000000000000..33c814b2805b --- /dev/null +++ b/pkg/golinters/swaggo/testdata/fix/in/swaggo.go @@ -0,0 +1,18 @@ +//golangcitest:config_path testdata/swaggo.yml +//golangcitest:expected_exitcode 0 +package api + +import "net/http" + +// @Summary Add a new pet to the store +// @Description get string by ID +// @ID get-string-by-int +// @Accept json +// @Produce json +// @Param some_id path int true "Some ID" Format(int64) +// @Param some_id body web.Pet true "Some ID" +// @Success 200 {string} string "ok" +// @Failure 400 {object} web.APIError "We need ID!!" +// @Failure 404 {object} web.APIError "Can not find ID" +// @Router /testapi/get-string-by-int/{some_id} [get] +func GetStringByInt(w http.ResponseWriter, r *http.Request) {} diff --git a/pkg/golinters/swaggo/testdata/fix/out/swaggo.go b/pkg/golinters/swaggo/testdata/fix/out/swaggo.go new file mode 100644 index 000000000000..8c4d2a2cdd40 --- /dev/null +++ b/pkg/golinters/swaggo/testdata/fix/out/swaggo.go @@ -0,0 +1,18 @@ +//golangcitest:config_path testdata/swaggo.yml +//golangcitest:expected_exitcode 0 +package api + +import "net/http" + +// @Summary Add a new pet to the store +// @Description get string by ID +// @ID get-string-by-int +// @Accept json +// @Produce json +// @Param some_id path int true "Some ID" Format(int64) +// @Param some_id body web.Pet true "Some ID" +// @Success 200 {string} string "ok" +// @Failure 400 {object} web.APIError "We need ID!!" +// @Failure 404 {object} web.APIError "Can not find ID" +// @Router /testapi/get-string-by-int/{some_id} [get] +func GetStringByInt(w http.ResponseWriter, r *http.Request) {} diff --git a/pkg/golinters/swaggo/testdata/swaggo.go b/pkg/golinters/swaggo/testdata/swaggo.go new file mode 100644 index 000000000000..db6b7da9dcfc --- /dev/null +++ b/pkg/golinters/swaggo/testdata/swaggo.go @@ -0,0 +1,18 @@ +//golangcitest:config_path testdata/swaggo.yml +package api + +import "net/http" + +// want +1 "File is not properly formatted" +// @Summary Add a new pet to the store +// @Description get string by ID +// @ID get-string-by-int +// @Accept json +// @Produce json +// @Param some_id path int true "Some ID" Format(int64) +// @Param some_id body web.Pet true "Some ID" +// @Success 200 {string} string "ok" +// @Failure 400 {object} web.APIError "We need ID!!" +// @Failure 404 {object} web.APIError "Can not find ID" +// @Router /testapi/get-string-by-int/{some_id} [get] +func GetStringByInt(w http.ResponseWriter, r *http.Request) {} diff --git a/pkg/golinters/swaggo/testdata/swaggo.yml b/pkg/golinters/swaggo/testdata/swaggo.yml new file mode 100644 index 000000000000..458e2fca7eeb --- /dev/null +++ b/pkg/golinters/swaggo/testdata/swaggo.yml @@ -0,0 +1,5 @@ +version: "2" + +formatters: + enable: + - swaggo diff --git a/pkg/golinters/tagalign/tagalign.go b/pkg/golinters/tagalign/tagalign.go index 412d69b937ef..eba51311c0cf 100644 --- a/pkg/golinters/tagalign/tagalign.go +++ b/pkg/golinters/tagalign/tagalign.go @@ -2,7 +2,6 @@ package tagalign import ( "github.com/4meepo/tagalign" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -24,12 +23,7 @@ func New(settings *config.TagAlignSettings) *goanalysis.Linter { } } - analyzer := tagalign.NewAnalyzer(options...) - - return goanalysis.NewLinter( - analyzer.Name, - analyzer.Doc, - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(tagalign.NewAnalyzer(options...)). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/tagliatelle/tagliatelle.go b/pkg/golinters/tagliatelle/tagliatelle.go index f6357e0e3747..e12cc9e82062 100644 --- a/pkg/golinters/tagliatelle/tagliatelle.go +++ b/pkg/golinters/tagliatelle/tagliatelle.go @@ -1,8 +1,9 @@ package tagliatelle import ( + "maps" + "github.com/ldez/tagliatelle" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -20,9 +21,7 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter { } if settings != nil { - for k, v := range settings.Case.Rules { - cfg.Rules[k] = v - } + maps.Copy(cfg.Rules, settings.Case.Rules) cfg.ExtendedRules = toExtendedRules(settings.Case.ExtendedRules) cfg.UseFieldName = settings.Case.UseFieldName @@ -42,14 +41,9 @@ func New(settings *config.TagliatelleSettings) *goanalysis.Linter { } } - a := tagliatelle.New(cfg) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(tagliatelle.New(cfg)). + WithLoadMode(goanalysis.LoadModeTypesInfo) } func toExtendedRules(src map[string]config.TagliatelleExtendedRule) map[string]tagliatelle.ExtendedRule { diff --git a/pkg/golinters/testableexamples/testableexamples.go b/pkg/golinters/testableexamples/testableexamples.go index 38334a096237..45fdc900e2c3 100644 --- a/pkg/golinters/testableexamples/testableexamples.go +++ b/pkg/golinters/testableexamples/testableexamples.go @@ -2,18 +2,12 @@ package testableexamples import ( "github.com/maratori/testableexamples/pkg/testableexamples" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := testableexamples.NewAnalyzer() - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(testableexamples.NewAnalyzer()). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/testifylint/testifylint.go b/pkg/golinters/testifylint/testifylint.go index b19471c1ea05..bb5eac0e451e 100644 --- a/pkg/golinters/testifylint/testifylint.go +++ b/pkg/golinters/testifylint/testifylint.go @@ -2,18 +2,16 @@ package testifylint import ( "github.com/Antonboom/testifylint/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.TestifylintSettings) *goanalysis.Linter { - a := analyzer.New() + var cfg map[string]any - cfg := make(map[string]map[string]any) if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "enable-all": settings.EnableAll, "disable-all": settings.DisableAll, @@ -23,30 +21,28 @@ func New(settings *config.TestifylintSettings) *goanalysis.Linter { "go-require.ignore-http-handlers": settings.GoRequire.IgnoreHTTPHandlers, } if len(settings.EnabledCheckers) > 0 { - cfg[a.Name]["enable"] = settings.EnabledCheckers + cfg["enable"] = settings.EnabledCheckers } if len(settings.DisabledCheckers) > 0 { - cfg[a.Name]["disable"] = settings.DisabledCheckers + cfg["disable"] = settings.DisabledCheckers } if b := settings.Formatter.CheckFormatString; b != nil { - cfg[a.Name]["formatter.check-format-string"] = *b + cfg["formatter.check-format-string"] = *b } if p := settings.ExpectedActual.ExpVarPattern; p != "" { - cfg[a.Name]["expected-actual.pattern"] = p + cfg["expected-actual.pattern"] = p } if p := settings.RequireError.FnPattern; p != "" { - cfg[a.Name]["require-error.fn-pattern"] = p + cfg["require-error.fn-pattern"] = p } if m := settings.SuiteExtraAssertCall.Mode; m != "" { - cfg[a.Name]["suite-extra-assert-call.mode"] = m + cfg["suite-extra-assert-call.mode"] = m } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.New()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/testpackage/testpackage.go b/pkg/golinters/testpackage/testpackage.go index ddd5ce95cd15..39c333f1b56d 100644 --- a/pkg/golinters/testpackage/testpackage.go +++ b/pkg/golinters/testpackage/testpackage.go @@ -4,25 +4,23 @@ import ( "strings" "github.com/maratori/testpackage/pkg/testpackage" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.TestpackageSettings) *goanalysis.Linter { - a := testpackage.NewAnalyzer() + var cfg map[string]any - var cfg map[string]map[string]any if settings != nil { - cfg = map[string]map[string]any{ - a.Name: { - testpackage.SkipRegexpFlagName: settings.SkipRegexp, - testpackage.AllowPackagesFlagName: strings.Join(settings.AllowPackages, ","), - }, + cfg = map[string]any{ + testpackage.SkipRegexpFlagName: settings.SkipRegexp, + testpackage.AllowPackagesFlagName: strings.Join(settings.AllowPackages, ","), } } - return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, cfg). + return goanalysis. + NewLinterFromAnalyzer(testpackage.NewAnalyzer()). + WithConfig(cfg). WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/thelper/thelper.go b/pkg/golinters/thelper/thelper.go index d9058582d83c..77090c5f8b15 100644 --- a/pkg/golinters/thelper/thelper.go +++ b/pkg/golinters/thelper/thelper.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/kulti/thelper/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -14,8 +13,6 @@ import ( ) func New(settings *config.ThelperSettings) *goanalysis.Linter { - a := analyzer.NewAnalyzer() - opts := map[string]struct{}{ "t_name": {}, "t_begin": {}, @@ -47,18 +44,14 @@ func New(settings *config.ThelperSettings) *goanalysis.Linter { args := slices.Collect(maps.Keys(opts)) - cfg := map[string]map[string]any{ - a.Name: { - "checks": strings.Join(args, ","), - }, + cfg := map[string]any{ + "checks": strings.Join(args, ","), } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(analyzer.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } func applyTHelperOptions(o config.ThelperOptions, prefix string, opts map[string]struct{}) { diff --git a/pkg/golinters/tparallel/tparallel.go b/pkg/golinters/tparallel/tparallel.go index f3ce2fcf7975..480ef3b1e92b 100644 --- a/pkg/golinters/tparallel/tparallel.go +++ b/pkg/golinters/tparallel/tparallel.go @@ -2,17 +2,12 @@ package tparallel import ( "github.com/moricho/tparallel" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := tparallel.Analyzer - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(tparallel.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/typecheck.go b/pkg/golinters/typecheck.go index ad51e8d00f90..db29f7c18394 100644 --- a/pkg/golinters/typecheck.go +++ b/pkg/golinters/typecheck.go @@ -7,18 +7,11 @@ import ( ) func NewTypecheck() *goanalysis.Linter { - const linterName = "typecheck" - - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: goanalysis.DummyRun, - } - - return goanalysis.NewLinter( - linterName, - "Like the front-end of a Go compiler, parses and type-checks Go code", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeNone) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "typecheck", + Doc: "Like the front-end of a Go compiler, parses and type-checks Go code", + Run: goanalysis.DummyRun, + }). + WithLoadMode(goanalysis.LoadModeNone) } diff --git a/pkg/golinters/unconvert/unconvert.go b/pkg/golinters/unconvert/unconvert.go index d48cf5175ad4..593dfbe96e63 100644 --- a/pkg/golinters/unconvert/unconvert.go +++ b/pkg/golinters/unconvert/unconvert.go @@ -16,43 +16,39 @@ const linterName = "unconvert" func New(settings *config.UnconvertSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue unconvert.SetFastMath(settings.FastMath) unconvert.SetSafe(settings.Safe) - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Run: func(pass *analysis.Pass) (any, error) { - issues := runUnconvert(pass) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: linterName, + Doc: "Remove unnecessary type conversions", + Run: func(pass *analysis.Pass) (any, error) { + issues := runUnconvert(pass) - if len(issues) == 0 { - return nil, nil - } - - mu.Lock() - resIssues = append(resIssues, issues...) - mu.Unlock() + if len(issues) == 0 { + return nil, nil + } - return nil, nil - }, - } + mu.Lock() + resIssues = append(resIssues, issues...) + mu.Unlock() - return goanalysis.NewLinter( - linterName, - "Remove unnecessary type conversions", - []*analysis.Analyzer{analyzer}, - nil, - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { - return resIssues - }).WithLoadMode(goanalysis.LoadModeTypesInfo) + return nil, nil + }, + }). + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { + return resIssues + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runUnconvert(pass *analysis.Pass) []goanalysis.Issue { +func runUnconvert(pass *analysis.Pass) []*goanalysis.Issue { positions := unconvert.Run(pass) - var issues []goanalysis.Issue + var issues []*goanalysis.Issue for _, position := range positions { issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: position, diff --git a/pkg/golinters/unparam/unparam.go b/pkg/golinters/unparam/unparam.go index 5a9bc8a5e473..b6cb2668b076 100644 --- a/pkg/golinters/unparam/unparam.go +++ b/pkg/golinters/unparam/unparam.go @@ -10,29 +10,22 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) -const linterName = "unparam" - func New(settings *config.UnparamSettings) *goanalysis.Linter { - analyzer := &analysis.Analyzer{ - Name: linterName, - Doc: goanalysis.TheOnlyanalyzerDoc, - Requires: []*analysis.Analyzer{buildssa.Analyzer}, - Run: func(pass *analysis.Pass) (any, error) { - err := runUnparam(pass, settings) - if err != nil { - return nil, err - } - - return nil, nil - }, - } - - return goanalysis.NewLinter( - linterName, - "Reports unused function parameters", - []*analysis.Analyzer{analyzer}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(&analysis.Analyzer{ + Name: "unparam", + Doc: "Reports unused function parameters", + Requires: []*analysis.Analyzer{buildssa.Analyzer}, + Run: func(pass *analysis.Pass) (any, error) { + err := runUnparam(pass, settings) + if err != nil { + return nil, err + } + + return nil, nil + }, + }). + WithLoadMode(goanalysis.LoadModeTypesInfo) } func runUnparam(pass *analysis.Pass, settings *config.UnparamSettings) error { diff --git a/pkg/golinters/unused/unused.go b/pkg/golinters/unused/unused.go index 375962259676..c0f4657dcc26 100644 --- a/pkg/golinters/unused/unused.go +++ b/pkg/golinters/unused/unused.go @@ -20,7 +20,7 @@ const linterName = "unused" func New(settings *config.UnusedSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue analyzer := &analysis.Analyzer{ Name: linterName, @@ -45,12 +45,12 @@ func New(settings *config.UnusedSettings) *goanalysis.Linter { "Checks Go code for unused constants, variables, functions and types", []*analysis.Analyzer{analyzer}, nil, - ).WithIssuesReporter(func(_ *linter.Context) []goanalysis.Issue { + ).WithIssuesReporter(func(_ *linter.Context) []*goanalysis.Issue { return resIssues }).WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runUnused(pass *analysis.Pass, cfg *config.UnusedSettings) []goanalysis.Issue { +func runUnused(pass *analysis.Pass, cfg *config.UnusedSettings) []*goanalysis.Issue { res := getUnusedResults(pass, cfg) used := make(map[string]bool) @@ -58,7 +58,7 @@ func runUnused(pass *analysis.Pass, cfg *config.UnusedSettings) []goanalysis.Iss used[fmt.Sprintf("%s %d %s", obj.Position.Filename, obj.Position.Line, obj.Name)] = true } - var issues []goanalysis.Issue + var issues []*goanalysis.Issue // Inspired by https://github.com/dominikh/go-tools/blob/d694aadcb1f50c2d8ac0a1dd06217ebb9f654764/lintcmd/lint.go#L177-L197 for _, object := range res.Unused { diff --git a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go index 14f4a93a6b3c..9eee473f0d6d 100644 --- a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go +++ b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.go @@ -2,7 +2,10 @@ //golangcitest:config_path testdata/usestdlibvars_non_default.yml package testdata -import "net/http" +import ( + "net/http" + "time" +) func _200() { _ = 200 @@ -52,3 +55,8 @@ const ( _ = "ECDSAWithP256AndSHA256" // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)` _ = "ECDSAWithP384AndSHA384" // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)` ) + +func _() { + var _ = time.Date(2023, 1, 2, 3, 4, 5, 0, time.UTC) // want `"1" can be replaced by time\.January` + var _ = time.Date(2023, 10, 2, 3, 4, 5, 0, time.UTC) // want `"10" can be replaced by time\.October` +} diff --git a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml index 8100af59cdb1..d2942621daee 100644 --- a/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml +++ b/pkg/golinters/usestdlibvars/testdata/usestdlibvars_non_default.yml @@ -13,3 +13,4 @@ linters: sql-isolation-level: true tls-signature-scheme: true constant-kind: true + time-date-month: true diff --git a/pkg/golinters/usestdlibvars/usestdlibvars.go b/pkg/golinters/usestdlibvars/usestdlibvars.go index f0b5f5420d00..e4a900ff6465 100644 --- a/pkg/golinters/usestdlibvars/usestdlibvars.go +++ b/pkg/golinters/usestdlibvars/usestdlibvars.go @@ -2,18 +2,16 @@ package usestdlibvars import ( "github.com/sashamelentyev/usestdlibvars/pkg/analyzer" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.UseStdlibVarsSettings) *goanalysis.Linter { - a := analyzer.New() + var cfg map[string]any - cfg := make(map[string]map[string]any) if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ analyzer.ConstantKindFlag: settings.ConstantKind, analyzer.CryptoHashFlag: settings.CryptoHash, analyzer.HTTPMethodFlag: settings.HTTPMethod, @@ -26,13 +24,12 @@ func New(settings *config.UseStdlibVarsSettings) *goanalysis.Linter { analyzer.TimeMonthFlag: settings.TimeMonth, analyzer.TimeWeekdayFlag: settings.TimeWeekday, analyzer.TLSSignatureSchemeFlag: settings.TLSSignatureScheme, + analyzer.TimeDateMonthFlag: settings.TimeDateMonth, } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(analyzer.New()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/usetesting/usetesting.go b/pkg/golinters/usetesting/usetesting.go index 5dfa9f11ad54..7371cc28eb01 100644 --- a/pkg/golinters/usetesting/usetesting.go +++ b/pkg/golinters/usetesting/usetesting.go @@ -2,18 +2,16 @@ package usetesting import ( "github.com/ldez/usetesting" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.UseTestingSettings) *goanalysis.Linter { - a := usetesting.NewAnalyzer() + var cfg map[string]any - cfg := make(map[string]map[string]any) if settings != nil { - cfg[a.Name] = map[string]any{ + cfg = map[string]any{ "contextbackground": settings.ContextBackground, "contexttodo": settings.ContextTodo, "oschdir": settings.OSChdir, @@ -24,10 +22,8 @@ func New(settings *config.UseTestingSettings) *goanalysis.Linter { } } - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(usetesting.NewAnalyzer()). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/varnamelen/varnamelen.go b/pkg/golinters/varnamelen/varnamelen.go index dbd8005ee0d1..a19d7987ddcd 100644 --- a/pkg/golinters/varnamelen/varnamelen.go +++ b/pkg/golinters/varnamelen/varnamelen.go @@ -5,15 +5,13 @@ import ( "strings" "github.com/blizzy78/varnamelen" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New(settings *config.VarnamelenSettings) *goanalysis.Linter { - analyzer := varnamelen.NewAnalyzer() - cfg := map[string]map[string]any{} + var cfg map[string]any if settings != nil { vnlCfg := map[string]any{ @@ -30,17 +28,15 @@ func New(settings *config.VarnamelenSettings) *goanalysis.Linter { if settings.MaxDistance > 0 { vnlCfg["maxDistance"] = strconv.Itoa(settings.MaxDistance) } + if settings.MinNameLength > 0 { vnlCfg["minNameLength"] = strconv.Itoa(settings.MinNameLength) } - - cfg[analyzer.Name] = vnlCfg } - return goanalysis.NewLinter( - analyzer.Name, - "checks that the length of a variable's name matches its scope", - []*analysis.Analyzer{analyzer}, - cfg, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(varnamelen.NewAnalyzer()). + WithDesc("checks that the length of a variable's name matches its scope"). + WithConfig(cfg). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/wastedassign/wastedassign.go b/pkg/golinters/wastedassign/wastedassign.go index 6599f7d4dace..d103a8d5a55b 100644 --- a/pkg/golinters/wastedassign/wastedassign.go +++ b/pkg/golinters/wastedassign/wastedassign.go @@ -2,18 +2,13 @@ package wastedassign import ( "github.com/sanposhiho/wastedassign/v2" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := wastedassign.Analyzer - - return goanalysis.NewLinter( - a.Name, - "Finds wasted assignment statements", - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(wastedassign.Analyzer). + WithDesc("Finds wasted assignment statements"). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/whitespace/whitespace.go b/pkg/golinters/whitespace/whitespace.go index cd7fda1ce0d0..bf03e1d8088b 100644 --- a/pkg/golinters/whitespace/whitespace.go +++ b/pkg/golinters/whitespace/whitespace.go @@ -2,7 +2,6 @@ package whitespace import ( "github.com/ultraware/whitespace" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -17,12 +16,7 @@ func New(settings *config.WhitespaceSettings) *goanalysis.Linter { } } - a := whitespace.NewAnalyzer(&wsSettings) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(whitespace.NewAnalyzer(&wsSettings)). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/wrapcheck/wrapcheck.go b/pkg/golinters/wrapcheck/wrapcheck.go index 8a4427f7d368..c29c509a80fd 100644 --- a/pkg/golinters/wrapcheck/wrapcheck.go +++ b/pkg/golinters/wrapcheck/wrapcheck.go @@ -2,7 +2,6 @@ package wrapcheck import ( "github.com/tomarrell/wrapcheck/v2/wrapcheck" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -29,12 +28,7 @@ func New(settings *config.WrapcheckSettings) *goanalysis.Linter { } } - a := wrapcheck.NewAnalyzer(cfg) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(wrapcheck.NewAnalyzer(cfg)). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/golinters/wsl/wsl.go b/pkg/golinters/wsl/wsl.go index 12148627eb5b..c71706f5c1d3 100644 --- a/pkg/golinters/wsl/wsl.go +++ b/pkg/golinters/wsl/wsl.go @@ -2,7 +2,6 @@ package wsl import ( "github.com/bombsimon/wsl/v4" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" @@ -10,6 +9,7 @@ import ( func New(settings *config.WSLSettings) *goanalysis.Linter { var conf *wsl.Configuration + if settings != nil { conf = &wsl.Configuration{ StrictAppend: settings.StrictAppend, @@ -30,12 +30,7 @@ func New(settings *config.WSLSettings) *goanalysis.Linter { } } - a := wsl.NewAnalyzer(conf) - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeSyntax) + return goanalysis. + NewLinterFromAnalyzer(wsl.NewAnalyzer(conf)). + WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/golinters/zerologlint/testdata/go.mod b/pkg/golinters/zerologlint/testdata/go.mod index 42508c71c705..6e255ef19b13 100644 --- a/pkg/golinters/zerologlint/testdata/go.mod +++ b/pkg/golinters/zerologlint/testdata/go.mod @@ -7,5 +7,5 @@ require github.com/rs/zerolog v1.34.0 require ( github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - golang.org/x/sys v0.31.0 // indirect + golang.org/x/sys v0.33.0 // indirect ) diff --git a/pkg/golinters/zerologlint/testdata/go.sum b/pkg/golinters/zerologlint/testdata/go.sum index 4c01b0c5ed90..3b0d10eedda7 100644 --- a/pkg/golinters/zerologlint/testdata/go.sum +++ b/pkg/golinters/zerologlint/testdata/go.sum @@ -14,5 +14,5 @@ github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= diff --git a/pkg/golinters/zerologlint/zerologlint.go b/pkg/golinters/zerologlint/zerologlint.go index 0daf0d48a4d6..46832da96c8b 100644 --- a/pkg/golinters/zerologlint/zerologlint.go +++ b/pkg/golinters/zerologlint/zerologlint.go @@ -2,18 +2,12 @@ package zerologlint import ( "github.com/ykadowak/zerologlint" - "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" ) func New() *goanalysis.Linter { - a := zerologlint.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) + return goanalysis. + NewLinterFromAnalyzer(zerologlint.Analyzer). + WithLoadMode(goanalysis.LoadModeTypesInfo) } diff --git a/pkg/lint/linter/linter.go b/pkg/lint/linter/linter.go index 7f68545cf159..e6b484efbb05 100644 --- a/pkg/lint/linter/linter.go +++ b/pkg/lint/linter/linter.go @@ -8,7 +8,7 @@ import ( ) type Linter interface { - Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) + Run(ctx context.Context, lintCtx *Context) ([]*result.Issue, error) Name() string Desc() string } @@ -43,7 +43,7 @@ func NewNoopDeprecated(name string, cfg *config.Config, level DeprecationLevel) return noop } -func (n Noop) Run(_ context.Context, lintCtx *Context) ([]result.Issue, error) { +func (n Noop) Run(_ context.Context, lintCtx *Context) ([]*result.Issue, error) { if n.reason == "" { return nil, nil } diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 5ac3e5ba2fb0..734aab63cd1c 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -3,6 +3,7 @@ package lintersdb import ( "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/golinters" + "github.com/golangci/golangci-lint/v2/pkg/golinters/arangolint" "github.com/golangci/golangci-lint/v2/pkg/golinters/asasalint" "github.com/golangci/golangci-lint/v2/pkg/golinters/asciicheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/bidichk" @@ -18,6 +19,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/dupl" "github.com/golangci/golangci-lint/v2/pkg/golinters/dupword" "github.com/golangci/golangci-lint/v2/pkg/golinters/durationcheck" + "github.com/golangci/golangci-lint/v2/pkg/golinters/embeddedstructfieldcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/err113" "github.com/golangci/golangci-lint/v2/pkg/golinters/errcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/errchkjson" @@ -77,6 +79,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/nilnil" "github.com/golangci/golangci-lint/v2/pkg/golinters/nlreturn" "github.com/golangci/golangci-lint/v2/pkg/golinters/noctx" + "github.com/golangci/golangci-lint/v2/pkg/golinters/noinlineerr" "github.com/golangci/golangci-lint/v2/pkg/golinters/nolintlint" "github.com/golangci/golangci-lint/v2/pkg/golinters/nonamedreturns" "github.com/golangci/golangci-lint/v2/pkg/golinters/nosprintfhostport" @@ -94,6 +97,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/spancheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/sqlclosecheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/staticcheck" + "github.com/golangci/golangci-lint/v2/pkg/golinters/swaggo" "github.com/golangci/golangci-lint/v2/pkg/golinters/tagalign" "github.com/golangci/golangci-lint/v2/pkg/golinters/tagliatelle" "github.com/golangci/golangci-lint/v2/pkg/golinters/testableexamples" @@ -135,6 +139,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { // The linters are sorted in the alphabetical order (case-insensitive). // When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint. return []*linter.Config{ + linter.NewConfig(arangolint.New()). + WithSince("v2.2.0"). + WithLoadForGoAnalysis(). + WithURL("https://github.com/Crocmagnon/arangolint"), + linter.NewConfig(asasalint.New(&cfg.Linters.Settings.Asasalint)). WithSince("v1.47.0"). WithLoadForGoAnalysis(). @@ -205,6 +214,10 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/charithe/durationcheck"), + linter.NewConfig(embeddedstructfieldcheck.New(&cfg.Linters.Settings.EmbeddedStructFieldCheck)). + WithSince("v2.2.0"). + WithURL("https://github.com/manuelarte/embeddedstructfieldcheck"), + linter.NewConfig(errcheck.New(&cfg.Linters.Settings.Errcheck)). WithGroups(config.GroupStandard). WithSince("v1.0.0"). @@ -499,6 +512,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/sonatard/noctx"), + linter.NewConfig(noinlineerr.New()). + WithSince("v2.2.0"). + WithLoadForGoAnalysis(). + WithURL("https://github.com/AlwxSin/noinlineerr"), + linter.NewConfig(nonamedreturns.New(&cfg.Linters.Settings.NoNamedReturns)). WithSince("v1.46.0"). WithLoadForGoAnalysis(). @@ -581,6 +599,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithAutoFix(). WithURL("https://staticcheck.dev/"), + linter.NewConfig(swaggo.New()). + WithSince("v2.2.0"). + WithAutoFix(). + WithURL("https://github.com/swaggo/swaggo"), + linter.NewConfig(tagalign.New(&cfg.Linters.Settings.TagAlign)). WithSince("v1.53.0"). WithAutoFix(). diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index 5ede9b24dae5..5cc46feb101d 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -118,17 +118,17 @@ func NewRunner(log logutils.Log, cfg *config.Config, goenv *goutil.Env, }, nil } -func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Issue, error) { +func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]*result.Issue, error) { sw := timeutils.NewStopwatch("linters", r.Log) defer sw.Print() var ( lintErrors error - issues []result.Issue + issues []*result.Issue ) for _, lc := range linters { - linterIssues, err := timeutils.TrackStage(sw, lc.Name(), func() ([]result.Issue, error) { + linterIssues, err := timeutils.TrackStage(sw, lc.Name(), func() ([]*result.Issue, error) { return r.runLinterSafe(ctx, r.lintCtx, lc) }) if err != nil { @@ -146,7 +146,7 @@ func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Is func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context, lc *linter.Config, -) (ret []result.Issue, err error) { +) (ret []*result.Issue, err error) { defer func() { if panicData := recover(); panicData != nil { if pe, ok := panicData.(*errorutil.PanicError); ok { @@ -185,13 +185,13 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context, return issues, nil } -func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue { +func (r *Runner) processLintResults(inIssues []*result.Issue) []*result.Issue { sw := timeutils.NewStopwatch("processing", r.Log) var issuesBefore, issuesAfter int statPerProcessor := map[string]processorStat{} - var outIssues []result.Issue + var outIssues []*result.Issue if len(inIssues) != 0 { issuesBefore += len(inIssues) outIssues = r.processIssues(inIssues, sw, statPerProcessor) @@ -225,9 +225,9 @@ func (r *Runner) printPerProcessorStat(stat map[string]processorStat) { } } -func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue { +func (r *Runner) processIssues(issues []*result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []*result.Issue { for _, p := range r.Processors { - newIssues, err := timeutils.TrackStage(sw, p.Name(), func() ([]result.Issue, error) { + newIssues, err := timeutils.TrackStage(sw, p.Name(), func() ([]*result.Issue, error) { return p.Process(issues) }) @@ -243,7 +243,7 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s // This is required by JSON serialization if issues == nil { - issues = []result.Issue{} + issues = []*result.Issue{} } } diff --git a/pkg/logutils/logutils.go b/pkg/logutils/logutils.go index 0ee48a3664bd..e417ac4b738d 100644 --- a/pkg/logutils/logutils.go +++ b/pkg/logutils/logutils.go @@ -79,11 +79,12 @@ const ( // Linters. const ( - DebugKeyForbidigo = "forbidigo" // Debugs `forbidigo` linter. - DebugKeyGoCritic = "gocritic" // Debugs `gocritic` linter. - DebugKeyGovet = "govet" // Debugs `govet` linter. - DebugKeyLinter = "linter" - DebugKeyRevive = "revive" // Debugs `revive` linter. + DebugKeyForbidigo = "forbidigo" // Debugs `forbidigo` linter. + DebugKeyGoCritic = "gocritic" // Debugs `gocritic` linter. + DebugKeyGovet = "govet" // Debugs `govet` linter. + DebugKeyLinter = "linter" + DebugKeyRevive = "revive" // Debugs `revive` linter. + DebugKeyStaticcheck = "staticcheck" // Debugs `staticcheck` linter. ) func getEnabledDebugs() map[string]bool { diff --git a/pkg/printers/checkstyle.go b/pkg/printers/checkstyle.go index 5a60554bdb62..c3869bd39d9d 100644 --- a/pkg/printers/checkstyle.go +++ b/pkg/printers/checkstyle.go @@ -37,15 +37,14 @@ func NewCheckstyle(log logutils.Log, w io.Writer) *Checkstyle { } } -func (p *Checkstyle) Print(issues []result.Issue) error { +func (p *Checkstyle) Print(issues []*result.Issue) error { out := checkstyleOutput{ Version: "5.0", } files := map[string]*checkstyleFile{} - for i := range issues { - issue := &issues[i] + for _, issue := range issues { file, ok := files[issue.FilePath()] if !ok { file = &checkstyleFile{ diff --git a/pkg/printers/checkstyle_test.go b/pkg/printers/checkstyle_test.go index f087a79b83b0..5c8781e388fb 100644 --- a/pkg/printers/checkstyle_test.go +++ b/pkg/printers/checkstyle_test.go @@ -14,7 +14,7 @@ import ( ) func TestCheckstyle_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/codeclimate.go b/pkg/printers/codeclimate.go index 872d860d3ba4..e2eded608fb9 100644 --- a/pkg/printers/codeclimate.go +++ b/pkg/printers/codeclimate.go @@ -30,12 +30,10 @@ func NewCodeClimate(log logutils.Log, w io.Writer) *CodeClimate { } } -func (p *CodeClimate) Print(issues []result.Issue) error { +func (p *CodeClimate) Print(issues []*result.Issue) error { ccIssues := make([]codeClimateIssue, 0, len(issues)) - for i := range issues { - issue := issues[i] - + for _, issue := range issues { ccIssue := codeClimateIssue{ Description: issue.Description(), CheckName: issue.FromLinter, diff --git a/pkg/printers/codeclimate_test.go b/pkg/printers/codeclimate_test.go index 28fd281c4548..159dd86e37ae 100644 --- a/pkg/printers/codeclimate_test.go +++ b/pkg/printers/codeclimate_test.go @@ -13,7 +13,7 @@ import ( ) func TestCodeClimate_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "minor", diff --git a/pkg/printers/html.go b/pkg/printers/html.go index 0f99bb7ff8ce..1f6ed18344b0 100644 --- a/pkg/printers/html.go +++ b/pkg/printers/html.go @@ -132,20 +132,20 @@ func NewHTML(w io.Writer) *HTML { return &HTML{w: w} } -func (p HTML) Print(issues []result.Issue) error { +func (p HTML) Print(issues []*result.Issue) error { var htmlIssues []htmlIssue - for i := range issues { - pos := fmt.Sprintf("%s:%d", issues[i].FilePath(), issues[i].Line()) - if issues[i].Pos.Column != 0 { - pos += fmt.Sprintf(":%d", issues[i].Pos.Column) + for _, issue := range issues { + pos := fmt.Sprintf("%s:%d", issue.FilePath(), issue.Line()) + if issue.Pos.Column != 0 { + pos += fmt.Sprintf(":%d", issue.Pos.Column) } htmlIssues = append(htmlIssues, htmlIssue{ - Title: strings.TrimSpace(issues[i].Text), + Title: strings.TrimSpace(issue.Text), Pos: pos, - Linter: issues[i].FromLinter, - Code: strings.Join(issues[i].SourceLines, "\n"), + Linter: issue.FromLinter, + Code: strings.Join(issue.SourceLines, "\n"), }) } diff --git a/pkg/printers/html_test.go b/pkg/printers/html_test.go index 3964d81ddeaf..17db307509c2 100644 --- a/pkg/printers/html_test.go +++ b/pkg/printers/html_test.go @@ -118,7 +118,7 @@ const expectedHTML = ` ` func TestHTML_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/json.go b/pkg/printers/json.go index 64fd33c7bae5..97354081c903 100644 --- a/pkg/printers/json.go +++ b/pkg/printers/json.go @@ -22,17 +22,17 @@ func NewJSON(w io.Writer, rd *report.Data) *JSON { } type JSONResult struct { - Issues []result.Issue + Issues []*result.Issue Report *report.Data } -func (p JSON) Print(issues []result.Issue) error { +func (p JSON) Print(issues []*result.Issue) error { res := JSONResult{ Issues: issues, Report: p.rd, } if res.Issues == nil { - res.Issues = []result.Issue{} + res.Issues = []*result.Issue{} } return json.NewEncoder(p.w).Encode(res) diff --git a/pkg/printers/json_test.go b/pkg/printers/json_test.go index 001c283ee611..50c67f995fe1 100644 --- a/pkg/printers/json_test.go +++ b/pkg/printers/json_test.go @@ -12,7 +12,7 @@ import ( ) func TestJSON_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/junitxml.go b/pkg/printers/junitxml.go index 708f83e5a860..b040e746703c 100644 --- a/pkg/printers/junitxml.go +++ b/pkg/printers/junitxml.go @@ -27,31 +27,30 @@ func NewJUnitXML(w io.Writer, extended bool) *JUnitXML { } } -func (p JUnitXML) Print(issues []result.Issue) error { +func (p JUnitXML) Print(issues []*result.Issue) error { suites := make(map[string]testSuiteXML) // use a map to group by file - for ind := range issues { - i := &issues[ind] - suiteName := i.FilePath() + for _, issue := range issues { + suiteName := issue.FilePath() testSuite := suites[suiteName] - testSuite.Suite = i.FilePath() + testSuite.Suite = issue.FilePath() testSuite.Tests++ testSuite.Failures++ tc := testCaseXML{ - Name: i.FromLinter, - ClassName: i.Pos.String(), + Name: issue.FromLinter, + ClassName: issue.Pos.String(), Failure: failureXML{ - Type: i.Severity, - Message: i.Pos.String() + ": " + i.Text, + Type: issue.Severity, + Message: issue.Pos.String() + ": " + issue.Text, Content: fmt.Sprintf("%s: %s\nCategory: %s\nFile: %s\nLine: %d\nDetails: %s", - i.Severity, i.Text, i.FromLinter, i.Pos.Filename, i.Pos.Line, strings.Join(i.SourceLines, "\n")), + issue.Severity, issue.Text, issue.FromLinter, issue.Pos.Filename, issue.Pos.Line, strings.Join(issue.SourceLines, "\n")), }, } if p.extended { - tc.File = i.Pos.Filename - tc.Line = i.Pos.Line + tc.File = issue.Pos.Filename + tc.Line = issue.Pos.Line } testSuite.TestCases = append(testSuite.TestCases, tc) diff --git a/pkg/printers/junitxml_test.go b/pkg/printers/junitxml_test.go index 7a429e546f46..90a365e79870 100644 --- a/pkg/printers/junitxml_test.go +++ b/pkg/printers/junitxml_test.go @@ -12,7 +12,7 @@ import ( ) func TestJUnitXML_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/printer.go b/pkg/printers/printer.go index 575bba75f1d5..bb3eab6205e8 100644 --- a/pkg/printers/printer.go +++ b/pkg/printers/printer.go @@ -23,7 +23,7 @@ const ( const defaultFileMode = 0o644 type issuePrinter interface { - Print(issues []result.Issue) error + Print(issues []*result.Issue) error } // Printer prints issues. @@ -63,7 +63,7 @@ func NewPrinter(log logutils.Log, cfg *config.Formats, reportData *report.Data, // Print prints issues based on the formats defined. // //nolint:gocyclo,funlen // the complexity is related to the number of formats. -func (c *Printer) Print(issues []result.Issue) error { +func (c *Printer) Print(issues []*result.Issue) error { if c.cfg.IsEmpty() { c.cfg.Text.Path = outputStdOut } diff --git a/pkg/printers/printer_test.go b/pkg/printers/printer_test.go index 850ee94a097b..6b3737f16688 100644 --- a/pkg/printers/printer_test.go +++ b/pkg/printers/printer_test.go @@ -29,7 +29,7 @@ func unmarshalFile(t *testing.T, filename string, v any) { func TestPrinter_Print_stdout(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} @@ -86,7 +86,7 @@ func TestPrinter_Print_stdout(t *testing.T) { func TestPrinter_Print_stderr(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} @@ -122,7 +122,7 @@ func TestPrinter_Print_stderr(t *testing.T) { func TestPrinter_Print_file(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} @@ -165,7 +165,7 @@ func TestPrinter_Print_file(t *testing.T) { func TestPrinter_Print_multiple(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} diff --git a/pkg/printers/sarif.go b/pkg/printers/sarif.go index e8d8c64f7da3..e1caf179a821 100644 --- a/pkg/printers/sarif.go +++ b/pkg/printers/sarif.go @@ -36,14 +36,12 @@ func NewSarif(log logutils.Log, w io.Writer) *Sarif { } } -func (p *Sarif) Print(issues []result.Issue) error { +func (p *Sarif) Print(issues []*result.Issue) error { run := sarifRun{} run.Tool.Driver.Name = "golangci-lint" run.Results = make([]sarifResult, 0) - for i := range issues { - issue := issues[i] - + for _, issue := range issues { sr := sarifResult{ RuleID: issue.FromLinter, Level: p.sanitizer.Sanitize(issue.Severity), diff --git a/pkg/printers/sarif_test.go b/pkg/printers/sarif_test.go index f6ddf4d81f07..400bb25bed37 100644 --- a/pkg/printers/sarif_test.go +++ b/pkg/printers/sarif_test.go @@ -13,7 +13,7 @@ import ( ) func TestSarif_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/tab.go b/pkg/printers/tab.go index 0d14593e5950..8edbb05e11fe 100644 --- a/pkg/printers/tab.go +++ b/pkg/printers/tab.go @@ -40,11 +40,11 @@ func (p *Tab) SprintfColored(ca color.Attribute, format string, args ...any) str return c.Sprintf(format, args...) } -func (p *Tab) Print(issues []result.Issue) error { +func (p *Tab) Print(issues []*result.Issue) error { w := tabwriter.NewWriter(p.w, 0, 0, 2, ' ', 0) - for i := range issues { - p.printIssue(&issues[i], w) + for _, issue := range issues { + p.printIssue(issue, w) } if err := w.Flush(); err != nil { diff --git a/pkg/printers/tab_test.go b/pkg/printers/tab_test.go index f8e47f84b2b1..1920334753e8 100644 --- a/pkg/printers/tab_test.go +++ b/pkg/printers/tab_test.go @@ -22,7 +22,7 @@ func TestTab_Print(t *testing.T) { }) color.NoColor = false - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/teamcity.go b/pkg/printers/teamcity.go index a85307729d05..36114fedfc57 100644 --- a/pkg/printers/teamcity.go +++ b/pkg/printers/teamcity.go @@ -48,12 +48,10 @@ func NewTeamCity(log logutils.Log, w io.Writer) *TeamCity { } } -func (p *TeamCity) Print(issues []result.Issue) error { +func (p *TeamCity) Print(issues []*result.Issue) error { uniqLinters := map[string]struct{}{} - for i := range issues { - issue := issues[i] - + for _, issue := range issues { _, ok := uniqLinters[issue.FromLinter] if !ok { inspectionType := InspectionType{ diff --git a/pkg/printers/teamcity_test.go b/pkg/printers/teamcity_test.go index eda415670273..121a0519eb48 100644 --- a/pkg/printers/teamcity_test.go +++ b/pkg/printers/teamcity_test.go @@ -13,7 +13,7 @@ import ( ) func TestTeamCity_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "WARNING", diff --git a/pkg/printers/text.go b/pkg/printers/text.go index 545679fb7b45..eb9297615be2 100644 --- a/pkg/printers/text.go +++ b/pkg/printers/text.go @@ -42,16 +42,16 @@ func (p *Text) SprintfColored(ca color.Attribute, format string, args ...any) st return c.Sprintf(format, args...) } -func (p *Text) Print(issues []result.Issue) error { - for i := range issues { - p.printIssue(&issues[i]) +func (p *Text) Print(issues []*result.Issue) error { + for _, issue := range issues { + p.printIssue(issue) if !p.printIssuedLine { continue } - p.printSourceCode(&issues[i]) - p.printUnderLinePointer(&issues[i]) + p.printSourceCode(issue) + p.printUnderLinePointer(issue) } return nil diff --git a/pkg/printers/text_test.go b/pkg/printers/text_test.go index 4a1c39483526..4aa784ee4457 100644 --- a/pkg/printers/text_test.go +++ b/pkg/printers/text_test.go @@ -22,7 +22,7 @@ func TestText_Print(t *testing.T) { }) color.NoColor = false - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/report/log.go b/pkg/report/log.go index ad096415123f..c964af559379 100644 --- a/pkg/report/log.go +++ b/pkg/report/log.go @@ -2,6 +2,7 @@ package report import ( "fmt" + "slices" "strings" "github.com/golangci/golangci-lint/v2/pkg/logutils" @@ -50,7 +51,7 @@ func (lw LogWrapper) Infof(format string, args ...any) { func (lw LogWrapper) Child(name string) logutils.Log { c := lw c.origLog = lw.origLog.Child(name) - c.tags = append([]string{}, lw.tags...) + c.tags = slices.Clone(lw.tags) c.tags = append(c.tags, name) return c } diff --git a/pkg/result/issue.go b/pkg/result/issue.go index 86a4ef3b7369..2587ffff2cc7 100644 --- a/pkg/result/issue.go +++ b/pkg/result/issue.go @@ -32,7 +32,7 @@ type Issue struct { // HunkPos is used only when golangci-lint is run over a diff HunkPos int `json:",omitempty"` - // If we know how to fix the issue we can provide replacement lines + // If we know how to fix the issue, we can provide replacement lines SuggestedFixes []analysis.SuggestedFix `json:",omitempty"` // If we are expecting a nolint (because this is from nolintlint), record the expected linter @@ -42,7 +42,7 @@ type Issue struct { // Only for Diff processor needs. WorkingDirectoryRelativePath string `json:"-"` - // Only for processor that need relative paths evaluation. + // Only for processors that need relative paths evaluation. RelativePath string `json:"-"` } diff --git a/pkg/result/processors/base_rule.go b/pkg/result/processors/base_rule.go index 607886ef1f39..46886624848a 100644 --- a/pkg/result/processors/base_rule.go +++ b/pkg/result/processors/base_rule.go @@ -2,6 +2,7 @@ package processors import ( "regexp" + "slices" "github.com/golangci/golangci-lint/v2/pkg/config" "github.com/golangci/golangci-lint/v2/pkg/fsutils" @@ -73,13 +74,7 @@ func (r *baseRule) match(issue *result.Issue, lines *fsutils.LineCache, log logu } func (r *baseRule) matchLinter(issue *result.Issue) bool { - for _, linter := range r.linters { - if linter == issue.FromLinter { - return true - } - } - - return false + return slices.Contains(r.linters, issue.FromLinter) } func (r *baseRule) matchSource(issue *result.Issue, lineCache *fsutils.LineCache, log logutils.Log) bool { diff --git a/pkg/result/processors/cgo.go b/pkg/result/processors/cgo.go index dea3801e2c8a..4cc7b57dbf05 100644 --- a/pkg/result/processors/cgo.go +++ b/pkg/result/processors/cgo.go @@ -31,7 +31,7 @@ func (*Cgo) Name() string { return "cgo" } -func (p *Cgo) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *Cgo) Process(issues []*result.Issue) ([]*result.Issue, error) { return filterIssuesErr(issues, p.shouldPassIssue) } diff --git a/pkg/result/processors/diff.go b/pkg/result/processors/diff.go index a84caf7b686a..15574ff0d374 100644 --- a/pkg/result/processors/diff.go +++ b/pkg/result/processors/diff.go @@ -48,7 +48,7 @@ func (*Diff) Name() string { return "diff" } -func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *Diff) Process(issues []*result.Issue) ([]*result.Issue, error) { if !p.onlyNew && p.fromRev == "" && p.fromMergeBase == "" && p.patchFilePath == "" && p.patch == "" { return issues, nil } diff --git a/pkg/result/processors/exclusion_generated_file_filter.go b/pkg/result/processors/exclusion_generated_file_filter.go index 6cbde3aedf58..d76ec3184f86 100644 --- a/pkg/result/processors/exclusion_generated_file_filter.go +++ b/pkg/result/processors/exclusion_generated_file_filter.go @@ -40,7 +40,7 @@ func (*GeneratedFileFilter) Name() string { return "generated_file_filter" } -func (p *GeneratedFileFilter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *GeneratedFileFilter) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.mode == config.GeneratedModeDisable { return issues, nil } diff --git a/pkg/result/processors/exclusion_paths.go b/pkg/result/processors/exclusion_paths.go index 104c33eefa5b..acf13edd0797 100644 --- a/pkg/result/processors/exclusion_paths.go +++ b/pkg/result/processors/exclusion_paths.go @@ -68,7 +68,7 @@ func (*ExclusionPaths) Name() string { return "exclusion_paths" } -func (p *ExclusionPaths) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *ExclusionPaths) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.pathPatterns) == 0 && len(p.pathExceptPatterns) == 0 { return issues, nil } @@ -114,5 +114,5 @@ func (p *ExclusionPaths) shouldPassIssue(issue *result.Issue) bool { matched = true } - return !matched + return matched } diff --git a/pkg/result/processors/exclusion_paths_test.go b/pkg/result/processors/exclusion_paths_test.go index 44e17d207d38..bfd19af13e65 100644 --- a/pkg/result/processors/exclusion_paths_test.go +++ b/pkg/result/processors/exclusion_paths_test.go @@ -19,22 +19,22 @@ func TestExclusionPaths_Process(t *testing.T) { testCases := []struct { desc string cfg *config.LinterExclusions - issues []result.Issue - expected []result.Issue + issues []*result.Issue + expected []*result.Issue }{ { desc: "paths: word", cfg: &config.LinterExclusions{ Paths: []string{"foo"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: "foo.go"}, {RelativePath: "foo/foo.go"}, {RelativePath: "foo/bar.go"}, {RelativePath: "bar/foo.go"}, {RelativePath: "bar/bar.go"}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: "bar/bar.go"}, }, }, @@ -43,14 +43,14 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ Paths: []string{"^foo"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("foo.go")}, {RelativePath: filepath.FromSlash("foo/foo.go")}, {RelativePath: filepath.FromSlash("foo/bar.go")}, {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, }, @@ -60,14 +60,14 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ Paths: []string{"^foo/"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("foo.go")}, {RelativePath: filepath.FromSlash("foo/foo.go")}, {RelativePath: filepath.FromSlash("foo/bar.go")}, {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("foo.go")}, {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, @@ -78,22 +78,22 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ Paths: []string{"c/d.go"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, {RelativePath: filepath.FromSlash("c/d.go")}, }, - expected: []result.Issue{}, + expected: []*result.Issue{}, }, { desc: "paths: same suffix with constrained expression", cfg: &config.LinterExclusions{ Paths: []string{"^c/d.go"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, {RelativePath: filepath.FromSlash("c/d.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, }, }, @@ -106,11 +106,11 @@ func TestExclusionPaths_Process(t *testing.T) { `^c/d.go`, }, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, {RelativePath: filepath.FromSlash("c/d.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, }, }, @@ -119,7 +119,7 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ PathsExcept: []string{`^base/c/.*$`}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -127,10 +127,10 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ - {RelativePath: filepath.FromSlash("base/a/file.go")}, - {RelativePath: filepath.FromSlash("base/b/file.go")}, - {RelativePath: filepath.FromSlash("base/d/file.go")}, + expected: []*result.Issue{ + {RelativePath: filepath.FromSlash("base/c/file.go")}, + {RelativePath: filepath.FromSlash("base/c/a/file.go")}, + {RelativePath: filepath.FromSlash("base/c/b/file.go")}, }, }, { @@ -142,7 +142,7 @@ func TestExclusionPaths_Process(t *testing.T) { `^base/c/.*$`, }, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -150,10 +150,10 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ - {RelativePath: filepath.FromSlash("base/a/file.go")}, - {RelativePath: filepath.FromSlash("base/b/file.go")}, - {RelativePath: filepath.FromSlash("base/d/file.go")}, + expected: []*result.Issue{ + {RelativePath: filepath.FromSlash("base/c/file.go")}, + {RelativePath: filepath.FromSlash("base/c/a/file.go")}, + {RelativePath: filepath.FromSlash("base/c/b/file.go")}, }, }, { @@ -164,7 +164,7 @@ func TestExclusionPaths_Process(t *testing.T) { `^base/c/.*$`, }, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -173,19 +173,20 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/d/file.go")}, {RelativePath: filepath.FromSlash("base/e/file.go")}, }, - expected: []result.Issue{ - {RelativePath: filepath.FromSlash("base/a/file.go")}, - {RelativePath: filepath.FromSlash("base/b/file.go")}, - {RelativePath: filepath.FromSlash("base/d/file.go")}, + expected: []*result.Issue{ + {RelativePath: filepath.FromSlash("base/c/file.go")}, + {RelativePath: filepath.FromSlash("base/c/a/file.go")}, + {RelativePath: filepath.FromSlash("base/c/b/file.go")}, + {RelativePath: filepath.FromSlash("base/e/file.go")}, }, }, { - desc: "pathsExcept and paths", + desc: "pathsExcept and paths (disjoint)", cfg: &config.LinterExclusions{ Paths: []string{"^base/b/"}, PathsExcept: []string{`^base/c/.*$`}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -193,10 +194,30 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ + {RelativePath: filepath.FromSlash("base/c/file.go")}, + {RelativePath: filepath.FromSlash("base/c/a/file.go")}, + {RelativePath: filepath.FromSlash("base/c/b/file.go")}, + }, + }, + { + desc: "pathsExcept and paths (intersection)", + cfg: &config.LinterExclusions{ + Paths: []string{"^base/c/a/"}, + PathsExcept: []string{`^base/c/.*$`}, + }, + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, + {RelativePath: filepath.FromSlash("base/b/file.go")}, + {RelativePath: filepath.FromSlash("base/c/file.go")}, + {RelativePath: filepath.FromSlash("base/c/a/file.go")}, + {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, + expected: []*result.Issue{ + {RelativePath: filepath.FromSlash("base/c/file.go")}, + {RelativePath: filepath.FromSlash("base/c/b/file.go")}, + }, }, } diff --git a/pkg/result/processors/exclusion_rules.go b/pkg/result/processors/exclusion_rules.go index 064921ae607a..2b5221a89085 100644 --- a/pkg/result/processors/exclusion_rules.go +++ b/pkg/result/processors/exclusion_rules.go @@ -49,7 +49,7 @@ func (*ExclusionRules) Name() string { return "exclusion_rules" } -func (p *ExclusionRules) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *ExclusionRules) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.rules) == 0 { return issues, nil } diff --git a/pkg/result/processors/exclusion_rules_test.go b/pkg/result/processors/exclusion_rules_test.go index 5657f45ed7a3..6f78ee2d2b3e 100644 --- a/pkg/result/processors/exclusion_rules_test.go +++ b/pkg/result/processors/exclusion_rules_test.go @@ -63,7 +63,7 @@ func TestExclusionRules_Process_multiple(t *testing.T) { {Path: filepath.FromSlash("testdata/exclusion_rules/exclusion_rules.go"), Line: 3, Linter: "lll"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -105,9 +105,9 @@ func TestExclusionRules_Process_text(t *testing.T) { p := NewExclusionRules(nil, lines, cfg) texts := []string{"exclude", "1", "", "exclud", "notexclude"} - var issues []result.Issue + var issues []*result.Issue for _, t := range texts { - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ Text: t, FromLinter: "linter", }) @@ -178,7 +178,7 @@ func TestExclusionRules_Process_caseSensitive_multiple(t *testing.T) { {Path: filepath.FromSlash("testdata/exclusion_rules/case_sensitive.go"), Line: 3, Linter: "lll"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -225,9 +225,9 @@ func TestExclusionRules_Process_caseSensitive_text(t *testing.T) { texts := []string{"exclude", "excLude", "1", "", "exclud", "notexclude"} - var issues []result.Issue + var issues []*result.Issue for _, t := range texts { - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ Text: t, FromLinter: "linter", }) diff --git a/pkg/result/processors/filename_unadjuster.go b/pkg/result/processors/filename_unadjuster.go index a3cdd8e6ed7c..e39601d5a4a4 100644 --- a/pkg/result/processors/filename_unadjuster.go +++ b/pkg/result/processors/filename_unadjuster.go @@ -66,7 +66,7 @@ func (*FilenameUnadjuster) Name() string { return "filename_unadjuster" } -func (p *FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *FilenameUnadjuster) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { mapper := p.m[issue.FilePath()] if mapper == nil { diff --git a/pkg/result/processors/fixer.go b/pkg/result/processors/fixer.go index 14dd3454eab6..ce33b27fb276 100644 --- a/pkg/result/processors/fixer.go +++ b/pkg/result/processors/fixer.go @@ -22,6 +22,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goformatters/gofumpt" "github.com/golangci/golangci-lint/v2/pkg/goformatters/goimports" "github.com/golangci/golangci-lint/v2/pkg/goformatters/golines" + "github.com/golangci/golangci-lint/v2/pkg/goformatters/swaggo" "github.com/golangci/golangci-lint/v2/pkg/logutils" "github.com/golangci/golangci-lint/v2/pkg/result" "github.com/golangci/golangci-lint/v2/pkg/timeutils" @@ -55,14 +56,14 @@ func (Fixer) Name() string { return "fixer" } -func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error) { +func (p Fixer) Process(issues []*result.Issue) ([]*result.Issue, error) { if !p.cfg.Issues.NeedFix { return issues, nil } p.log.Infof("Applying suggested fixes") - notFixableIssues, err := timeutils.TrackStage(p.sw, "all", func() ([]result.Issue, error) { + notFixableIssues, err := timeutils.TrackStage(p.sw, "all", func() ([]*result.Issue, error) { return p.process(issues) }) if err != nil { @@ -75,13 +76,13 @@ func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error) { } //nolint:funlen,gocyclo // This function should not be split. -func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) { +func (p Fixer) process(issues []*result.Issue) ([]*result.Issue, error) { // filenames / linters / edits editsByLinter := make(map[string]map[string][]diff.Edit) - formatters := []string{gofumpt.Name, goimports.Name, gofmt.Name, gci.Name, golines.Name} + formatters := []string{gofumpt.Name, goimports.Name, gofmt.Name, gci.Name, golines.Name, swaggo.Name} - var notFixableIssues []result.Issue + var notFixableIssues []*result.Issue toBeFormattedFiles := make(map[string]struct{}) @@ -93,7 +94,7 @@ func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) { continue } - if issue.SuggestedFixes == nil || skipNoTextEdit(&issue) { + if issue.SuggestedFixes == nil || skipNoTextEdit(issue) { notFixableIssues = append(notFixableIssues, issue) continue } diff --git a/pkg/result/processors/invalid_issue.go b/pkg/result/processors/invalid_issue.go index a7f45d408333..fa1b19e82c17 100644 --- a/pkg/result/processors/invalid_issue.go +++ b/pkg/result/processors/invalid_issue.go @@ -24,7 +24,7 @@ func (InvalidIssue) Name() string { return "invalid_issue" } -func (p InvalidIssue) Process(issues []result.Issue) ([]result.Issue, error) { +func (p InvalidIssue) Process(issues []*result.Issue) ([]*result.Issue, error) { tcIssues := filterIssuesUnsafe(issues, func(issue *result.Issue) bool { return issue.FromLinter == typeCheckName }) diff --git a/pkg/result/processors/invalid_issue_test.go b/pkg/result/processors/invalid_issue_test.go index 32628c336d31..c685551a9673 100644 --- a/pkg/result/processors/invalid_issue_test.go +++ b/pkg/result/processors/invalid_issue_test.go @@ -19,21 +19,21 @@ func TestInvalidIssue_Process(t *testing.T) { testCases := []struct { desc string - issues []result.Issue - expected []result.Issue + issues []*result.Issue + expected []*result.Issue }{ { desc: "typecheck", - issues: []result.Issue{ + issues: []*result.Issue{ {FromLinter: "typecheck"}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {FromLinter: "typecheck"}, }, }, { desc: "keep only typecheck issues if any exist", - issues: []result.Issue{ + issues: []*result.Issue{ {FromLinter: "typecheck"}, { FromLinter: "example", @@ -42,13 +42,13 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{ + expected: []*result.Issue{ {FromLinter: "typecheck"}, }, }, { desc: "Go file", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -56,7 +56,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -67,7 +67,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, { desc: "go.mod", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -75,7 +75,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -86,7 +86,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, { desc: "non Go file", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -94,11 +94,11 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{}, + expected: []*result.Issue{}, }, { desc: "no filename", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -106,7 +106,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{}, + expected: []*result.Issue{}, }, } diff --git a/pkg/result/processors/issues.go b/pkg/result/processors/issues.go index 1e76291c77a1..cc4deeb5267e 100644 --- a/pkg/result/processors/issues.go +++ b/pkg/result/processors/issues.go @@ -6,62 +6,62 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func filterIssues(issues []result.Issue, filter func(issue *result.Issue) bool) []result.Issue { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - if issues[i].FromLinter == typeCheckName { +func filterIssues(issues []*result.Issue, filter func(issue *result.Issue) bool) []*result.Issue { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + if issue.FromLinter == typeCheckName { // don't hide typechecking errors in generated files: users expect to see why the project isn't compiling - retIssues = append(retIssues, issues[i]) + retIssues = append(retIssues, issue) continue } - if filter(&issues[i]) { - retIssues = append(retIssues, issues[i]) + if filter(issue) { + retIssues = append(retIssues, issue) } } return retIssues } -func filterIssuesUnsafe(issues []result.Issue, filter func(issue *result.Issue) bool) []result.Issue { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - if filter(&issues[i]) { - retIssues = append(retIssues, issues[i]) +func filterIssuesUnsafe(issues []*result.Issue, filter func(issue *result.Issue) bool) []*result.Issue { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + if filter(issue) { + retIssues = append(retIssues, issue) } } return retIssues } -func filterIssuesErr(issues []result.Issue, filter func(issue *result.Issue) (bool, error)) ([]result.Issue, error) { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - if issues[i].FromLinter == typeCheckName { +func filterIssuesErr(issues []*result.Issue, filter func(issue *result.Issue) (bool, error)) ([]*result.Issue, error) { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + if issue.FromLinter == typeCheckName { // don't hide typechecking errors in generated files: users expect to see why the project isn't compiling - retIssues = append(retIssues, issues[i]) + retIssues = append(retIssues, issue) continue } - ok, err := filter(&issues[i]) + ok, err := filter(issue) if err != nil { - return nil, fmt.Errorf("can't filter issue %#v: %w", issues[i], err) + return nil, fmt.Errorf("can't filter issue %#v: %w", issue, err) } if ok { - retIssues = append(retIssues, issues[i]) + retIssues = append(retIssues, issue) } } return retIssues, nil } -func transformIssues(issues []result.Issue, transform func(issue *result.Issue) *result.Issue) []result.Issue { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - newIssue := transform(&issues[i]) +func transformIssues(issues []*result.Issue, transform func(issue *result.Issue) *result.Issue) []*result.Issue { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + newIssue := transform(issue) if newIssue != nil { - retIssues = append(retIssues, *newIssue) + retIssues = append(retIssues, newIssue) } } diff --git a/pkg/result/processors/max_from_linter.go b/pkg/result/processors/max_from_linter.go index dec9f3e7f13a..bc7572f2ccaf 100644 --- a/pkg/result/processors/max_from_linter.go +++ b/pkg/result/processors/max_from_linter.go @@ -29,7 +29,7 @@ func (*MaxFromLinter) Name() string { return "max_from_linter" } -func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *MaxFromLinter) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.limit <= 0 { // no limit return issues, nil } diff --git a/pkg/result/processors/max_per_file_from_linter.go b/pkg/result/processors/max_per_file_from_linter.go index fdb6bb0278da..b04b92ea7a7f 100644 --- a/pkg/result/processors/max_per_file_from_linter.go +++ b/pkg/result/processors/max_per_file_from_linter.go @@ -7,6 +7,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/goformatters/gofumpt" "github.com/golangci/golangci-lint/v2/pkg/goformatters/goimports" "github.com/golangci/golangci-lint/v2/pkg/goformatters/golines" + "github.com/golangci/golangci-lint/v2/pkg/goformatters/swaggo" "github.com/golangci/golangci-lint/v2/pkg/result" ) @@ -24,7 +25,7 @@ func NewMaxPerFileFromLinter(cfg *config.Config) *MaxPerFileFromLinter { if !cfg.Issues.NeedFix { // if we don't fix we do this limiting to not annoy user; // otherwise we need to fix all issues in the file at once - for _, f := range []string{gofmt.Name, gofumpt.Name, goimports.Name, gci.Name, golines.Name} { + for _, f := range []string{gofmt.Name, gofumpt.Name, goimports.Name, gci.Name, golines.Name, swaggo.Name} { maxPerFileFromLinterConfig[f] = 1 } } @@ -39,7 +40,7 @@ func (*MaxPerFileFromLinter) Name() string { return "max_per_file_from_linter" } -func (p *MaxPerFileFromLinter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *MaxPerFileFromLinter) Process(issues []*result.Issue) ([]*result.Issue, error) { return filterIssuesUnsafe(issues, func(issue *result.Issue) bool { limit := p.maxPerFileFromLinterConfig[issue.FromLinter] if limit == 0 { diff --git a/pkg/result/processors/max_per_file_from_linter_test.go b/pkg/result/processors/max_per_file_from_linter_test.go index c5bc7ebc1e8b..a886b47c75f0 100644 --- a/pkg/result/processors/max_per_file_from_linter_test.go +++ b/pkg/result/processors/max_per_file_from_linter_test.go @@ -7,8 +7,8 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newFromLinterIssue(linterName string) result.Issue { - return result.Issue{ +func newFromLinterIssue(linterName string) *result.Issue { + return &result.Issue{ FromLinter: linterName, } } diff --git a/pkg/result/processors/max_same_issues.go b/pkg/result/processors/max_same_issues.go index 06e87586e171..ba22cf31fb62 100644 --- a/pkg/result/processors/max_same_issues.go +++ b/pkg/result/processors/max_same_issues.go @@ -31,7 +31,7 @@ func (*MaxSameIssues) Name() string { return "max_same_issues" } -func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *MaxSameIssues) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.limit <= 0 { // no limit return issues, nil } diff --git a/pkg/result/processors/max_same_issues_test.go b/pkg/result/processors/max_same_issues_test.go index 574059ebbb41..8eb7de0e39a8 100644 --- a/pkg/result/processors/max_same_issues_test.go +++ b/pkg/result/processors/max_same_issues_test.go @@ -10,10 +10,10 @@ import ( func TestMaxSameIssues(t *testing.T) { p := NewMaxSameIssues(1, logutils.NewStderrLog(logutils.DebugKeyEmpty), &config.Config{}) - i1 := result.Issue{ + i1 := &result.Issue{ Text: "1", } - i2 := result.Issue{ + i2 := &result.Issue{ Text: "2", } diff --git a/pkg/result/processors/nolint_filter.go b/pkg/result/processors/nolint_filter.go index 96fd6403ec45..bd2a09abea43 100644 --- a/pkg/result/processors/nolint_filter.go +++ b/pkg/result/processors/nolint_filter.go @@ -91,7 +91,7 @@ func (*NolintFilter) Name() string { return "nolint_filter" } -func (p *NolintFilter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *NolintFilter) Process(issues []*result.Issue) ([]*result.Issue, error) { // put nolintlint issues last because we process other issues first to determine which nolint directives are unused sort.Stable(sortWithNolintlintLast(issues)) return filterIssuesErr(issues, p.shouldPassIssue) @@ -185,8 +185,7 @@ func (p *NolintFilter) buildIgnoredRangesForFile(f *ast.File, fset *token.FileSe ast.Walk(&e, f) // TODO: merge all ranges: there are repeated ranges - allRanges := append([]ignoredRange{}, inlineRanges...) - allRanges = append(allRanges, e.expandedRanges...) + allRanges := slices.Concat(inlineRanges, e.expandedRanges) return allRanges } @@ -300,7 +299,7 @@ func (e *rangeExpander) Visit(node ast.Node) ast.Visitor { } // put nolintlint last -type sortWithNolintlintLast []result.Issue +type sortWithNolintlintLast []*result.Issue func (issues sortWithNolintlintLast) Len() int { return len(issues) diff --git a/pkg/result/processors/nolint_filter_test.go b/pkg/result/processors/nolint_filter_test.go index 79dc6c1ce4bb..c620875aba98 100644 --- a/pkg/result/processors/nolint_filter_test.go +++ b/pkg/result/processors/nolint_filter_test.go @@ -16,8 +16,8 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newNolintFileIssue(line int, fromLinter string) result.Issue { - return result.Issue{ +func newNolintFileIssue(line int, fromLinter string) *result.Issue { + return &result.Issue{ Pos: token.Position{ Filename: filepath.FromSlash("testdata/nolint_filter/nolint.go"), Line: line, @@ -26,7 +26,7 @@ func newNolintFileIssue(line int, fromLinter string) result.Issue { } } -func newNolint2FileIssue(line int) result.Issue { +func newNolint2FileIssue(line int) *result.Issue { i := newNolintFileIssue(line, "errcheck") i.Pos.Filename = filepath.FromSlash("testdata/nolint_filter/nolint2.go") return i @@ -126,7 +126,7 @@ func TestTestNolintFilter_Process(t *testing.T) { func TestNolintFilter_Process_invalidLinterName(t *testing.T) { fileName := filepath.FromSlash("testdata/nolint_filter/bad_names.go") - issues := []result.Issue{ + issues := []*result.Issue{ { Pos: token.Position{ Filename: fileName, @@ -161,7 +161,7 @@ func TestNolintFilter_Process_invalidLinterName(t *testing.T) { func TestNolintFilter_Process_invalidLinterNameWithViolationOnTheSameLine(t *testing.T) { log := getMockLog() log.On("Warnf", "Found unknown linters in //nolint directives: %s", "foobar") - issues := []result.Issue{ + issues := []*result.Issue{ { Pos: token.Position{ Filename: filepath.FromSlash("testdata/nolint_filter/apply_to_unknown.go"), @@ -246,14 +246,14 @@ func TestNolintFilter_Process_wholeFile(t *testing.T) { p := newTestNolintFilter(getMockLog()) defer p.Finish() - processAssertEmpty(t, p, result.Issue{ + processAssertEmpty(t, p, &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 9, }, FromLinter: "errcheck", }) - processAssertSame(t, p, result.Issue{ + processAssertSame(t, p, &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 14, @@ -284,7 +284,7 @@ func TestNolintFilter_Process_unused(t *testing.T) { } // the issue below is the nolintlint issue that would be generated for the test file - nolintlintIssueMisspell := result.Issue{ + nolintlintIssueMisspell := &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 3, @@ -295,7 +295,7 @@ func TestNolintFilter_Process_unused(t *testing.T) { } // the issue below is another nolintlint issue that would be generated for the test file - nolintlintIssueMisspellUnusedOK := result.Issue{ + nolintlintIssueMisspellUnusedOK := &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 5, @@ -323,7 +323,7 @@ func TestNolintFilter_Process_unused(t *testing.T) { p := createProcessor(t, log, []string{"misspell", "nolintlint"}) defer p.Finish() - processAssertEmpty(t, p, []result.Issue{{ + processAssertEmpty(t, p, []*result.Issue{{ Pos: token.Position{ Filename: fileName, Line: 3, diff --git a/pkg/result/processors/path_absoluter.go b/pkg/result/processors/path_absoluter.go index 99f3de42a2cd..240cedf8eaf4 100644 --- a/pkg/result/processors/path_absoluter.go +++ b/pkg/result/processors/path_absoluter.go @@ -22,7 +22,7 @@ func (*PathAbsoluter) Name() string { return "path_absoluter" } -func (p *PathAbsoluter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *PathAbsoluter) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { if filepath.IsAbs(issue.FilePath()) { return issue diff --git a/pkg/result/processors/path_prettifier.go b/pkg/result/processors/path_prettifier.go index cb6ef8ebc27d..94dfbab370ab 100644 --- a/pkg/result/processors/path_prettifier.go +++ b/pkg/result/processors/path_prettifier.go @@ -30,7 +30,7 @@ func (*PathPrettifier) Name() string { return "path_prettifier" } -func (p *PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *PathPrettifier) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.cfg.PathMode == fsutils.OutputPathModeAbsolute { return issues, nil } diff --git a/pkg/result/processors/path_prettifier_test.go b/pkg/result/processors/path_prettifier_test.go index 824509712ef7..2f403d46a327 100644 --- a/pkg/result/processors/path_prettifier_test.go +++ b/pkg/result/processors/path_prettifier_test.go @@ -13,15 +13,15 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newPPIssue(fn, rp string) result.Issue { - return result.Issue{ +func newPPIssue(fn, rp string) *result.Issue { + return &result.Issue{ Pos: token.Position{Filename: filepath.FromSlash(fn)}, RelativePath: filepath.FromSlash(rp), } } func TestPathPrettifier_Process(t *testing.T) { - paths := func(ps ...string) (issues []result.Issue) { + paths := func(ps ...string) (issues []*result.Issue) { for _, p := range ps { issues = append(issues, newPPIssue("test", p)) } @@ -30,12 +30,12 @@ func TestPathPrettifier_Process(t *testing.T) { for _, tt := range []struct { name, prefix string - issues, want []result.Issue + issues, want []*result.Issue }{ { name: "empty prefix", issues: paths("some/path", "cool"), - want: []result.Issue{ + want: []*result.Issue{ newPPIssue("some/path", "some/path"), newPPIssue("cool", "cool"), }, @@ -44,7 +44,7 @@ func TestPathPrettifier_Process(t *testing.T) { name: "prefix", prefix: "ok", issues: paths("some/path", "cool"), - want: []result.Issue{ + want: []*result.Issue{ newPPIssue("ok/some/path", "some/path"), newPPIssue("ok/cool", "cool"), }, @@ -53,7 +53,7 @@ func TestPathPrettifier_Process(t *testing.T) { name: "prefix slashed", prefix: "ok/", issues: paths("some/path", "cool"), - want: []result.Issue{ + want: []*result.Issue{ newPPIssue("ok/some/path", "some/path"), newPPIssue("ok/cool", "cool"), }, diff --git a/pkg/result/processors/path_relativity.go b/pkg/result/processors/path_relativity.go index 8b2958a4a308..c68662c7bb1f 100644 --- a/pkg/result/processors/path_relativity.go +++ b/pkg/result/processors/path_relativity.go @@ -36,7 +36,7 @@ func (*PathRelativity) Name() string { return "path_relativity" } -func (p *PathRelativity) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *PathRelativity) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { newIssue := *issue diff --git a/pkg/result/processors/path_shortener.go b/pkg/result/processors/path_shortener.go index 7a14c39c972e..23df4f02cc20 100644 --- a/pkg/result/processors/path_shortener.go +++ b/pkg/result/processors/path_shortener.go @@ -29,7 +29,7 @@ func (PathShortener) Name() string { return "path_shortener" } -func (p PathShortener) Process(issues []result.Issue) ([]result.Issue, error) { +func (p PathShortener) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { newIssue := issue newIssue.Text = strings.ReplaceAll(newIssue.Text, p.wd+"/", "") diff --git a/pkg/result/processors/processor.go b/pkg/result/processors/processor.go index 1976d6e44ad9..f5603c94dc75 100644 --- a/pkg/result/processors/processor.go +++ b/pkg/result/processors/processor.go @@ -7,7 +7,7 @@ import ( const typeCheckName = "typecheck" type Processor interface { - Process(issues []result.Issue) ([]result.Issue, error) + Process(issues []*result.Issue) ([]*result.Issue, error) Name() string Finish() } diff --git a/pkg/result/processors/processor_test.go b/pkg/result/processors/processor_test.go index 41bb78a7b3ae..95fdb5f81445 100644 --- a/pkg/result/processors/processor_test.go +++ b/pkg/result/processors/processor_test.go @@ -18,8 +18,8 @@ type issueTestCase struct { Severity string } -func newIssueFromIssueTestCase(c issueTestCase) result.Issue { - return result.Issue{ +func newIssueFromIssueTestCase(c issueTestCase) *result.Issue { + return &result.Issue{ Text: c.Text, FromLinter: c.Linter, Severity: c.Severity, @@ -31,13 +31,13 @@ func newIssueFromIssueTestCase(c issueTestCase) result.Issue { } } -func newIssueFromTextTestCase(text string) result.Issue { - return result.Issue{ +func newIssueFromTextTestCase(text string) *result.Issue { + return &result.Issue{ Text: text, } } -func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue { +func process(t *testing.T, p Processor, issues ...*result.Issue) []*result.Issue { t.Helper() processedIssues, err := p.Process(issues) @@ -45,14 +45,14 @@ func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue { return processedIssues } -func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) { +func processAssertSame(t *testing.T, p Processor, issues ...*result.Issue) { t.Helper() processedIssues := process(t, p, issues...) assert.Equal(t, issues, processedIssues) } -func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) { +func processAssertEmpty(t *testing.T, p Processor, issues ...*result.Issue) { t.Helper() processedIssues := process(t, p, issues...) diff --git a/pkg/result/processors/severity.go b/pkg/result/processors/severity.go index 035ca80c4e1d..33c3997f8889 100644 --- a/pkg/result/processors/severity.go +++ b/pkg/result/processors/severity.go @@ -43,7 +43,7 @@ func NewSeverity(log logutils.Log, lines *fsutils.LineCache, cfg *config.Severit func (p *Severity) Name() string { return p.name } -func (p *Severity) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *Severity) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.rules) == 0 && p.defaultSeverity == "" { return issues, nil } diff --git a/pkg/result/processors/severity_test.go b/pkg/result/processors/severity_test.go index 0774f0b1d517..a5c50d0011cc 100644 --- a/pkg/result/processors/severity_test.go +++ b/pkg/result/processors/severity_test.go @@ -92,7 +92,7 @@ func TestSeverity_multiple(t *testing.T) { {Path: "empty.go", Text: "empty", Linter: "empty"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -141,9 +141,9 @@ func TestSeverity_text(t *testing.T) { p := NewSeverity(nil, nil, opts) texts := []string{"seveRity", "1", "", "serverit", "notseverity"} - var issues []result.Issue + var issues []*result.Issue for _, t := range texts { - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ Text: t, FromLinter: "linter", }) @@ -176,7 +176,7 @@ func TestSeverity_onlyDefault(t *testing.T) { {Path: "empty.go", Text: "empty", Linter: "empty"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -230,7 +230,7 @@ func TestSeverity_caseSensitive(t *testing.T) { {Path: "e.go", Text: "ssL", Linter: "gosec"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go index 033eca9a4374..8ba06bccfd10 100644 --- a/pkg/result/processors/sort_results.go +++ b/pkg/result/processors/sort_results.go @@ -54,7 +54,7 @@ func NewSortResults(cfg *config.Output) *SortResults { func (SortResults) Name() string { return "sort_results" } // Process is performing sorting of the result issues. -func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { +func (p SortResults) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.cfg.SortOrder) == 0 { p.cfg.SortOrder = []string{orderNameLinter, orderNameFile} } @@ -72,8 +72,8 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { comp := mergeComparators(cmps...) - slices.SortFunc(issues, func(a, b result.Issue) int { - return comp(&a, &b) + slices.SortFunc(issues, func(a, b *result.Issue) int { + return comp(a, b) }) return issues, nil diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go index fcfd824c8eb1..dc097cc967de 100644 --- a/pkg/result/processors/sort_results_test.go +++ b/pkg/result/processors/sort_results_test.go @@ -12,7 +12,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -var issues = []result.Issue{ +var issues = []*result.Issue{ { FromLinter: "b", Severity: "medium", @@ -50,7 +50,7 @@ var issues = []result.Issue{ }, } -var extraSeverityIssues = []result.Issue{ +var extraSeverityIssues = []*result.Issue{ { FromLinter: "c", Severity: "error", @@ -72,16 +72,16 @@ var extraSeverityIssues = []result.Issue{ } type compareTestCase struct { - a, b result.Issue + a, b *result.Issue expected int } func testCompareValues(t *testing.T, cmp issueComparator, name string, tests []compareTestCase) { - for i, test := range tests { //nolint:gocritic // To ignore rangeValCopy rule + for i, test := range tests { t.Run(fmt.Sprintf("%s(%d)", name, i), func(t *testing.T) { t.Parallel() - res := cmp(&test.a, &test.b) + res := cmp(test.a, test.b) assert.Equal(t, compToString(test.expected), compToString(res)) }) @@ -210,7 +210,7 @@ func Test_numericCompare(t *testing.T) { } func TestSortResults_Process(t *testing.T) { - tests := make([]result.Issue, len(issues)) + tests := make([]*result.Issue, len(issues)) copy(tests, issues) cfg := &config.Output{} @@ -219,7 +219,7 @@ func TestSortResults_Process(t *testing.T) { results, err := sr.Process(tests) require.NoError(t, err) - assert.Equal(t, []result.Issue{issues[1], issues[0], issues[3], issues[2]}, results) + assert.Equal(t, []*result.Issue{issues[1], issues[0], issues[3], issues[2]}, results) } func compToString(c int) string { diff --git a/pkg/result/processors/source_code.go b/pkg/result/processors/source_code.go index 1096269c8176..d4e82643c0d9 100644 --- a/pkg/result/processors/source_code.go +++ b/pkg/result/processors/source_code.go @@ -31,7 +31,7 @@ func (SourceCode) Name() string { return "source_code" } -func (p SourceCode) Process(issues []result.Issue) ([]result.Issue, error) { +func (p SourceCode) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, p.transform), nil } diff --git a/pkg/result/processors/uniq_by_line.go b/pkg/result/processors/uniq_by_line.go index 113b5814ad16..953496355b09 100644 --- a/pkg/result/processors/uniq_by_line.go +++ b/pkg/result/processors/uniq_by_line.go @@ -25,7 +25,7 @@ func (*UniqByLine) Name() string { return "uniq_by_line" } -func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *UniqByLine) Process(issues []*result.Issue) ([]*result.Issue, error) { if !p.enabled { return issues, nil } diff --git a/pkg/result/processors/uniq_by_line_test.go b/pkg/result/processors/uniq_by_line_test.go index dadca6a9afa1..d623c2e62569 100644 --- a/pkg/result/processors/uniq_by_line_test.go +++ b/pkg/result/processors/uniq_by_line_test.go @@ -7,8 +7,8 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newULIssue(file string, line int) result.Issue { - return result.Issue{ +func newULIssue(file string, line int) *result.Issue { + return &result.Issue{ Pos: token.Position{ Filename: file, Line: line, diff --git a/scripts/gen_github_action_config/go.mod b/scripts/gen_github_action_config/go.mod index c76a4de5840a..32b5cca642a1 100644 --- a/scripts/gen_github_action_config/go.mod +++ b/scripts/gen_github_action_config/go.mod @@ -5,7 +5,7 @@ go 1.23.0 require ( github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064 github.com/stretchr/testify v1.10.0 - golang.org/x/oauth2 v0.29.0 + golang.org/x/oauth2 v0.30.0 ) require ( diff --git a/scripts/gen_github_action_config/go.sum b/scripts/gen_github_action_config/go.sum index b9b970ef73ac..16f1f14cd28c 100644 --- a/scripts/gen_github_action_config/go.sum +++ b/scripts/gen_github_action_config/go.sum @@ -1,7 +1,5 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/shurcooL/githubv4 v0.0.0-20240429030203-be2daab69064 h1:RCQBSFx5JrsbHltqTtJ+kN3U0Y3a/N/GlVdmRSoxzyE= @@ -10,8 +8,8 @@ github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZV github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= -golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= +golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/scripts/website/expand_templates/thanks_test.go b/scripts/website/expand_templates/thanks_test.go index 6af152336e99..7caa7e28c49f 100644 --- a/scripts/website/expand_templates/thanks_test.go +++ b/scripts/website/expand_templates/thanks_test.go @@ -14,7 +14,7 @@ type FakeLinter struct { name string } -func (*FakeLinter) Run(_ context.Context, _ *linter.Context) ([]result.Issue, error) { +func (*FakeLinter) Run(_ context.Context, _ *linter.Context) ([]*result.Issue, error) { return nil, nil } diff --git a/test/testshared/integration/run.go b/test/testshared/integration/run.go index cd0b4ca97076..f1add865fb54 100644 --- a/test/testshared/integration/run.go +++ b/test/testshared/integration/run.go @@ -4,6 +4,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strings" "testing" "time" @@ -70,7 +71,7 @@ func testOneSource(t *testing.T, log *logutils.StderrLog, binPath, sourcePath st } for _, addArg := range []string{"", "-Etypecheck"} { - caseArgs := append([]string{}, args...) + caseArgs := slices.Clone(args) if addArg != "" { caseArgs = append(caseArgs, addArg) diff --git a/test/testshared/runner.go b/test/testshared/runner.go index c516ad9a181a..69bb8bac80a7 100644 --- a/test/testshared/runner.go +++ b/test/testshared/runner.go @@ -4,6 +4,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strings" "sync" "syscall" @@ -286,10 +287,8 @@ func (r *RunnerResult) ExpectNoIssues() { func (r *RunnerResult) ExpectExitCode(possibleCodes ...int) *RunnerResult { r.tb.Helper() - for _, pc := range possibleCodes { - if pc == r.exitCode { - return r - } + if slices.Contains(possibleCodes, r.exitCode) { + return r } assert.Fail(r.tb, "invalid exit code", "exit code (%d) must be one of %v: %s", r.exitCode, possibleCodes, r.output)