Skip to content

Commit 326d6be

Browse files
updated golangci-lint and fixed errors in the code (#1231)
1 parent b211f8e commit 326d6be

File tree

11 files changed

+72
-137
lines changed

11 files changed

+72
-137
lines changed

.golangci.yml

Lines changed: 16 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,46 @@
11
run:
2-
deadline: 3m
3-
skip-files:
4-
- php/parser/scanner/scanner.go
5-
- php/parser/scanner/lexer_tokens.go
6-
- php/parser/scanner/lexer.go
7-
- php/parser/printer/printer.go
8-
- php/parser/printer/pretty_printer.go
2+
timeout: 3m
93

104
linters:
115
enable:
12-
- deadcode
6+
- errcheck
137
- gas
148
- gocritic
159
- gofmt
1610
- goimports
17-
- golint
1811
- gosimple
1912
- ineffassign
20-
- megacheck
2113
- misspell
2214
- nakedret
2315
- staticcheck
24-
- structcheck
2516
- typecheck
2617
- unconvert
2718
- unused
28-
- varcheck
2919
- exportloopref
20+
- govet
3021
disable:
3122
- depguard
3223
- dupl
3324
- gocyclo
34-
- interfacer
3525
- lll
36-
- maligned
3726
- prealloc
38-
- gosec
27+
- gosec # TODO: enable it
28+
- unparam
29+
- revive
3930
fast: false
4031

41-
linters-settings:
42-
gocritic:
43-
enabled-checks:
44-
- appendAssign
45-
- appendCombine
46-
- argOrder
47-
- assignOp
48-
- badCall
49-
- badCond
50-
- badRegexp
51-
- boolExprSimplify
52-
- captLocal
53-
- caseOrder
54-
- codegenComment
55-
- commentFormatting
56-
- commentedOutCode
57-
- commentedOutImport
58-
- defaultCaseOrder
59-
- deferUnlambda
60-
- deprecatedComment
61-
- dupArg
62-
- dupBranchBody
63-
- dupCase
64-
- dupImport
65-
- dupSubExpr
66-
- elseif
67-
- emptyFallthrough
68-
- emptyStringTest
69-
- equalFold
70-
- evalOrder
71-
- exitAfterDefer
72-
- filepathJoin
73-
- flagDeref
74-
- flagName
75-
- ifElseChain
76-
- importShadow
77-
- indexAlloc
78-
- initClause
79-
- mapKey
80-
- methodExprCall
81-
- nestingReduce
82-
- newDeref
83-
- nilValReturn
84-
- offBy1
85-
- rangeExprCopy
86-
- regexpMust
87-
- regexpPattern
88-
- regexpSimplify
89-
- ruleguard
90-
- singleCaseSwitch
91-
- sloppyLen
92-
- sloppyReassign
93-
- sloppyTypeAssert
94-
- sortSlice
95-
- stringXbytes
96-
- switchTrue
97-
- truncateCmp
98-
- typeAssertChain
99-
- typeSwitchVar
100-
- typeUnparen
101-
- underef
102-
- unlabelStmt
103-
- unlambda
104-
- unnamedResult
105-
- unnecessaryBlock
106-
- unslice
107-
- valSwap
108-
- weakCond
109-
- whyNoLint
110-
- wrapperFunc
111-
- yodaStyleExpr
112-
settings:
113-
ruleguard:
114-
rules: "rules.go"
115-
11632
issues:
11733
exclude-rules:
11834
- path: php/parser
11935
linters:
12036
- gocritic
121-
- golint
37+
- revive
38+
- path: cmd/stubs/phpstorm_stubs.go
39+
linters:
40+
- gofmt
41+
exclude-dirs:
42+
- php/parser/scanner/scanner.go
43+
- php/parser/scanner/lexer_tokens.go
44+
- php/parser/scanner/lexer.go
45+
- php/parser/printer/printer.go
46+
- php/parser/printer/pretty_printer.go

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ playground:
2727
check: lint test
2828

2929
lint:
30-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.39.0
30+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH_DIR)/bin v1.59.1
3131
@echo "running linters..."
3232
@$(GOPATH_DIR)/bin/golangci-lint run ./src/...
3333
@echo "no linter errors found"

