Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit 6f1e3a8

Browse files
authored
Merge pull request #5 from mbilski/bugfix/empty-struct-patterns
Ignore struct patterns check if list is empty
2 parents 17724dd + b07351b commit 6f1e3a8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

main

83 Bytes
Binary file not shown.

pkg/analyzer/analyzer.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ func newFlagSet() flag.FlagSet {
3636
}
3737

3838
func run(pass *analysis.Pass) (interface{}, error) {
39+
splitFn := func(c rune) bool { return c == ',' }
3940
inspector := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
40-
structPatterns := strings.Split(StructPatternList, ",")
41+
structPatterns := strings.FieldsFunc(StructPatternList, splitFn)
4142
// validate the pattern syntax
4243
for _, pattern := range structPatterns {
4344
_, err := path.Match(pattern, "")
@@ -117,11 +118,13 @@ func run(pass *analysis.Pass) (interface{}, error) {
117118
if len(compositeLit.Elts) == 0 {
118119
// Check if this composite is one of the results the last return statement
119120
isInResults := false
120-
for _, result := range returnStmt.Results {
121-
compareComposite, ok := result.(*ast.CompositeLit)
122-
if ok {
123-
if compareComposite == compositeLit {
124-
isInResults = true
121+
if returnStmt != nil {
122+
for _, result := range returnStmt.Results {
123+
compareComposite, ok := result.(*ast.CompositeLit)
124+
if ok {
125+
if compareComposite == compositeLit {
126+
isInResults = true
127+
}
125128
}
126129
}
127130
}

0 commit comments

Comments
 (0)