Skip to content

Commit 0e15096

Browse files
Excavator: Bump go dependency github.com/golangci/golangci-lint/v2
1 parent 3042022 commit 0e15096

File tree

137 files changed

+10293
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+10293
-178
lines changed

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/analysisinternal/analysis.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,30 @@ package analysisinternal
88

99
import (
1010
"fmt"
11-
"os"
11+
"slices"
1212

1313
"golang.org/x/tools/go/analysis"
1414
)
1515

16-
// MakeReadFile returns a simple implementation of the Pass.ReadFile function.
17-
func MakeReadFile(pass *analysis.Pass) func(filename string) ([]byte, error) {
16+
// A ReadFileFunc is a function that returns the
17+
// contents of a file, such as [os.ReadFile].
18+
type ReadFileFunc = func(filename string) ([]byte, error)
19+
20+
// CheckedReadFile returns a wrapper around a Pass.ReadFile
21+
// function that performs the appropriate checks.
22+
func CheckedReadFile(pass *analysis.Pass, readFile ReadFileFunc) ReadFileFunc {
1823
return func(filename string) ([]byte, error) {
1924
if err := CheckReadable(pass, filename); err != nil {
2025
return nil, err
2126
}
22-
return os.ReadFile(filename)
27+
return readFile(filename)
2328
}
2429
}
2530

2631
// CheckReadable enforces the access policy defined by the ReadFile field of [analysis.Pass].
2732
func CheckReadable(pass *analysis.Pass, filename string) error {
28-
if slicesContains(pass.OtherFiles, filename) ||
29-
slicesContains(pass.IgnoredFiles, filename) {
33+
if slices.Contains(pass.OtherFiles, filename) ||
34+
slices.Contains(pass.IgnoredFiles, filename) {
3035
return nil
3136
}
3237
for _, f := range pass.Files {
@@ -36,13 +41,3 @@ func CheckReadable(pass *analysis.Pass, filename string) error {
3641
}
3742
return fmt.Errorf("Pass.ReadFile: %s is not among OtherFiles, IgnoredFiles, or names of Files", filename)
3843
}
39-
40-
// TODO(adonovan): use go1.21 slices.Contains.
41-
func slicesContains[S ~[]E, E comparable](slice S, x E) bool {
42-
for _, elem := range slice {
43-
if elem == x {
44-
return true
45-
}
46-
}
47-
return false
48-
}

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/diff/diff.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package diff
77

88
import (
99
"fmt"
10+
"slices"
1011
"sort"
1112
"strings"
1213
)
@@ -64,7 +65,7 @@ func ApplyBytes(src []byte, edits []Edit) ([]byte, error) {
6465
// It may return a different slice.
6566
func validate(src string, edits []Edit) ([]Edit, int, error) {
6667
if !sort.IsSorted(editsSort(edits)) {
67-
edits = append([]Edit(nil), edits...)
68+
edits = slices.Clone(edits)
6869
SortEdits(edits)
6970
}
7071

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/diff/lcs/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (l lcs) fix() lcs {
5151
// from the set of diagonals in l, find a maximal non-conflicting set
5252
// this problem may be NP-complete, but we use a greedy heuristic,
5353
// which is quadratic, but with a better data structure, could be D log D.
54-
// indepedent is not enough: {0,3,1} and {3,0,2} can't both occur in an lcs
54+
// independent is not enough: {0,3,1} and {3,0,2} can't both occur in an lcs
5555
// which has to have monotone x and y
5656
if len(l) == 0 {
5757
return nil

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/diff/lcs/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ computed labels. That is the worst case. Had the code noticed (x,y)=(u,v)=(3,3)
139139
from the edgegraph. The implementation looks for a number of special cases to try to avoid computing an extra forward path.
140140
141141
If the two-sided algorithm has stop early (because D has become too large) it will have found a forward LCS and a
142-
backwards LCS. Ideally these go with disjoint prefixes and suffixes of A and B, but disjointness may fail and the two
142+
backwards LCS. Ideally these go with disjoint prefixes and suffixes of A and B, but disjointedness may fail and the two
143143
computed LCS may conflict. (An easy example is where A is a suffix of B, and shares a short prefix. The backwards LCS
144144
is all of A, and the forward LCS is a prefix of A.) The algorithm combines the two
145145
to form a best-effort LCS. In the worst case the forward partial LCS may have to

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/diff/lcs/old.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func forward(e *editGraph) lcs {
105105
return ans
106106
}
107107
// from D to D+1
108-
for D := 0; D < e.limit; D++ {
108+
for D := range e.limit {
109109
e.setForward(D+1, -(D + 1), e.getForward(D, -D))
110110
if ok, ans := e.fdone(D+1, -(D + 1)); ok {
111111
return ans
@@ -199,13 +199,14 @@ func (e *editGraph) bdone(D, k int) (bool, lcs) {
199199
}
200200

201201
// run the backward algorithm, until success or up to the limit on D.
202+
// (used only by tests)
202203
func backward(e *editGraph) lcs {
203204
e.setBackward(0, 0, e.ux)
204205
if ok, ans := e.bdone(0, 0); ok {
205206
return ans
206207
}
207208
// from D to D+1
208-
for D := 0; D < e.limit; D++ {
209+
for D := range e.limit {
209210
e.setBackward(D+1, -(D + 1), e.getBackward(D, -D)-1)
210211
if ok, ans := e.bdone(D+1, -(D + 1)); ok {
211212
return ans
@@ -299,7 +300,7 @@ func twosided(e *editGraph) lcs {
299300
e.setBackward(0, 0, e.ux)
300301

301302
// from D to D+1
302-
for D := 0; D < e.limit; D++ {
303+
for D := range e.limit {
303304
// just finished a backwards pass, so check
304305
if got, ok := e.twoDone(D, D); ok {
305306
return e.twolcs(D, D, got)
@@ -376,10 +377,7 @@ func (e *editGraph) twoDone(df, db int) (int, bool) {
376377
if (df+db+e.delta)%2 != 0 {
377378
return 0, false // diagonals cannot overlap
378379
}
379-
kmin := -db + e.delta
380-
if -df > kmin {
381-
kmin = -df
382-
}
380+
kmin := max(-df, -db+e.delta)
383381
kmax := db + e.delta
384382
if df < kmax {
385383
kmax = df

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/diff/ndiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func diffRunes(before, after []rune) []Edit {
7272
func runes(bytes []byte) []rune {
7373
n := utf8.RuneCount(bytes)
7474
runes := make([]rune, n)
75-
for i := 0; i < n; i++ {
75+
for i := range n {
7676
r, sz := utf8.DecodeRune(bytes)
7777
bytes = bytes[sz:]
7878
runes[i] = r

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/internal/x/tools/diff/unified.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ func toUnified(fromName, toName string, content string, edits []Edit, contextLin
129129

130130
switch {
131131
case h != nil && start == last:
132-
//direct extension
132+
// direct extension
133133
case h != nil && start <= last+gap:
134-
//within range of previous lines, add the joiners
134+
// within range of previous lines, add the joiners
135135
addEqualLines(h, lines, last, start)
136136
default:
137-
//need to start a new hunk
137+
// need to start a new hunk
138138
if h != nil {
139139
// add the edge to the previous hunk
140140
addEqualLines(h, lines, last, last+contextLines)

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/pkg/commands/internal/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (b Builder) createVersion(orig string) (string, error) {
257257
continue
258258
}
259259

260-
dh, err := dirhash.HashDir(plugin.Path, "", dirhash.DefaultHash)
260+
dh, err := hashDir(plugin.Path, "", dirhash.DefaultHash)
261261
if err != nil {
262262
return "", fmt.Errorf("hash plugin directory: %w", err)
263263
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package internal
6+
7+
import (
8+
"fmt"
9+
"io"
10+
"os"
11+
"path/filepath"
12+
"strings"
13+
14+
"golang.org/x/mod/sumdb/dirhash"
15+
)
16+
17+
// Slightly modified copy of [dirhash.HashDir].
18+
// https://github.com/golang/mod/blob/v0.28.0/sumdb/dirhash/hash.go#L67-L79
19+
func hashDir(dir, prefix string, hash dirhash.Hash) (string, error) {
20+
files, err := dirFiles(dir, prefix)
21+
if err != nil {
22+
return "", err
23+
}
24+
25+
osOpen := func(name string) (io.ReadCloser, error) {
26+
return os.Open(filepath.Join(dir, strings.TrimPrefix(name, prefix)))
27+
}
28+
29+
return hash(files, osOpen)
30+
}
31+
32+
// Modified copy of [dirhash.DirFiles].
33+
// https://github.com/golang/mod/blob/v0.28.0/sumdb/dirhash/hash.go#L81-L109
34+
// And adapted to globally follows the rules from https://github.com/golang/mod/blob/v0.28.0/zip/zip.go
35+
func dirFiles(dir, prefix string) ([]string, error) {
36+
var files []string
37+
38+
dir = filepath.Clean(dir)
39+
40+
err := filepath.Walk(dir, func(file string, info os.FileInfo, err error) error {
41+
if err != nil {
42+
return err
43+
}
44+
45+
if info.IsDir() {
46+
if dir == file {
47+
// Don't skip the top-level directory.
48+
return nil
49+
}
50+
51+
switch info.Name() {
52+
// Skip vendor and node directories.
53+
case "vendor", "node_modules":
54+
return filepath.SkipDir
55+
56+
// Skip VCS directories.
57+
case ".bzr", ".git", ".hg", ".svn":
58+
return filepath.SkipDir
59+
}
60+
61+
// Skip submodules (directories containing go.mod files).
62+
if goModInfo, err := os.Lstat(filepath.Join(dir, "go.mod")); err == nil && !goModInfo.IsDir() {
63+
return filepath.SkipDir
64+
}
65+
66+
return nil
67+
}
68+
69+
if file == dir {
70+
return fmt.Errorf("%s is not a directory", dir)
71+
}
72+
73+
if !info.Mode().IsRegular() {
74+
return nil
75+
}
76+
77+
rel := file
78+
79+
if dir != "." {
80+
rel = file[len(dir)+1:]
81+
}
82+
83+
f := filepath.Join(prefix, rel)
84+
85+
files = append(files, filepath.ToSlash(f))
86+
87+
return nil
88+
})
89+
if err != nil {
90+
return nil, err
91+
}
92+
return files, nil
93+
}

generated_src/golangcilint/internal/github.com/golangci/golangci-lint/v2/pkg/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func forceRootParsePersistentFlags() (*rootOptions, error) {
127127
fs := pflag.NewFlagSet("config flag set", pflag.ContinueOnError)
128128

129129
// Ignore unknown flags because we will parse the command flags later.
130-
fs.ParseErrorsWhitelist = pflag.ParseErrorsWhitelist{UnknownFlags: true}
130+
fs.ParseErrorsAllowlist = pflag.ParseErrorsAllowlist{UnknownFlags: true}
131131

132132
opts := &rootOptions{}
133133

0 commit comments

Comments
 (0)