Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated golangci-lint and fixed errors in the code #1231

Merged
merged 16 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 16 additions & 91 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions playground/wasm/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build wasm
// +build wasm

package main
Expand Down
2 changes: 2 additions & 0 deletions src/ir/irutil/nodeSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions src/ir/node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
69 changes: 35 additions & 34 deletions src/linter/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<k,v> and list<type>
// 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<k,v> and list<type>
// 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 (
Expand Down
2 changes: 1 addition & 1 deletion src/linter/root_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/phpgrep/tracing_disabled.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !tracing
Hidanio marked this conversation as resolved.
Show resolved Hide resolved
// +build !tracing

package phpgrep
Expand Down
1 change: 1 addition & 0 deletions src/phpgrep/tracing_enabled.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tracing
Hidanio marked this conversation as resolved.
Show resolved Hide resolved
// +build tracing

package phpgrep
Expand Down
2 changes: 1 addition & 1 deletion src/types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/comment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down