playground/wasm/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build wasm
12
// +build wasm
23

34
package main

src/ir/irutil/nodeSet.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
// shows that we can use n=4 or n=5 as a sweet spot.
1515
//
1616
// PHP corpus results (if conditions + switch cases):
17+
//
1718
// 256131 only slice is used (slice=1 map=0)
1819
// 56628 only slice is used (slice=2 map=0)
1920
// 5844 only slice is used (slice=3 map=0)
@@ -35,6 +36,7 @@ import (
3536
// as a unique key for a map. This is the same thing staticcheck linter does.
3637
//
3738
// A comparison of slice-only (old) and hybrid solutions (new):
39+
//
3840
// name old time/op new time/op delta
3941
// NodeSet/1-8 9.42ns ± 0% 9.47ns ± 1% ~ (p=0.222 n=4+5)
4042
// NodeSet/5-8 923ns ± 3% 908ns ± 1% ~ (p=0.159 n=5+4)

src/ir/node_types.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ type ReferenceExpr struct {
681681
Variable Node
682682
}
683683

684-
// ShellExecExpr is a ``-quoted string.
684+
// ShellExecExpr is a `$shell`-quoted string.
685685
type ShellExecExpr struct {
686686
Position *position.Position
687687
OpenBacktickTkn *token.Token
@@ -763,8 +763,10 @@ type Name struct {
763763

764764
// Argument is a wrapper node for func/method arguments.
765765
// Possible syntax's:
766-
// $Name: $Expr
767-
// $Expr
766+
//
767+
// $Name: $Expr
768+
// $Expr
769+
//
768770
// If $Variadic is true, it's `...$Expr`.
769771
// If $IsReference is true, it's `&$Expr`.
770772
type Argument struct {
@@ -795,11 +797,13 @@ type Nullable struct {
795797

796798
// Parameter is a function param declaration.
797799
// Possible syntax's:
798-
// #[$AttrGroups] $Modifiers $VariableType $Variable = $DefaultValue
799-
// #[$AttrGroups] $VariableType $Variable = $DefaultValue
800-
// $VariableType $Variable = $DefaultValue
801-
// $VariableType $Variable
802-
// $Variable
800+
//
801+
// #[$AttrGroups] $Modifiers $VariableType $Variable = $DefaultValue
802+
// #[$AttrGroups] $VariableType $Variable = $DefaultValue
803+
// $VariableType $Variable = $DefaultValue
804+
// $VariableType $Variable
805+
// $Variable
806+
//
803807
// If $ByRef is true, it's `&$Variable`.
804808
// If $Variadic is true, it's `...$Variable`.
805809
type Parameter struct {

src/linter/cache.go

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,41 @@ import (
1616
// cacheVersions is a magic number that helps to distinguish incompatible caches.
1717
//
1818
// Version log:
19-
// 27 - added Static field to meta.FuncInfo
20-
// 28 - array type parsed as mixed[]
21-
// 29 - updated type inference for ClassConstFetch
22-
// 30 - resolve ClassConstFetch to a wrapped type string
23-
// 31 - fixed plus operator type inference for arrays
24-
// 32 - replaced Static:bool with Flags:uint8 in meta.FuncInfo
25-
// 33 - support parsing of array<k,v> and list<type>
26-
// 34 - support parsing of ?ClassName as "ClassName|null"
27-
// 35 - added Flags:uint8 to meta.ClassInfo
28-
// 36 - added FuncAbstract bit to FuncFlags
29-
// added FuncFinal bit to FuncFlags
30-
// added ClassFinal bit to ClassFlags
31-
// FuncInfo now stores original function name
32-
// ClassInfo now stores original class name
33-
// 37 - added ClassShape bit to ClassFlags
34-
// changed meta.scopeVar bool fields representation
35-
// 38 - replaced TypesMap.immutable:bool with flags:uint8.
36-
// added mapPrecise flag to mark precise type maps.
37-
// 39 - added new field Value in ConstantInfo
38-
// 40 - changed string const value storage (no quotes)
39-
// 41 - const-folding affected const definition values
40-
// 42 - bool-typed consts are now stored in meta info
41-
// 43 - define'd const values stored in cache
42-
// 44 - rename ConstantInfo => ConstInfo
43-
// 45 - added Mixins field to meta.ClassInfo
44-
// 46 - changed the way of inferring the return type of functions and methods
45-
// 47 - forced cache version invalidation due to the #921
46-
// 48 - renamed meta.TypesMap to types.Map; this affects gob encoding
47-
// 49 - for shape, names are now generated using the keys that make up this shape
48-
// 50 - added Flags field for meta.PropertyInfo
49-
// 51 - added anonymous classes
50-
// 52 - renamed all PhpDoc and Phpdoc with PHPDoc
51-
// 53 - added DeprecationInfo for functions and methods and support for some attributes
52-
// 54 - forced cache version invalidation due to the #1165
19+
//
20+
// 27 - added Static field to meta.FuncInfo
21+
// 28 - array type parsed as mixed[]
22+
// 29 - updated type inference for ClassConstFetch
23+
// 30 - resolve ClassConstFetch to a wrapped type string
24+
// 31 - fixed plus operator type inference for arrays
25+
// 32 - replaced Static:bool with Flags:uint8 in meta.FuncInfo
26+
// 33 - support parsing of array<k,v> and list<type>
27+
// 34 - support parsing of ?ClassName as "ClassName|null"
28+
// 35 - added Flags:uint8 to meta.ClassInfo
29+
// 36 - added FuncAbstract bit to FuncFlags
30+
// added FuncFinal bit to FuncFlags
31+
// added ClassFinal bit to ClassFlags
32+
// FuncInfo now stores original function name
33+
// ClassInfo now stores original class name
34+
// 37 - added ClassShape bit to ClassFlags
35+
// changed meta.scopeVar bool fields representation
36+
// 38 - replaced TypesMap.immutable:bool with flags:uint8.
37+
// added mapPrecise flag to mark precise type maps.
38+
// 39 - added new field Value in ConstantInfo
39+
// 40 - changed string const value storage (no quotes)
40+
// 41 - const-folding affected const definition values
41+
// 42 - bool-typed consts are now stored in meta info
42+
// 43 - define'd const values stored in cache
43+
// 44 - rename ConstantInfo => ConstInfo
44+
// 45 - added Mixins field to meta.ClassInfo
45+
// 46 - changed the way of inferring the return type of functions and methods
46+
// 47 - forced cache version invalidation due to the #921
47+
// 48 - renamed meta.TypesMap to types.Map; this affects gob encoding
48+
// 49 - for shape, names are now generated using the keys that make up this shape
49+
// 50 - added Flags field for meta.PropertyInfo
50+
// 51 - added anonymous classes
51+
// 52 - renamed all PhpDoc and Phpdoc with PHPDoc
52+
// 53 - added DeprecationInfo for functions and methods and support for some attributes
53+
// 54 - forced cache version invalidation due to the #1165
5354
const cacheVersion = 54
5455

5556
var (

src/linter/root_checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ func (r *rootChecker) isValidPHPDocRef(ref string) bool {
470470
return true // OK: function reference
471471
}
472472
if _, ok := r.info.GetConstant(globalRef); ok {
473-
return true // OK: const reference
473+
return true // OK: here's the const reference
474474
}
475475
}
476476
fqnRef := expandName(ref)

src/phpgrep/tracing_disabled.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !tracing
12
// +build !tracing
23

34
package phpgrep

src/phpgrep/tracing_enabled.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build tracing
12
// +build tracing
23

34
package phpgrep

src/types/map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (m Map) IsLazyArray() bool {
192192
}
193193

194194
for typ := range m.m {
195-
if len(typ) > 0 && typ[0] == WArrayOf {
195+
if typ != "" && typ[0] == WArrayOf {
196196
return true
197197
}
198198
}

0 commit comments

Comments
 (0)