Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ require (
golang.org/x/mod v0.34.0
golang.org/x/sync v0.20.0
golang.org/x/sys v0.42.0
golang.org/x/tools v0.42.0
golang.org/x/tools v0.43.0
honnef.co/go/tools v0.7.0
mvdan.cc/gofumpt v0.9.2
mvdan.cc/unparam v0.0.0-20251027182757-5beb8c8f8f15
Expand Down
8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions internal/x/tools/analysisflags/readme.md

This file was deleted.

11 changes: 0 additions & 11 deletions internal/x/tools/analysisinternal/readme.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package analysisinternal provides gopls' internal analyses with a
// number of helper functions that operate on typed syntax trees.
package analysisinternal
package driverutil

// This file defines helpers for implementing [analysis.Pass.ReadFile].

import (
"fmt"
Expand Down
25 changes: 25 additions & 0 deletions internal/x/tools/driverutil/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# driverutil

Extracted from `/internal/analysis/driverutil/` (related to `checker`).
This is just a copy of `readfile.go` and `url.go` without any changes.

Previously, it was `analysisinternal` and `analysisflags` packages.

## History

- https://github.com/golangci/golangci-lint/pull/6434
- sync with https://github.com/golang/tools/blob/v0.43.0/internal/analysis/driverutil/readfile.go

## analysisinternal History

- https://github.com/golangci/golangci-lint/pull/6076
- sync with https://github.com/golang/tools/blob/v0.37.0/internal/analysisinternal/
- https://github.com/golangci/golangci-lint/pull/5576
- sync with https://github.com/golang/tools/blob/v0.28.0/internal/analysisinternal/

## analysisflags History

- https://github.com/golangci/golangci-lint/pull/6076
- sync with https://github.com/golang/tools/blob/v0.37.0/go/analysis/internal/analysisflags
- https://github.com/golangci/golangci-lint/pull/5576
- sync with https://github.com/golang/tools/blob/v0.28.0/go/analysis/internal/analysisflags
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package analysisflags
package driverutil

import (
"fmt"
Expand Down
46 changes: 35 additions & 11 deletions pkg/goanalysis/runner_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Altered copy of https://github.com/golang/tools/blob/v0.28.0/go/analysis/internal/checker/checker.go
// Altered copy of https://github.com/golang/tools/blob/v0.43.0/go/analysis/checker/checker.go

package goanalysis

Expand All @@ -19,8 +19,7 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"

"github.com/golangci/golangci-lint/v2/internal/x/tools/analysisflags"
"github.com/golangci/golangci-lint/v2/internal/x/tools/analysisinternal"
"github.com/golangci/golangci-lint/v2/internal/x/tools/driverutil"
"github.com/golangci/golangci-lint/v2/pkg/goanalysis/pkgerrors"
)

Expand Down Expand Up @@ -134,9 +133,7 @@ func (act *action) analyze() {

module := &analysis.Module{} // possibly empty (non nil) in go/analysis drivers.
if mod := act.Package.Module; mod != nil {
module.Path = mod.Path
module.Version = mod.Version
module.GoVersion = mod.GoVersion
module = analysisModuleFromPackagesModule(mod)
}

// Run the analysis.
Expand All @@ -161,7 +158,7 @@ func (act *action) analyze() {
AllObjectFacts: act.AllObjectFacts,
AllPackageFacts: act.AllPackageFacts,
}
pass.ReadFile = analysisinternal.CheckedReadFile(pass, os.ReadFile)
pass.ReadFile = driverutil.CheckedReadFile(pass, os.ReadFile)
act.pass = pass

act.runner.passToPkgGuard.Lock()
Expand Down Expand Up @@ -199,7 +196,7 @@ func (act *action) analyze() {

// resolve diagnostic URLs
for i := range act.Diagnostics {
url, err := analysisflags.ResolveURL(act.Analyzer, act.Diagnostics[i])
url, err := driverutil.ResolveURL(act.Analyzer, act.Diagnostics[i])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -324,7 +321,7 @@ func exportedFrom(obj types.Object, pkg *types.Package) bool {
switch obj := obj.(type) {
case *types.Func:
return obj.Exported() && obj.Pkg() == pkg ||
obj.Type().(*types.Signature).Recv() != nil
obj.Signature().Recv() != nil
case *types.Var:
if obj.IsField() {
return true
Expand Down Expand Up @@ -387,8 +384,8 @@ func (act *action) exportObjectFact(obj types.Object, fact analysis.Fact) {
// See documentation at AllObjectFacts field of [analysis.Pass].
func (act *action) AllObjectFacts() []analysis.ObjectFact {
facts := make([]analysis.ObjectFact, 0, len(act.objectFacts))
for k := range act.objectFacts {
facts = append(facts, analysis.ObjectFact{Object: k.obj, Fact: act.objectFacts[k]})
for k, fact := range act.objectFacts {
facts = append(facts, analysis.ObjectFact{Object: k.obj, Fact: fact})
}
return facts
}
Expand Down Expand Up @@ -445,3 +442,30 @@ func (act *action) AllPackageFacts() []analysis.PackageFact {
}
return facts
}

// NOTE(ldez) no alteration.
func analysisModuleFromPackagesModule(mod *packages.Module) *analysis.Module {
if mod == nil {
return nil
}

var modErr *analysis.ModuleError
if mod.Error != nil {
modErr = &analysis.ModuleError{
Err: mod.Error.Err,
}
}

return &analysis.Module{
Path: mod.Path,
Version: mod.Version,
Replace: analysisModuleFromPackagesModule(mod.Replace),
Time: mod.Time,
Main: mod.Main,
Indirect: mod.Indirect,
Dir: mod.Dir,
GoMod: mod.GoMod,
GoVersion: mod.GoVersion,
Error: modErr,
}
}
6 changes: 2 additions & 4 deletions pkg/golinters/modernize/testdata/fix/out/fmtappendf.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ func comma() {
type S struct{ Bytes []byte }
var _ = struct{ A S }{
A: S{
Bytes: // want "Replace .*Sprint.* with fmt.Appendf"
fmt.Appendf(nil, "%d", 0),
Bytes: fmt.Appendf(nil, "%d", 0),
},
}
_ = // want "Replace .*Sprint.* with fmt.Appendf"
fmt.Appendf(nil, "%d", 0)
_ = fmt.Appendf(nil, "%d", 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func _() {
}
var ok bool // define an ok variable to test the fix won't shadow it for its if stmt body
_ = ok
if after, ok0 := strings.CutPrefix(s, pre); ok0 { // want "TrimPrefix can be simplified to CutPrefix"
if after, ok := strings.CutPrefix(s, pre); ok { // want "TrimPrefix can be simplified to CutPrefix"
println(after)
}
var predefined string
Expand Down
Loading