From c73aae64302d84b50d83f7a9426d3fac1a465890 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 01:25:26 +0700 Subject: [PATCH 01/15] updated `golangci-lint` to `1.59.1` --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1657109bb..b5aa8953d 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ playground: check: lint test lint: - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.39.0 + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.59.1 @echo "running linters..." @$(GOPATH_DIR)/bin/golangci-lint run ./src/... @echo "no linter errors found" From 28af6abb7dcaf59fa954ad0afaa7278860688a5f Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 01:35:13 +0700 Subject: [PATCH 02/15] fixed warnings from `gocritic` --- .golangci.yml | 75 -------------------------------------- src/linter/root_checker.go | 2 +- src/types/map.go | 2 +- 3 files changed, 2 insertions(+), 77 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a23f9b98d..27ed70a4c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -38,81 +38,6 @@ linters: - gosec fast: false -linters-settings: - gocritic: - enabled-checks: - - appendAssign - - appendCombine - - argOrder - - assignOp - - badCall - - badCond - - badRegexp - - boolExprSimplify - - captLocal - - caseOrder - - codegenComment - - commentFormatting - - commentedOutCode - - commentedOutImport - - defaultCaseOrder - - deferUnlambda - - deprecatedComment - - dupArg - - dupBranchBody - - dupCase - - dupImport - - dupSubExpr - - elseif - - emptyFallthrough - - emptyStringTest - - equalFold - - evalOrder - - exitAfterDefer - - filepathJoin - - flagDeref - - flagName - - ifElseChain - - importShadow - - indexAlloc - - initClause - - mapKey - - methodExprCall - - nestingReduce - - newDeref - - nilValReturn - - offBy1 - - rangeExprCopy - - regexpMust - - regexpPattern - - regexpSimplify - - ruleguard - - singleCaseSwitch - - sloppyLen - - sloppyReassign - - sloppyTypeAssert - - sortSlice - - stringXbytes - - switchTrue - - truncateCmp - - typeAssertChain - - typeSwitchVar - - typeUnparen - - underef - - unlabelStmt - - unlambda - - unnamedResult - - unnecessaryBlock - - unslice - - valSwap - - weakCond - - whyNoLint - - wrapperFunc - - yodaStyleExpr - settings: - ruleguard: - rules: "rules.go" - issues: exclude-rules: - path: php/parser diff --git a/src/linter/root_checker.go b/src/linter/root_checker.go index 40763c19b..149b767d7 100644 --- a/src/linter/root_checker.go +++ b/src/linter/root_checker.go @@ -470,7 +470,7 @@ func (r *rootChecker) isValidPHPDocRef(ref string) bool { return true // OK: function reference } if _, ok := r.info.GetConstant(globalRef); ok { - return true // OK: const reference + return true // OK: here's the const reference } } fqnRef := expandName(ref) diff --git a/src/types/map.go b/src/types/map.go index e7ba69579..f942d81ba 100644 --- a/src/types/map.go +++ b/src/types/map.go @@ -192,7 +192,7 @@ func (m Map) IsLazyArray() bool { } for typ := range m.m { - if len(typ) > 0 && typ[0] == WArrayOf { + if typ != "" && typ[0] == WArrayOf { return true } } From 67046c8d897d7f6da068cd9f259804fc452585e5 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:03:11 +0700 Subject: [PATCH 03/15] fixed warnings from `gofmt` --- .golangci.yml | 3 ++ playground/wasm/main.go | 1 + src/ir/irutil/nodeSet.go | 2 + src/ir/node_types.go | 20 ++++++---- src/linter/cache.go | 69 +++++++++++++++++---------------- src/phpgrep/tracing_disabled.go | 1 + src/phpgrep/tracing_enabled.go | 1 + src/utils/comment_parser.go | 2 +- 8 files changed, 56 insertions(+), 43 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 27ed70a4c..0ba3a0eb3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,3 +44,6 @@ issues: linters: - gocritic - golint + - path: cmd/stubs/phpstorm_stubs.go + linters: + - gofmt diff --git a/playground/wasm/main.go b/playground/wasm/main.go index 1a662f156..5b2e790aa 100644 --- a/playground/wasm/main.go +++ b/playground/wasm/main.go @@ -1,3 +1,4 @@ +//go:build wasm // +build wasm package main diff --git a/src/ir/irutil/nodeSet.go b/src/ir/irutil/nodeSet.go index c2bef380d..f86930c97 100644 --- a/src/ir/irutil/nodeSet.go +++ b/src/ir/irutil/nodeSet.go @@ -14,6 +14,7 @@ import ( // shows that we can use n=4 or n=5 as a sweet spot. // // PHP corpus results (if conditions + switch cases): +// // 256131 only slice is used (slice=1 map=0) // 56628 only slice is used (slice=2 map=0) // 5844 only slice is used (slice=3 map=0) @@ -35,6 +36,7 @@ import ( // as a unique key for a map. This is the same thing staticcheck linter does. // // A comparison of slice-only (old) and hybrid solutions (new): +// // name old time/op new time/op delta // NodeSet/1-8 9.42ns ± 0% 9.47ns ± 1% ~ (p=0.222 n=4+5) // NodeSet/5-8 923ns ± 3% 908ns ± 1% ~ (p=0.159 n=5+4) diff --git a/src/ir/node_types.go b/src/ir/node_types.go index 690929aa7..3b6da86f9 100644 --- a/src/ir/node_types.go +++ b/src/ir/node_types.go @@ -681,7 +681,7 @@ type ReferenceExpr struct { Variable Node } -// ShellExecExpr is a ``-quoted string. +// ShellExecExpr is a `$shell`-quoted string. type ShellExecExpr struct { Position *position.Position OpenBacktickTkn *token.Token @@ -763,8 +763,10 @@ type Name struct { // Argument is a wrapper node for func/method arguments. // Possible syntax's: -// $Name: $Expr -// $Expr +// +// $Name: $Expr +// $Expr +// // If $Variadic is true, it's `...$Expr`. // If $IsReference is true, it's `&$Expr`. type Argument struct { @@ -795,11 +797,13 @@ type Nullable struct { // Parameter is a function param declaration. // Possible syntax's: -// #[$AttrGroups] $Modifiers $VariableType $Variable = $DefaultValue -// #[$AttrGroups] $VariableType $Variable = $DefaultValue -// $VariableType $Variable = $DefaultValue -// $VariableType $Variable -// $Variable +// +// #[$AttrGroups] $Modifiers $VariableType $Variable = $DefaultValue +// #[$AttrGroups] $VariableType $Variable = $DefaultValue +// $VariableType $Variable = $DefaultValue +// $VariableType $Variable +// $Variable +// // If $ByRef is true, it's `&$Variable`. // If $Variadic is true, it's `...$Variable`. type Parameter struct { diff --git a/src/linter/cache.go b/src/linter/cache.go index 528fb0318..b893fbd1d 100644 --- a/src/linter/cache.go +++ b/src/linter/cache.go @@ -16,40 +16,41 @@ import ( // cacheVersions is a magic number that helps to distinguish incompatible caches. // // Version log: -// 27 - added Static field to meta.FuncInfo -// 28 - array type parsed as mixed[] -// 29 - updated type inference for ClassConstFetch -// 30 - resolve ClassConstFetch to a wrapped type string -// 31 - fixed plus operator type inference for arrays -// 32 - replaced Static:bool with Flags:uint8 in meta.FuncInfo -// 33 - support parsing of array and list -// 34 - support parsing of ?ClassName as "ClassName|null" -// 35 - added Flags:uint8 to meta.ClassInfo -// 36 - added FuncAbstract bit to FuncFlags -// added FuncFinal bit to FuncFlags -// added ClassFinal bit to ClassFlags -// FuncInfo now stores original function name -// ClassInfo now stores original class name -// 37 - added ClassShape bit to ClassFlags -// changed meta.scopeVar bool fields representation -// 38 - replaced TypesMap.immutable:bool with flags:uint8. -// added mapPrecise flag to mark precise type maps. -// 39 - added new field Value in ConstantInfo -// 40 - changed string const value storage (no quotes) -// 41 - const-folding affected const definition values -// 42 - bool-typed consts are now stored in meta info -// 43 - define'd const values stored in cache -// 44 - rename ConstantInfo => ConstInfo -// 45 - added Mixins field to meta.ClassInfo -// 46 - changed the way of inferring the return type of functions and methods -// 47 - forced cache version invalidation due to the #921 -// 48 - renamed meta.TypesMap to types.Map; this affects gob encoding -// 49 - for shape, names are now generated using the keys that make up this shape -// 50 - added Flags field for meta.PropertyInfo -// 51 - added anonymous classes -// 52 - renamed all PhpDoc and Phpdoc with PHPDoc -// 53 - added DeprecationInfo for functions and methods and support for some attributes -// 54 - forced cache version invalidation due to the #1165 +// +// 27 - added Static field to meta.FuncInfo +// 28 - array type parsed as mixed[] +// 29 - updated type inference for ClassConstFetch +// 30 - resolve ClassConstFetch to a wrapped type string +// 31 - fixed plus operator type inference for arrays +// 32 - replaced Static:bool with Flags:uint8 in meta.FuncInfo +// 33 - support parsing of array and list +// 34 - support parsing of ?ClassName as "ClassName|null" +// 35 - added Flags:uint8 to meta.ClassInfo +// 36 - added FuncAbstract bit to FuncFlags +// added FuncFinal bit to FuncFlags +// added ClassFinal bit to ClassFlags +// FuncInfo now stores original function name +// ClassInfo now stores original class name +// 37 - added ClassShape bit to ClassFlags +// changed meta.scopeVar bool fields representation +// 38 - replaced TypesMap.immutable:bool with flags:uint8. +// added mapPrecise flag to mark precise type maps. +// 39 - added new field Value in ConstantInfo +// 40 - changed string const value storage (no quotes) +// 41 - const-folding affected const definition values +// 42 - bool-typed consts are now stored in meta info +// 43 - define'd const values stored in cache +// 44 - rename ConstantInfo => ConstInfo +// 45 - added Mixins field to meta.ClassInfo +// 46 - changed the way of inferring the return type of functions and methods +// 47 - forced cache version invalidation due to the #921 +// 48 - renamed meta.TypesMap to types.Map; this affects gob encoding +// 49 - for shape, names are now generated using the keys that make up this shape +// 50 - added Flags field for meta.PropertyInfo +// 51 - added anonymous classes +// 52 - renamed all PhpDoc and Phpdoc with PHPDoc +// 53 - added DeprecationInfo for functions and methods and support for some attributes +// 54 - forced cache version invalidation due to the #1165 const cacheVersion = 54 var ( diff --git a/src/phpgrep/tracing_disabled.go b/src/phpgrep/tracing_disabled.go index fce504417..a1b359d5f 100644 --- a/src/phpgrep/tracing_disabled.go +++ b/src/phpgrep/tracing_disabled.go @@ -1,3 +1,4 @@ +//go:build !tracing // +build !tracing package phpgrep diff --git a/src/phpgrep/tracing_enabled.go b/src/phpgrep/tracing_enabled.go index 5bb559015..7f1f4ab95 100644 --- a/src/phpgrep/tracing_enabled.go +++ b/src/phpgrep/tracing_enabled.go @@ -1,3 +1,4 @@ +//go:build tracing // +build tracing package phpgrep diff --git a/src/utils/comment_parser.go b/src/utils/comment_parser.go index b9178cb92..2edfd828e 100644 --- a/src/utils/comment_parser.go +++ b/src/utils/comment_parser.go @@ -16,7 +16,7 @@ func NewCommentParser(comment string, line int) *CommentParser { } // ParseExpectation parses a string describing expected errors like -// want `error description 1` [and` error description 2` and `error 3` ...] +// want `error description 1` [and` error description 2` and `error 3` ...] func (c *CommentParser) ParseExpectation() (wants []string, err error) { // It is necessary to remove \r, since in windows the lines are separated by \r\n. c.comment = strings.TrimSuffix(c.comment, "\r") From 612b5e1e2c67f0f6fda675062a3edcc1ea4e33b1 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:04:50 +0700 Subject: [PATCH 04/15] removed `varcheck` linter (inactivated) --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 0ba3a0eb3..3a7278f92 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -25,7 +25,6 @@ linters: - typecheck - unconvert - unused - - varcheck - exportloopref disable: - depguard From 1a4bc9a6e17a78f491c79201df4e4c66972395d7 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:05:21 +0700 Subject: [PATCH 05/15] removed `structcheck` linter (inactivated) --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 3a7278f92..4a583d488 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,6 @@ linters: - misspell - nakedret - staticcheck - - structcheck - typecheck - unconvert - unused From 08939960533fe4e37e6ceef157edabc1dd00030f Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:05:34 +0700 Subject: [PATCH 06/15] removed `deadcode` linter (inactivated) --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 4a583d488..89afffb18 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,6 @@ run: linters: enable: - - deadcode - gas - gocritic - gofmt From 216af9f1ea8c6d3ae126978a0795f6ee731e89c1 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:08:24 +0700 Subject: [PATCH 07/15] removed `golint` linter (inactivated) --- .golangci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 89afffb18..83d7c2130 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,7 +13,6 @@ linters: - gocritic - gofmt - goimports - - golint - gosimple - ineffassign - megacheck @@ -40,7 +39,7 @@ issues: - path: php/parser linters: - gocritic - - golint + - revive - path: cmd/stubs/phpstorm_stubs.go linters: - gofmt From 23f2a02c168736e1b4eaeffb692590f3ba02505a Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:26:34 +0700 Subject: [PATCH 08/15] removed `megacheck` linter (deprecated) --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 83d7c2130..fa3175bbd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,7 +15,6 @@ linters: - goimports - gosimple - ineffassign - - megacheck - misspell - nakedret - staticcheck From 2fc94944640634d7c441c7afbf0ccf7e76831041 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:28:34 +0700 Subject: [PATCH 09/15] removed `interfacer` linter (deprecated) --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index fa3175bbd..bad1aa86c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,7 +26,6 @@ linters: - depguard - dupl - gocyclo - - interfacer - lll - maligned - prealloc From 86209092d0895436cd34509afd1c406db0f8ce70 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:29:01 +0700 Subject: [PATCH 10/15] removed `maligned` linter (deprecated) --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index bad1aa86c..5869bb2b0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,7 +27,6 @@ linters: - dupl - gocyclo - lll - - maligned - prealloc - gosec fast: false From 590f180739ae9eb9f3a294daf57272025ce02a2e Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:35:56 +0700 Subject: [PATCH 11/15] added `errcheck` linter --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 5869bb2b0..769db8553 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,6 +9,7 @@ run: linters: enable: + - errcheck - gas - gocritic - gofmt From 8172d8a8f23784c42b8419b9ce9115cfc7b6d5bf Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:37:53 +0700 Subject: [PATCH 12/15] added `govet` linter --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 769db8553..862fb9118 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,7 @@ linters: - unconvert - unused - exportloopref + - govet disable: - depguard - dupl From b5e7dc93e7026468a183718fb8a6900bacfee62c Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:38:49 +0700 Subject: [PATCH 13/15] added backlog for linters --- .golangci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 862fb9118..3aa52deaf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,7 +30,9 @@ linters: - gocyclo - lll - prealloc - - gosec + - gosec # TODO: enable it + - unparam + - revive fast: false issues: From de2272145b6b6ada9963270e50e86fed0c577fff Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:40:07 +0700 Subject: [PATCH 14/15] renamed `deadline` to `timeout` --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 3aa52deaf..d7df3eb63 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - deadline: 3m + timeout: 3m skip-files: - php/parser/scanner/scanner.go - php/parser/scanner/lexer_tokens.go From 8a237345a4e4211961a91ffa68149a9703efe1e9 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 28 Jul 2024 02:41:34 +0700 Subject: [PATCH 15/15] renamed `run.skip-files` to `issues.exclude-dirs` --- .golangci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d7df3eb63..275ff3727 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,5 @@ run: timeout: 3m - skip-files: - - php/parser/scanner/scanner.go - - php/parser/scanner/lexer_tokens.go - - php/parser/scanner/lexer.go - - php/parser/printer/printer.go - - php/parser/printer/pretty_printer.go linters: enable: @@ -44,3 +38,9 @@ issues: - path: cmd/stubs/phpstorm_stubs.go linters: - gofmt + exclude-dirs: + - php/parser/scanner/scanner.go + - php/parser/scanner/lexer_tokens.go + - php/parser/scanner/lexer.go + - php/parser/printer/printer.go + - php/parser/printer/pretty_printer.go