diff --git a/.golangci.yml b/.golangci.yml index a23f9b98d..275ff3727 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,121 +1,46 @@ run: - deadline: 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 + timeout: 3m linters: enable: - - deadcode + - errcheck - gas - gocritic - gofmt - goimports - - golint - gosimple - ineffassign - - megacheck - misspell - nakedret - staticcheck - - structcheck - typecheck - unconvert - unused - - varcheck - exportloopref + - govet disable: - depguard - dupl - gocyclo - - interfacer - lll - - maligned - prealloc - - gosec + - gosec # TODO: enable it + - unparam + - revive 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 linters: - gocritic - - golint + - revive + - 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 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" 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/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/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/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 } } 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")