From ae66746dfeef40447c4a620477a55a5728102656 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 10:29:09 -0500 Subject: [PATCH 1/9] Add no-pointer-to-string-slice custom linter Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- tools/go.mod | 2 + tools/go.sum | 4 ++ tools/no-pointer-to-string-slice/main.go | 56 +++++++++++++++++++ tools/no-pointer-to-string-slice/main_test.go | 12 ++++ .../testdata/src/a/main.go | 10 ++++ .../testdata/src/b/main.go | 10 ++++ .../testdata/src/c/main.go | 9 +++ 7 files changed, 103 insertions(+) create mode 100644 tools/no-pointer-to-string-slice/main.go create mode 100644 tools/no-pointer-to-string-slice/main_test.go create mode 100644 tools/no-pointer-to-string-slice/testdata/src/a/main.go create mode 100644 tools/no-pointer-to-string-slice/testdata/src/b/main.go create mode 100644 tools/no-pointer-to-string-slice/testdata/src/c/main.go diff --git a/tools/go.mod b/tools/go.mod index 188a79ce51f..4485d50cab0 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -8,6 +8,7 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/go-github/v68 v68.0.0 golang.org/x/sync v0.10.0 + golang.org/x/tools v0.29.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -21,6 +22,7 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect + golang.org/x/mod v0.22.0 // indirect ) // Use version at HEAD, not the latest published. diff --git a/tools/go.sum b/tools/go.sum index 3073cf11c8f..72ab7e6e0e6 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -43,8 +43,12 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= +golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/tools/no-pointer-to-string-slice/main.go b/tools/no-pointer-to-string-slice/main.go new file mode 100644 index 00000000000..2a76f8a4e6a --- /dev/null +++ b/tools/no-pointer-to-string-slice/main.go @@ -0,0 +1,56 @@ +// no-pointer-to-string-slice is a custom linter to be used by +// golangci-lint to find instances of `[]*string` and report +// that they should be changed to `[]string`. +package main + +import ( + "go/ast" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/singlechecker" +) + +var Analyzer = &analysis.Analyzer{ + Name: "noPointerToStringSlice", + Doc: "reports usage of []*string and suggests using []string instead", + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + for _, file := range pass.Files { + ast.Inspect(file, func(n ast.Node) bool { + // Check for []*string in array types + if arrType, ok := n.(*ast.ArrayType); ok { + if starExpr, ok := arrType.Elt.(*ast.StarExpr); ok { + if ident, ok := starExpr.X.(*ast.Ident); ok && ident.Name == "string" { + msg := "use []string instead of []*string" + pass.Reportf(arrType.Pos(), msg) + println("Reported:", msg) // Debugging output + } + } + } + + // Check for []*string in struct fields + if structType, ok := n.(*ast.StructType); ok { + for _, field := range structType.Fields.List { + if arrType, ok := field.Type.(*ast.ArrayType); ok { + if starExpr, ok := arrType.Elt.(*ast.StarExpr); ok { + if ident, ok := starExpr.X.(*ast.Ident); ok && ident.Name == "string" { + msg := "use []string instead of []*string in struct fields" + pass.Reportf(field.Pos(), msg) + println("Reported:", msg) // Debugging output + } + } + } + } + } + + return true + }) + } + return nil, nil +} + +func main() { + singlechecker.Main(Analyzer) +} diff --git a/tools/no-pointer-to-string-slice/main_test.go b/tools/no-pointer-to-string-slice/main_test.go new file mode 100644 index 00000000000..5c288e5b8c4 --- /dev/null +++ b/tools/no-pointer-to-string-slice/main_test.go @@ -0,0 +1,12 @@ +package main + +import ( + "testing" + + "golang.org/x/tools/go/analysis/analysistest" +) + +func TestRun(t *testing.T) { + testdata := analysistest.TestData() + analysistest.Run(t, testdata, Analyzer, "a", "b", "c") +} diff --git a/tools/no-pointer-to-string-slice/testdata/src/a/main.go b/tools/no-pointer-to-string-slice/testdata/src/a/main.go new file mode 100644 index 00000000000..accededdcfe --- /dev/null +++ b/tools/no-pointer-to-string-slice/testdata/src/a/main.go @@ -0,0 +1,10 @@ +package main + +type Example struct { + Names []*string // want `use \[\]string instead of \[\]\*string in struct fields` +} + +func main() { + slice := []*string{} // want `use \[\]string instead of \[\]\*string` + _ = slice +} diff --git a/tools/no-pointer-to-string-slice/testdata/src/b/main.go b/tools/no-pointer-to-string-slice/testdata/src/b/main.go new file mode 100644 index 00000000000..89ba9732191 --- /dev/null +++ b/tools/no-pointer-to-string-slice/testdata/src/b/main.go @@ -0,0 +1,10 @@ +package main + +// type Example struct { +// Names []string // Should not be flagged +// } + +// func main() { +// slice := []string{} // Should not be flagged +// _ = slice +// } diff --git a/tools/no-pointer-to-string-slice/testdata/src/c/main.go b/tools/no-pointer-to-string-slice/testdata/src/c/main.go new file mode 100644 index 00000000000..1e4b30f2520 --- /dev/null +++ b/tools/no-pointer-to-string-slice/testdata/src/c/main.go @@ -0,0 +1,9 @@ +package main + +// type Inner struct { +// Values []*string // Should be flagged +// } + +// type Outer struct { +// Inner Inner // Should not be flagged (no []*string directly) +// } From 4bb1671244db345ffc87be32f98d0a1e07163373 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:58:22 -0500 Subject: [PATCH 2/9] Add sliceofpointers custom linter Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- .custom-gcl.yml | 4 ++ .golangci.yml | 29 ++++++---- tools/no-pointer-to-string-slice/main.go | 56 ------------------- .../testdata/src/a/main.go | 10 ---- .../testdata/src/b/main.go | 10 ---- .../testdata/src/c/main.go | 9 --- tools/sliceofpointers/main.go | 54 ++++++++++++++++++ .../main_test.go | 2 +- .../testdata/src/has-warnings/main.go | 16 ++++++ .../testdata/src/no-warnings/main.go | 16 ++++++ 10 files changed, 108 insertions(+), 98 deletions(-) create mode 100644 .custom-gcl.yml delete mode 100644 tools/no-pointer-to-string-slice/main.go delete mode 100644 tools/no-pointer-to-string-slice/testdata/src/a/main.go delete mode 100644 tools/no-pointer-to-string-slice/testdata/src/b/main.go delete mode 100644 tools/no-pointer-to-string-slice/testdata/src/c/main.go create mode 100644 tools/sliceofpointers/main.go rename tools/{no-pointer-to-string-slice => sliceofpointers}/main_test.go (68%) create mode 100644 tools/sliceofpointers/testdata/src/has-warnings/main.go create mode 100644 tools/sliceofpointers/testdata/src/no-warnings/main.go diff --git a/.custom-gcl.yml b/.custom-gcl.yml new file mode 100644 index 00000000000..93a51359bd5 --- /dev/null +++ b/.custom-gcl.yml @@ -0,0 +1,4 @@ +version: v1.57.0 +plugins: + - module: "github.com/google/go-github/v68/tools/sliceofpointers" + path: ./tools/sliceofpointers/sliceofpointers.so diff --git a/.golangci.yml b/.golangci.yml index eae5a3bdd6a..108b80427a2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,12 +18,17 @@ linters: - perfsprint - paralleltest - revive + - sliceofpointers - stylecheck - tparallel - unconvert - unparam - whitespace linters-settings: + custom: + sliceofpointers: + type: "module" + description: Reports usage of []*string and slices of structs without pointers. gocritic: disable-all: true enabled-checks: @@ -38,7 +43,7 @@ linters-settings: misspell: locale: US ignore-words: - - "analyses" # returned by the GitHub API + - "analyses" # returned by the GitHub API - "cancelled" # returned by the GitHub API # extra words from https://go.dev//wiki/Spelling extra-words: @@ -102,28 +107,28 @@ issues: path: _test\.go # We need to pass nil Context in order to test DoBare erroring on nil ctx. - - linters: [ staticcheck ] - text: 'SA1012: do not pass a nil Context' + - linters: [staticcheck] + text: "SA1012: do not pass a nil Context" path: _test\.go # We need to use sha1 for validating signatures - - linters: [ gosec ] - text: 'G505: Blocklisted import crypto/sha1: weak cryptographic primitive' + - linters: [gosec] + text: "G505: Blocklisted import crypto/sha1: weak cryptographic primitive" # This is adapted from golangci-lint's default exclusions. It disables linting for error checks on # os.RemoveAll, fmt.Fprint*, fmt.Scanf, and any function ending in "Close". - - linters: [ errcheck ] + - linters: [errcheck] text: Error return value of .(.*Close|fmt\.Fprint.*|fmt\.Scanf|os\.Remove(All)?). is not checked # We don't care about file inclusion via variable in examples or internal tools. - - linters: [ gosec ] - text: 'G304: Potential file inclusion via variable' + - linters: [gosec] + text: "G304: Potential file inclusion via variable" path: '^(example|tools)\/' # We don't run parallel integration tests - - linters: [ paralleltest, tparallel ] - path: '^test/integration' + - linters: [paralleltest, tparallel] + path: "^test/integration" # Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10). - - linters: [ perfsprint] - text: 'fmt.Sprint.* can be replaced with faster strconv.FormatInt' + - linters: [perfsprint] + text: "fmt.Sprint.* can be replaced with faster strconv.FormatInt" diff --git a/tools/no-pointer-to-string-slice/main.go b/tools/no-pointer-to-string-slice/main.go deleted file mode 100644 index 2a76f8a4e6a..00000000000 --- a/tools/no-pointer-to-string-slice/main.go +++ /dev/null @@ -1,56 +0,0 @@ -// no-pointer-to-string-slice is a custom linter to be used by -// golangci-lint to find instances of `[]*string` and report -// that they should be changed to `[]string`. -package main - -import ( - "go/ast" - - "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/singlechecker" -) - -var Analyzer = &analysis.Analyzer{ - Name: "noPointerToStringSlice", - Doc: "reports usage of []*string and suggests using []string instead", - Run: run, -} - -func run(pass *analysis.Pass) (interface{}, error) { - for _, file := range pass.Files { - ast.Inspect(file, func(n ast.Node) bool { - // Check for []*string in array types - if arrType, ok := n.(*ast.ArrayType); ok { - if starExpr, ok := arrType.Elt.(*ast.StarExpr); ok { - if ident, ok := starExpr.X.(*ast.Ident); ok && ident.Name == "string" { - msg := "use []string instead of []*string" - pass.Reportf(arrType.Pos(), msg) - println("Reported:", msg) // Debugging output - } - } - } - - // Check for []*string in struct fields - if structType, ok := n.(*ast.StructType); ok { - for _, field := range structType.Fields.List { - if arrType, ok := field.Type.(*ast.ArrayType); ok { - if starExpr, ok := arrType.Elt.(*ast.StarExpr); ok { - if ident, ok := starExpr.X.(*ast.Ident); ok && ident.Name == "string" { - msg := "use []string instead of []*string in struct fields" - pass.Reportf(field.Pos(), msg) - println("Reported:", msg) // Debugging output - } - } - } - } - } - - return true - }) - } - return nil, nil -} - -func main() { - singlechecker.Main(Analyzer) -} diff --git a/tools/no-pointer-to-string-slice/testdata/src/a/main.go b/tools/no-pointer-to-string-slice/testdata/src/a/main.go deleted file mode 100644 index accededdcfe..00000000000 --- a/tools/no-pointer-to-string-slice/testdata/src/a/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -type Example struct { - Names []*string // want `use \[\]string instead of \[\]\*string in struct fields` -} - -func main() { - slice := []*string{} // want `use \[\]string instead of \[\]\*string` - _ = slice -} diff --git a/tools/no-pointer-to-string-slice/testdata/src/b/main.go b/tools/no-pointer-to-string-slice/testdata/src/b/main.go deleted file mode 100644 index 89ba9732191..00000000000 --- a/tools/no-pointer-to-string-slice/testdata/src/b/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -// type Example struct { -// Names []string // Should not be flagged -// } - -// func main() { -// slice := []string{} // Should not be flagged -// _ = slice -// } diff --git a/tools/no-pointer-to-string-slice/testdata/src/c/main.go b/tools/no-pointer-to-string-slice/testdata/src/c/main.go deleted file mode 100644 index 1e4b30f2520..00000000000 --- a/tools/no-pointer-to-string-slice/testdata/src/c/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -// type Inner struct { -// Values []*string // Should be flagged -// } - -// type Outer struct { -// Inner Inner // Should not be flagged (no []*string directly) -// } diff --git a/tools/sliceofpointers/main.go b/tools/sliceofpointers/main.go new file mode 100644 index 00000000000..1e66e33bb8e --- /dev/null +++ b/tools/sliceofpointers/main.go @@ -0,0 +1,54 @@ +// sliceofpointers is a custom linter to be used by +// golangci-lint to find instances of `[]*string` and +// slices of structs without pointers and report them. +// See: https://github.com/google/go-github/issues/180 +package main + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/singlechecker" +) + +var analyzer = &analysis.Analyzer{ + Name: "sliceofpointers", + Doc: "reports usage of []*string and slices of structs without pointers", + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + for _, file := range pass.Files { + ast.Inspect(file, func(n ast.Node) bool { + if n == nil { + return false + } + + switch t := n.(type) { + case *ast.ArrayType: + checkArrayType(t, t.Pos(), pass) + } + + return true + }) + } + return nil, nil +} + +func checkArrayType(arrType *ast.ArrayType, tokenPos token.Pos, pass *analysis.Pass) { + if starExpr, ok := arrType.Elt.(*ast.StarExpr); ok { + if ident, ok := starExpr.X.(*ast.Ident); ok && ident.Name == "string" { + const msg = "use []string instead of []*string" + pass.Reportf(tokenPos, msg) + } + } else if ident, ok := arrType.Elt.(*ast.Ident); ok && ident.Obj != nil { + if _, ok := ident.Obj.Decl.(*ast.TypeSpec).Type.(*ast.StructType); ok { + pass.Reportf(tokenPos, "use []*%v instead of []%[1]v", ident.Name) + } + } +} + +func main() { + singlechecker.Main(analyzer) +} diff --git a/tools/no-pointer-to-string-slice/main_test.go b/tools/sliceofpointers/main_test.go similarity index 68% rename from tools/no-pointer-to-string-slice/main_test.go rename to tools/sliceofpointers/main_test.go index 5c288e5b8c4..d354a39ed84 100644 --- a/tools/no-pointer-to-string-slice/main_test.go +++ b/tools/sliceofpointers/main_test.go @@ -8,5 +8,5 @@ import ( func TestRun(t *testing.T) { testdata := analysistest.TestData() - analysistest.Run(t, testdata, Analyzer, "a", "b", "c") + analysistest.Run(t, testdata, analyzer, "has-warnings", "no-warnings") } diff --git a/tools/sliceofpointers/testdata/src/has-warnings/main.go b/tools/sliceofpointers/testdata/src/has-warnings/main.go new file mode 100644 index 00000000000..83544fc8415 --- /dev/null +++ b/tools/sliceofpointers/testdata/src/has-warnings/main.go @@ -0,0 +1,16 @@ +package main + +type Example struct { + Strings []*string `json:"strings,omitempty"` // want `use \[\]string instead of \[\]\*string` + Things []Thing `json:"things,omitempty"` // want `use \[\]\*Thing instead of \[\]Thing` +} + +type Thing struct { +} + +func main() { + slice1 := []*string{} // want `use \[\]string instead of \[\]\*string` + _ = slice1 + slice2 := []Thing{} // want `use \[\]\*Thing instead of \[\]Thing` + _ = slice2 +} diff --git a/tools/sliceofpointers/testdata/src/no-warnings/main.go b/tools/sliceofpointers/testdata/src/no-warnings/main.go new file mode 100644 index 00000000000..d37b849d221 --- /dev/null +++ b/tools/sliceofpointers/testdata/src/no-warnings/main.go @@ -0,0 +1,16 @@ +package main + +type Example struct { + Strings []string `json:"strings,omitempty"` // Should not be flagged + Things []*Thing `json:"things,omitempty"` // Should not be flagged +} + +type Thing struct { +} + +func main() { + slice1 := []string{} // Should not be flagged + _ = slice1 + slice2 := []*Thing{} // Should not be flagged + _ = slice2 +} From b22d8b85526894f07b5263e966f2f983eb1aef2b Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:37:29 -0500 Subject: [PATCH 3/9] Follow example at https://github.com/golangci/example-plugin-module-linter Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- .custom-gcl.yml | 4 -- .golangci.yml | 3 +- tools/go.mod | 1 + tools/go.sum | 2 + tools/sliceofpointers/main_test.go | 12 ------ .../{main.go => sliceofpointers.go} | 37 +++++++++++++------ tools/sliceofpointers/sliceofpointers_test.go | 14 +++++++ 7 files changed, 45 insertions(+), 28 deletions(-) delete mode 100644 .custom-gcl.yml delete mode 100644 tools/sliceofpointers/main_test.go rename tools/sliceofpointers/{main.go => sliceofpointers.go} (59%) create mode 100644 tools/sliceofpointers/sliceofpointers_test.go diff --git a/.custom-gcl.yml b/.custom-gcl.yml deleted file mode 100644 index 93a51359bd5..00000000000 --- a/.custom-gcl.yml +++ /dev/null @@ -1,4 +0,0 @@ -version: v1.57.0 -plugins: - - module: "github.com/google/go-github/v68/tools/sliceofpointers" - path: ./tools/sliceofpointers/sliceofpointers.so diff --git a/.golangci.yml b/.golangci.yml index 108b80427a2..fae768c5a57 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,8 +27,9 @@ linters: linters-settings: custom: sliceofpointers: - type: "module" + type: module description: Reports usage of []*string and slices of structs without pointers. + original-url: github.com/google/go-github/v68/tools/sliceofpointers gocritic: disable-all: true enabled-checks: diff --git a/tools/go.mod b/tools/go.mod index 4485d50cab0..a59f96573d0 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -5,6 +5,7 @@ go 1.22.0 require ( github.com/alecthomas/kong v1.6.0 github.com/getkin/kin-openapi v0.128.0 + github.com/golangci/plugin-module-register v0.1.1 github.com/google/go-cmp v0.6.0 github.com/google/go-github/v68 v68.0.0 golang.org/x/sync v0.10.0 diff --git a/tools/go.sum b/tools/go.sum index 72ab7e6e0e6..60fe1c17c1a 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -14,6 +14,8 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +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/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/tools/sliceofpointers/main_test.go b/tools/sliceofpointers/main_test.go deleted file mode 100644 index d354a39ed84..00000000000 --- a/tools/sliceofpointers/main_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "testing" - - "golang.org/x/tools/go/analysis/analysistest" -) - -func TestRun(t *testing.T) { - testdata := analysistest.TestData() - analysistest.Run(t, testdata, analyzer, "has-warnings", "no-warnings") -} diff --git a/tools/sliceofpointers/main.go b/tools/sliceofpointers/sliceofpointers.go similarity index 59% rename from tools/sliceofpointers/main.go rename to tools/sliceofpointers/sliceofpointers.go index 1e66e33bb8e..9e088ebf43a 100644 --- a/tools/sliceofpointers/main.go +++ b/tools/sliceofpointers/sliceofpointers.go @@ -1,21 +1,40 @@ -// sliceofpointers is a custom linter to be used by +// Package sliceofpointers is a custom linter to be used by // golangci-lint to find instances of `[]*string` and // slices of structs without pointers and report them. // See: https://github.com/google/go-github/issues/180 -package main +package sliceofpointers import ( "go/ast" "go/token" + "github.com/golangci/plugin-module-register/register" "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/singlechecker" ) -var analyzer = &analysis.Analyzer{ - Name: "sliceofpointers", - Doc: "reports usage of []*string and slices of structs without pointers", - Run: run, +func init() { + register.Plugin("sliceofpointers", New) +} + +type SliceOfPointersPlugin struct{} + +// New returns an analysis.Analyzer to use with golangci-lint +func New(settings any) (register.LinterPlugin, error) { + return &SliceOfPointersPlugin{}, nil +} + +func (f *SliceOfPointersPlugin) BuildAnalyzers() ([]*analysis.Analyzer, error) { + return []*analysis.Analyzer{ + { + Name: "sliceofpointers", + Doc: "Reports usage of []*string and slices of structs without pointers.", + Run: run, + }, + }, nil +} + +func (f *SliceOfPointersPlugin) GetLoadMode() string { + return register.LoadModeSyntax } func run(pass *analysis.Pass) (interface{}, error) { @@ -48,7 +67,3 @@ func checkArrayType(arrType *ast.ArrayType, tokenPos token.Pos, pass *analysis.P } } } - -func main() { - singlechecker.Main(analyzer) -} diff --git a/tools/sliceofpointers/sliceofpointers_test.go b/tools/sliceofpointers/sliceofpointers_test.go new file mode 100644 index 00000000000..9989c3985df --- /dev/null +++ b/tools/sliceofpointers/sliceofpointers_test.go @@ -0,0 +1,14 @@ +package sliceofpointers + +import ( + "testing" + + "golang.org/x/tools/go/analysis/analysistest" +) + +func TestRun(t *testing.T) { + testdata := analysistest.TestData() + plugin, _ := New(nil) + analyzers, _ := plugin.BuildAnalyzers() + analysistest.Run(t, testdata, analyzers[0], "has-warnings", "no-warnings") +} From e07bebd99ea42b55645d42ea8d4f81fc0d45445a Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:40:00 -0500 Subject: [PATCH 4/9] Add .custom-gcl.yml and go.mod Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- .custom-gcl.yml | 4 ++++ tools/sliceofpointers/go.mod | 13 +++++++++++++ tools/sliceofpointers/go.sum | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 .custom-gcl.yml create mode 100644 tools/sliceofpointers/go.mod create mode 100644 tools/sliceofpointers/go.sum diff --git a/.custom-gcl.yml b/.custom-gcl.yml new file mode 100644 index 00000000000..ef66b2066fe --- /dev/null +++ b/.custom-gcl.yml @@ -0,0 +1,4 @@ +version: v1.57.0 +plugins: + - module: "github.com/google/go-github/v68/tools/sliceofpointers" + path: ./tools/sliceofpointers diff --git a/tools/sliceofpointers/go.mod b/tools/sliceofpointers/go.mod new file mode 100644 index 00000000000..759fa734d9e --- /dev/null +++ b/tools/sliceofpointers/go.mod @@ -0,0 +1,13 @@ +module tools/sliceofpointers + +go 1.22.0 + +require ( + github.com/golangci/plugin-module-register v0.1.1 + golang.org/x/tools v0.29.0 +) + +require ( + golang.org/x/mod v0.22.0 // indirect + golang.org/x/sync v0.10.0 // indirect +) diff --git a/tools/sliceofpointers/go.sum b/tools/sliceofpointers/go.sum new file mode 100644 index 00000000000..c2f7392bb23 --- /dev/null +++ b/tools/sliceofpointers/go.sum @@ -0,0 +1,10 @@ +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/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= +golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= From 5b5afd5b1a3ea0aaf3e6cac5f65d857729661c8f Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:53:17 -0500 Subject: [PATCH 5/9] Update .gitignore Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8e24389445d..b81979c9430 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ vendor/ # goenv local version. See https://github.com/syndbg/goenv/blob/master/COMMANDS.md#goenv-local for more info. .go-version + +# golangci-lint -v custom generates the following local file: +custom-gcl From 7fa7c02119d95db734e3497e77db461f38b8d7c7 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 15:02:34 -0500 Subject: [PATCH 6/9] go mod tidy Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- tools/go.mod | 3 --- tools/go.sum | 6 ------ 2 files changed, 9 deletions(-) diff --git a/tools/go.mod b/tools/go.mod index a59f96573d0..188a79ce51f 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -5,11 +5,9 @@ go 1.22.0 require ( github.com/alecthomas/kong v1.6.0 github.com/getkin/kin-openapi v0.128.0 - github.com/golangci/plugin-module-register v0.1.1 github.com/google/go-cmp v0.6.0 github.com/google/go-github/v68 v68.0.0 golang.org/x/sync v0.10.0 - golang.org/x/tools v0.29.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -23,7 +21,6 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect - golang.org/x/mod v0.22.0 // indirect ) // Use version at HEAD, not the latest published. diff --git a/tools/go.sum b/tools/go.sum index 60fe1c17c1a..3073cf11c8f 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -14,8 +14,6 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= -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/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -45,12 +43,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= -golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE= -golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= From 6bb5c1e523379ce08e4f5ee84e7c46d100acad89 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 16:19:18 -0500 Subject: [PATCH 7/9] Update .custom-gcl.yml Co-authored-by: Ludovic Fernandez --- .custom-gcl.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.custom-gcl.yml b/.custom-gcl.yml index ef66b2066fe..d3bf8857d00 100644 --- a/.custom-gcl.yml +++ b/.custom-gcl.yml @@ -1,4 +1,4 @@ -version: v1.57.0 +version: v1.62.0 plugins: - module: "github.com/google/go-github/v68/tools/sliceofpointers" path: ./tools/sliceofpointers From 1a32bcd3143bb41032594fb11c057180b3159bc7 Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:02:36 -0500 Subject: [PATCH 8/9] Clean linter warnings Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/codespaces_secrets_test.go | 18 +++++++++--------- github/github.go | 3 ++- github/strings_test.go | 1 + scrape/apps.go | 6 +++--- scrape/apps_test.go | 2 +- scrape/forms.go | 4 ++-- scrape/forms_test.go | 16 ++++++++-------- script/lint.sh | 9 +++++---- tools/sliceofpointers/sliceofpointers.go | 2 +- tools/sliceofpointers/sliceofpointers_test.go | 1 + 10 files changed, 33 insertions(+), 29 deletions(-) diff --git a/github/codespaces_secrets_test.go b/github/codespaces_secrets_test.go index 543e0651def..987cfaab612 100644 --- a/github/codespaces_secrets_test.go +++ b/github/codespaces_secrets_test.go @@ -25,7 +25,7 @@ func TestCodespacesService_ListSecrets(t *testing.T) { methodName string } opts := &ListOptions{Page: 2, PerPage: 2} - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -128,7 +128,7 @@ func TestCodespacesService_GetSecret(t *testing.T) { badCall func(context.Context, *Client) (*Secret, *Response, error) methodName string } - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -222,7 +222,7 @@ func TestCodespacesService_CreateOrUpdateSecret(t *testing.T) { badCall func(context.Context, *Client, *EncryptedSecret) (*Response, error) methodName string } - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -318,7 +318,7 @@ func TestCodespacesService_DeleteSecret(t *testing.T) { badCall func(context.Context, *Client) (*Response, error) methodName string } - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -401,7 +401,7 @@ func TestCodespacesService_GetPublicKey(t *testing.T) { methodName string } - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -496,7 +496,7 @@ func TestCodespacesService_ListSelectedReposForSecret(t *testing.T) { methodName string } opts := &ListOptions{Page: 2, PerPage: 2} - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -581,7 +581,7 @@ func TestCodespacesService_SetSelectedReposForSecret(t *testing.T) { methodName string } ids := SelectedRepoIDs{64780797} - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -653,7 +653,7 @@ func TestCodespacesService_AddSelectedReposForSecret(t *testing.T) { methodName string } repo := &Repository{ID: Ptr(int64(1234))} - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { @@ -721,7 +721,7 @@ func TestCodespacesService_RemoveSelectedReposFromSecret(t *testing.T) { methodName string } repo := &Repository{ID: Ptr(int64(1234))} - tests := []test{ + tests := []*test{ { name: "User", handleFunc: func(mux *http.ServeMux) { diff --git a/github/github.go b/github/github.go index d4ba320aa5d..ab74c5b72da 100644 --- a/github/github.go +++ b/github/github.go @@ -1117,7 +1117,8 @@ GitHub API docs: https://docs.github.com/rest/#client-errors type ErrorResponse struct { Response *http.Response `json:"-"` // HTTP response that caused this error Message string `json:"message"` // error message - Errors []Error `json:"errors"` // more detail on individual errors + //nolint:sliceofpointers + Errors []Error `json:"errors"` // more detail on individual errors // Block is only populated on certain types of errors such as code 451. Block *ErrorBlock `json:"block,omitempty"` // Most errors will also include a documentation_url field pointing diff --git a/github/strings_test.go b/github/strings_test.go index 4d53f21aac6..a164cebcac0 100644 --- a/github/strings_test.go +++ b/github/strings_test.go @@ -49,6 +49,7 @@ func TestStringify(t *testing.T) { {Ptr(123), `123`}, {Ptr(false), `false`}, { + //nolint:sliceofpointers []*string{Ptr("a"), Ptr("b")}, `["a" "b"]`, }, diff --git a/scrape/apps.go b/scrape/apps.go index fe99ea84a03..686cf773800 100644 --- a/scrape/apps.go +++ b/scrape/apps.go @@ -46,13 +46,13 @@ func (c *Client) AppRestrictionsEnabled(org string) (bool, error) { // ListOAuthApps lists the reviewed OAuth Applications for the // specified organization (whether approved or denied). -func (c *Client) ListOAuthApps(org string) ([]OAuthApp, error) { +func (c *Client) ListOAuthApps(org string) ([]*OAuthApp, error) { doc, err := c.get("/organizations/%s/settings/oauth_application_policy", org) if err != nil { return nil, err } - var apps []OAuthApp + var apps []*OAuthApp doc.Find(".oauth-application-allowlist ul > li").Each(func(i int, s *goquery.Selection) { var app OAuthApp app.Name = s.Find(".request-info strong").First().Text() @@ -73,7 +73,7 @@ func (c *Client) ListOAuthApps(org string) ([]OAuthApp, error) { } else if r := s.Find(".request-indicator .denied-request"); r.Length() > 0 { app.State = OAuthAppDenied } - apps = append(apps, app) + apps = append(apps, &app) }) return apps, nil diff --git a/scrape/apps_test.go b/scrape/apps_test.go index ae5b191eed8..7e9688e5efb 100644 --- a/scrape/apps_test.go +++ b/scrape/apps_test.go @@ -61,7 +61,7 @@ func Test_ListOAuthApps(t *testing.T) { if err != nil { t.Fatalf("ListOAuthApps(e) returned err: %v", err) } - want := []OAuthApp{ + want := []*OAuthApp{ { ID: 22222, Name: "Coveralls", diff --git a/scrape/forms.go b/scrape/forms.go index 6e01171e155..7beb46cf6e1 100644 --- a/scrape/forms.go +++ b/scrape/forms.go @@ -35,7 +35,7 @@ type htmlForm struct { // // In the future, we might want to allow a custom selector to be passed in to // further restrict what forms will be returned. -func parseForms(node *html.Node) (forms []htmlForm) { +func parseForms(node *html.Node) (forms []*htmlForm) { if node == nil { return nil } @@ -71,7 +71,7 @@ func parseForms(node *html.Node) (forms []htmlForm) { value := s.Text() form.Values.Add(name, value) }) - forms = append(forms, form) + forms = append(forms, &form) }) return forms diff --git a/scrape/forms_test.go b/scrape/forms_test.go index 28c30c6c670..b10f250127d 100644 --- a/scrape/forms_test.go +++ b/scrape/forms_test.go @@ -16,14 +16,14 @@ func Test_ParseForms(t *testing.T) { tests := []struct { description string html string - forms []htmlForm + forms []*htmlForm }{ {"no forms", ``, nil}, - {"empty form", `
`, []htmlForm{{Values: url.Values{}}}}, + {"empty form", `
`, []*htmlForm{{Values: url.Values{}}}}, { "single form with one value", `
`, - []htmlForm{{Action: "a", Method: "m", Values: url.Values{"n1": {"v1"}}}}, + []*htmlForm{{Action: "a", Method: "m", Values: url.Values{"n1": {"v1"}}}}, }, { "two forms", @@ -31,7 +31,7 @@ func Test_ParseForms(t *testing.T) {
`, - []htmlForm{ + []*htmlForm{ {Action: "a1", Method: "m1", Values: url.Values{"n1": {"v1"}}}, {Action: "a2", Method: "m2", Values: url.Values{"n2": {"v2"}}}, }, @@ -43,7 +43,7 @@ func Test_ParseForms(t *testing.T) { `, - []htmlForm{{Values: url.Values{}}}, + []*htmlForm{{Values: url.Values{}}}, }, { "form with radio buttons", @@ -52,7 +52,7 @@ func Test_ParseForms(t *testing.T) { `, - []htmlForm{{Values: url.Values{"n1": {"v3"}}}}, + []*htmlForm{{Values: url.Values{"n1": {"v3"}}}}, }, { "form with checkboxes", @@ -61,12 +61,12 @@ func Test_ParseForms(t *testing.T) { `, - []htmlForm{{Values: url.Values{"n1": {"v1"}, "n3": {"v3"}}}}, + []*htmlForm{{Values: url.Values{"n1": {"v1"}, "n3": {"v3"}}}}, }, { "single form with textarea", `
`, - []htmlForm{{Values: url.Values{"n1": {"v1"}}}}, + []*htmlForm{{Values: url.Values{"n1": {"v1"}}}}, }, } diff --git a/script/lint.sh b/script/lint.sh index a52e9bfa2b6..8decafeb7e5 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -19,9 +19,10 @@ fail() { EXIT_CODE=1 } -# install golangci-lint bin/golangci-lint doesn't exist with the correct version -if ! "$BIN"/golangci-lint --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then +# install golangci-lint and custom-gcl in ./bin if they don't exist with the correct version +if ! "$BIN"/custom-gcl --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" + "$BIN"/golangci-lint custom && mv ./custom-gcl "$BIN" fi MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" @@ -33,9 +34,9 @@ for dir in $MOD_DIRS; do cd "$dir" # github actions output when running in an action if [ -n "$GITHUB_ACTIONS" ]; then - "$BIN"/golangci-lint run --path-prefix "$dir" --out-format colored-line-number + "$BIN"/custom-gcl run --path-prefix "$dir" --out-format colored-line-number else - "$BIN"/golangci-lint run --path-prefix "$dir" + "$BIN"/custom-gcl run --path-prefix "$dir" fi ) || fail "failed linting $dir" done diff --git a/tools/sliceofpointers/sliceofpointers.go b/tools/sliceofpointers/sliceofpointers.go index 9e088ebf43a..65a023a4fde 100644 --- a/tools/sliceofpointers/sliceofpointers.go +++ b/tools/sliceofpointers/sliceofpointers.go @@ -18,7 +18,7 @@ func init() { type SliceOfPointersPlugin struct{} -// New returns an analysis.Analyzer to use with golangci-lint +// New returns an analysis.Analyzer to use with golangci-lint. func New(settings any) (register.LinterPlugin, error) { return &SliceOfPointersPlugin{}, nil } diff --git a/tools/sliceofpointers/sliceofpointers_test.go b/tools/sliceofpointers/sliceofpointers_test.go index 9989c3985df..d771ece9ffe 100644 --- a/tools/sliceofpointers/sliceofpointers_test.go +++ b/tools/sliceofpointers/sliceofpointers_test.go @@ -7,6 +7,7 @@ import ( ) func TestRun(t *testing.T) { + t.Parallel() testdata := analysistest.TestData() plugin, _ := New(nil) analyzers, _ := plugin.BuildAnalyzers() From 15174dfd14fa5099f40313e2ae8126d86e913fca Mon Sep 17 00:00:00 2001 From: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:10:58 -0500 Subject: [PATCH 9/9] Update copyright notices Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- tools/sliceofpointers/sliceofpointers.go | 5 +++++ tools/sliceofpointers/sliceofpointers_test.go | 5 +++++ tools/sliceofpointers/testdata/src/has-warnings/main.go | 5 +++++ tools/sliceofpointers/testdata/src/no-warnings/main.go | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/tools/sliceofpointers/sliceofpointers.go b/tools/sliceofpointers/sliceofpointers.go index 65a023a4fde..d6a59b38f28 100644 --- a/tools/sliceofpointers/sliceofpointers.go +++ b/tools/sliceofpointers/sliceofpointers.go @@ -1,3 +1,8 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + // Package sliceofpointers is a custom linter to be used by // golangci-lint to find instances of `[]*string` and // slices of structs without pointers and report them. diff --git a/tools/sliceofpointers/sliceofpointers_test.go b/tools/sliceofpointers/sliceofpointers_test.go index d771ece9ffe..8fb0787f022 100644 --- a/tools/sliceofpointers/sliceofpointers_test.go +++ b/tools/sliceofpointers/sliceofpointers_test.go @@ -1,3 +1,8 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package sliceofpointers import ( diff --git a/tools/sliceofpointers/testdata/src/has-warnings/main.go b/tools/sliceofpointers/testdata/src/has-warnings/main.go index 83544fc8415..84e0d024e4b 100644 --- a/tools/sliceofpointers/testdata/src/has-warnings/main.go +++ b/tools/sliceofpointers/testdata/src/has-warnings/main.go @@ -1,3 +1,8 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main type Example struct { diff --git a/tools/sliceofpointers/testdata/src/no-warnings/main.go b/tools/sliceofpointers/testdata/src/no-warnings/main.go index d37b849d221..529d1d2fdad 100644 --- a/tools/sliceofpointers/testdata/src/no-warnings/main.go +++ b/tools/sliceofpointers/testdata/src/no-warnings/main.go @@ -1,3 +1,8 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package main type Example struct {