From d920feb2cc11cfdd5cd9d03f74dd205b054e8d50 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Tue, 30 Jan 2024 16:59:38 +0100 Subject: [PATCH 1/2] Consolidate linters into single binary --- Makefile | 4 +--- {linter => linters}/koanf/handlers.go | 2 +- {linter => linters}/koanf/koanf.go | 7 +------ {linter => linters}/koanf/koanf_test.go | 2 +- linters/linters.go | 18 ++++++++++++++++++ .../pointercheck/pointercheck.go | 7 +------ .../pointercheck/pointercheck_test.go | 2 +- {linter => linters}/rightshift/rightshift.go | 7 +------ .../rightshift/rightshift_test.go | 2 +- {linter => linters}/structinit/structinit.go | 7 +------ .../structinit/structinit_test.go | 2 +- {linter => linters}/testdata/src/koanf/a/a.go | 0 {linter => linters}/testdata/src/koanf/b/b.go | 0 .../testdata/src/pointercheck/pointercheck.go | 0 .../testdata/src/rightshift/rightshift.go | 0 .../testdata/src/structinit/a/a.go | 0 16 files changed, 28 insertions(+), 32 deletions(-) rename {linter => linters}/koanf/handlers.go (99%) rename {linter => linters}/koanf/koanf.go (95%) rename {linter => linters}/koanf/koanf_test.go (99%) create mode 100644 linters/linters.go rename linter/pointercheck/pointer.go => linters/pointercheck/pointercheck.go (95%) rename linter/pointercheck/pointer_test.go => linters/pointercheck/pointercheck_test.go (96%) rename {linter => linters}/rightshift/rightshift.go (94%) rename {linter => linters}/rightshift/rightshift_test.go (97%) rename {linter => linters}/structinit/structinit.go (96%) rename {linter => linters}/structinit/structinit_test.go (97%) rename {linter => linters}/testdata/src/koanf/a/a.go (100%) rename {linter => linters}/testdata/src/koanf/b/b.go (100%) rename {linter => linters}/testdata/src/pointercheck/pointercheck.go (100%) rename {linter => linters}/testdata/src/rightshift/rightshift.go (100%) rename {linter => linters}/testdata/src/structinit/a/a.go (100%) diff --git a/Makefile b/Makefile index 956ab0c357..d03b940726 100644 --- a/Makefile +++ b/Makefile @@ -311,9 +311,7 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(arbitrator_pro # strategic rules to minimize dependency building .make/lint: $(DEP_PREDICATE) build-node-deps $(ORDER_ONLY_PREDICATE) .make - go run ./linter/koanf ./... - go run ./linter/pointercheck ./... - go run ./linter/rightshift ./... + go run ./linters ./... golangci-lint run --fix yarn --cwd contracts solhint @touch $@ diff --git a/linter/koanf/handlers.go b/linters/koanf/handlers.go similarity index 99% rename from linter/koanf/handlers.go rename to linters/koanf/handlers.go index 5826004014..5ee3b80f9f 100644 --- a/linter/koanf/handlers.go +++ b/linters/koanf/handlers.go @@ -1,4 +1,4 @@ -package main +package koanf import ( "fmt" diff --git a/linter/koanf/koanf.go b/linters/koanf/koanf.go similarity index 95% rename from linter/koanf/koanf.go rename to linters/koanf/koanf.go index f09fdd3d05..e53064b6b3 100644 --- a/linter/koanf/koanf.go +++ b/linters/koanf/koanf.go @@ -1,4 +1,4 @@ -package main +package koanf import ( "errors" @@ -8,7 +8,6 @@ import ( "reflect" "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/singlechecker" ) var ( @@ -97,7 +96,3 @@ func run(dryRun bool, pass *analysis.Pass) (interface{}, error) { } return ret, nil } - -func main() { - singlechecker.Main(Analyzer) -} diff --git a/linter/koanf/koanf_test.go b/linters/koanf/koanf_test.go similarity index 99% rename from linter/koanf/koanf_test.go rename to linters/koanf/koanf_test.go index 0840ae5217..9029951dfa 100644 --- a/linter/koanf/koanf_test.go +++ b/linters/koanf/koanf_test.go @@ -1,4 +1,4 @@ -package main +package koanf import ( "errors" diff --git a/linters/linters.go b/linters/linters.go new file mode 100644 index 0000000000..a6c9f6d55e --- /dev/null +++ b/linters/linters.go @@ -0,0 +1,18 @@ +package main + +import ( + "github.com/offchainlabs/nitro/linters/koanf" + "github.com/offchainlabs/nitro/linters/pointercheck" + "github.com/offchainlabs/nitro/linters/rightshift" + "github.com/offchainlabs/nitro/linters/structinit" + "golang.org/x/tools/go/analysis/multichecker" +) + +func main() { + multichecker.Main( + koanf.Analyzer, + pointercheck.Analyzer, + rightshift.Analyzer, + structinit.Analyzer, + ) +} diff --git a/linter/pointercheck/pointer.go b/linters/pointercheck/pointercheck.go similarity index 95% rename from linter/pointercheck/pointer.go rename to linters/pointercheck/pointercheck.go index 4da2d8cc21..682ebd9357 100644 --- a/linter/pointercheck/pointer.go +++ b/linters/pointercheck/pointercheck.go @@ -1,4 +1,4 @@ -package main +package pointercheck import ( "fmt" @@ -8,7 +8,6 @@ import ( "reflect" "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/singlechecker" ) var Analyzer = &analysis.Analyzer{ @@ -90,7 +89,3 @@ func ptrIdent(pass *analysis.Pass, e ast.Expr) bool { } return false } - -func main() { - singlechecker.Main(Analyzer) -} diff --git a/linter/pointercheck/pointer_test.go b/linters/pointercheck/pointercheck_test.go similarity index 96% rename from linter/pointercheck/pointer_test.go rename to linters/pointercheck/pointercheck_test.go index 47d5c63014..24f4534bca 100644 --- a/linter/pointercheck/pointer_test.go +++ b/linters/pointercheck/pointercheck_test.go @@ -1,4 +1,4 @@ -package main +package pointercheck import ( "os" diff --git a/linter/rightshift/rightshift.go b/linters/rightshift/rightshift.go similarity index 94% rename from linter/rightshift/rightshift.go rename to linters/rightshift/rightshift.go index f50d8a25ac..d6fcbfec6c 100644 --- a/linter/rightshift/rightshift.go +++ b/linters/rightshift/rightshift.go @@ -1,4 +1,4 @@ -package main +package rightshift import ( "go/ast" @@ -6,7 +6,6 @@ import ( "reflect" "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/singlechecker" ) var Analyzer = &analysis.Analyzer{ @@ -70,7 +69,3 @@ func isOne(expr ast.Expr) bool { bl, ok := expr.(*ast.BasicLit) return ok && bl.Kind == token.INT && bl.Value == "1" } - -func main() { - singlechecker.Main(Analyzer) -} diff --git a/linter/rightshift/rightshift_test.go b/linters/rightshift/rightshift_test.go similarity index 97% rename from linter/rightshift/rightshift_test.go rename to linters/rightshift/rightshift_test.go index 41555c068f..3640d79975 100644 --- a/linter/rightshift/rightshift_test.go +++ b/linters/rightshift/rightshift_test.go @@ -1,4 +1,4 @@ -package main +package rightshift import ( "os" diff --git a/linter/structinit/structinit.go b/linters/structinit/structinit.go similarity index 96% rename from linter/structinit/structinit.go rename to linters/structinit/structinit.go index 31baf1c90e..236b8747b2 100644 --- a/linter/structinit/structinit.go +++ b/linters/structinit/structinit.go @@ -1,4 +1,4 @@ -package main +package structinit import ( "fmt" @@ -8,7 +8,6 @@ import ( "strings" "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/singlechecker" ) // Tip for linter that struct that has this comment should be included in the @@ -112,7 +111,3 @@ type position struct { fileName string line int } - -func main() { - singlechecker.Main(Analyzer) -} diff --git a/linter/structinit/structinit_test.go b/linters/structinit/structinit_test.go similarity index 97% rename from linter/structinit/structinit_test.go rename to linters/structinit/structinit_test.go index df8588a58f..57dfc2b000 100644 --- a/linter/structinit/structinit_test.go +++ b/linters/structinit/structinit_test.go @@ -1,4 +1,4 @@ -package main +package structinit import ( "os" diff --git a/linter/testdata/src/koanf/a/a.go b/linters/testdata/src/koanf/a/a.go similarity index 100% rename from linter/testdata/src/koanf/a/a.go rename to linters/testdata/src/koanf/a/a.go diff --git a/linter/testdata/src/koanf/b/b.go b/linters/testdata/src/koanf/b/b.go similarity index 100% rename from linter/testdata/src/koanf/b/b.go rename to linters/testdata/src/koanf/b/b.go diff --git a/linter/testdata/src/pointercheck/pointercheck.go b/linters/testdata/src/pointercheck/pointercheck.go similarity index 100% rename from linter/testdata/src/pointercheck/pointercheck.go rename to linters/testdata/src/pointercheck/pointercheck.go diff --git a/linter/testdata/src/rightshift/rightshift.go b/linters/testdata/src/rightshift/rightshift.go similarity index 100% rename from linter/testdata/src/rightshift/rightshift.go rename to linters/testdata/src/rightshift/rightshift.go diff --git a/linter/testdata/src/structinit/a/a.go b/linters/testdata/src/structinit/a/a.go similarity index 100% rename from linter/testdata/src/structinit/a/a.go rename to linters/testdata/src/structinit/a/a.go From 68d8534e96f7a5bb3c8a3b582df527602263dbcd Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Tue, 30 Jan 2024 17:13:55 +0100 Subject: [PATCH 2/2] Update Go CI workflow with consolidated linters binary --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbf00bcb2d..b27c196a6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,8 +117,7 @@ jobs: skip-pkg-cache: true - name: Custom Lint run: | - go run ./linter/koanf ./... - go run ./linter/pointercheck ./... + go run ./linters ./... - name: Set environment variables run: |