Skip to content

Commit 20b5129

Browse files
committed
Updating golanglint
1 parent 89518a0 commit 20b5129

29 files changed

+156
-86
lines changed

.golangci.bck.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
run:
2+
timeout: 5m
3+
linters:
4+
enable:
5+
- asciicheck
6+
- depguard
7+
- errorlint
8+
- gci
9+
- gochecknoinits
10+
- gofmt
11+
- goimports
12+
- gosec
13+
- gosimple
14+
- staticcheck
15+
- unused
16+
- misspell
17+
- nakedret
18+
- nolintlint
19+
- predeclared
20+
- revive
21+
- unconvert
22+
- unparam
23+
linters-settings:
24+
depguard:
25+
rules:
26+
prevent_unmaintained_packages:
27+
list-mode: lax
28+
files:
29+
- $all
30+
- "!$test"
31+
deny:
32+
- pkg: io/ioutil
33+
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
34+
issues:
35+
exclude-rules:
36+
- linters:
37+
- revive
38+
text: "var-naming"

.golangci.yml

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,52 @@
1-
run:
2-
timeout: 5m
1+
version: "2"
32
linters:
43
enable:
54
- asciicheck
65
- depguard
76
- errorlint
8-
- gci
97
- gochecknoinits
10-
- gofmt
11-
- goimports
128
- gosec
13-
- gosimple
14-
- staticcheck
15-
- unused
169
- misspell
1710
- nakedret
1811
- nolintlint
1912
- predeclared
2013
- revive
2114
- unconvert
2215
- unparam
23-
linters-settings:
24-
depguard:
16+
settings:
17+
depguard:
18+
rules:
19+
prevent_unmaintained_packages:
20+
list-mode: lax
21+
files:
22+
- $all
23+
- '!$test'
24+
deny:
25+
- pkg: io/ioutil
26+
desc: 'replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil'
27+
exclusions:
28+
generated: lax
29+
presets:
30+
- comments
31+
- common-false-positives
32+
- legacy
33+
- std-error-handling
2534
rules:
26-
prevent_unmaintained_packages:
27-
list-mode: lax
28-
files:
29-
- $all
30-
- "!$test"
31-
deny:
32-
- pkg: io/ioutil
33-
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
34-
issues:
35-
exclude-rules:
36-
- linters:
37-
- revive
38-
text: "var-naming"
35+
- linters:
36+
- revive
37+
text: var-naming
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- gci
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

acceptance_tests/load-file.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
testLoadFileNotExist() {
44
result=$(./yq e -n 'load("cat.yml")' 2>&1)
55
assertEquals 1 $?
6-
assertEquals "Error: Failed to load cat.yml: open cat.yml: no such file or directory" "$result"
6+
assertEquals "Error: failed to load cat.yml: open cat.yml: no such file or directory" "$result"
77
}
88

99
testLoadFileExpNotExist() {
@@ -15,7 +15,7 @@ testLoadFileExpNotExist() {
1515
testStrLoadFileNotExist() {
1616
result=$(./yq e -n 'strload("cat.yml")' 2>&1)
1717
assertEquals 1 $?
18-
assertEquals "Error: Failed to load cat.yml: open cat.yml: no such file or directory" "$result"
18+
assertEquals "Error: failed to load cat.yml: open cat.yml: no such file or directory" "$result"
1919
}
2020

2121
testStrLoadFileExpNotExist() {

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ func getHumanVersion() string {
4545
}
4646

4747
// Strip off any single quotes added by the git information.
48-
return strings.Replace(version, "'", "", -1)
48+
return strings.ReplaceAll(version, "'", "")
4949
}

pkg/yqlib/candidate_node.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,14 @@ func (n *CandidateNode) SetParent(parent *CandidateNode) {
201201
type ValueVisitor func(*CandidateNode) error
202202

203203
func (n *CandidateNode) VisitValues(visitor ValueVisitor) error {
204-
if n.Kind == MappingNode {
204+
switch n.Kind {
205+
case MappingNode:
205206
for i := 1; i < len(n.Content); i = i + 2 {
206207
if err := visitor(n.Content[i]); err != nil {
207208
return err
208209
}
209210
}
210-
} else if n.Kind == SequenceNode {
211+
case SequenceNode:
211212
for i := 0; i < len(n.Content); i = i + 1 {
212213
if err := visitor(n.Content[i]); err != nil {
213214
return err

pkg/yqlib/data_tree_navigator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ func (d *dataTreeNavigator) GetMatchingNodes(context Context, expressionNode *Ex
6464
if handler != nil {
6565
return handler(d, context, expressionNode)
6666
}
67-
return Context{}, fmt.Errorf("Unknown operator %v", expressionNode.Operation.OperationType)
67+
return Context{}, fmt.Errorf("unknown operator %v", expressionNode.Operation.OperationType)
6868

6969
}

pkg/yqlib/decoder_toml.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,12 @@ func (dec *tomlDecoder) processTopLevelNode(currentNode *toml.Node) (bool, error
249249
var runAgainstCurrentExp bool
250250
var err error
251251
log.Debug("processTopLevelNode: Going to process %v state is current %v", currentNode.Kind, NodeToString(dec.rootMap))
252-
if currentNode.Kind == toml.Table {
252+
switch currentNode.Kind {
253+
case toml.Table:
253254
runAgainstCurrentExp, err = dec.processTable(currentNode)
254-
} else if currentNode.Kind == toml.ArrayTable {
255+
case toml.ArrayTable:
255256
runAgainstCurrentExp, err = dec.processArrayTable(currentNode)
256-
} else {
257+
default:
257258
runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(dec.rootMap, currentNode)
258259
}
259260

pkg/yqlib/decoder_xml.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,14 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
315315
case xml.Comment:
316316

317317
commentStr := string(xml.CharData(se))
318-
if elem.state == "started" {
318+
switch elem.state {
319+
case "started":
319320
applyFootComment(elem, commentStr)
320321

321-
} else if elem.state == "chardata" {
322+
case "chardata":
322323
log.Debug("got a line comment for (%v) %v: [%v]", elem.state, elem.label, commentStr)
323324
elem.n.LineComment = joinComments([]string{elem.n.LineComment, commentStr}, " ")
324-
} else {
325+
default:
325326
log.Debug("got a head comment for (%v) %v: [%v]", elem.state, elem.label, commentStr)
326327
elem.n.HeadComment = joinComments([]string{elem.n.HeadComment, commentStr}, " ")
327328
}

pkg/yqlib/encoder_lua.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,14 @@ func needsQuoting(s string) bool {
167167
// [%a_][%w_]*
168168
for i, c := range s {
169169
if i == 0 {
170+
// keeping for legacy reasons, upgraded linter
171+
//nolint:staticcheck
170172
if !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
171173
return true
172174
}
173175
} else {
176+
// keeping for legacy reasons, upgraded linter
177+
//nolint:staticcheck
174178
if !((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') {
175179
return true
176180
}
@@ -299,10 +303,10 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *CandidateNode) error {
299303
return writeString(writer, node.Value)
300304
}
301305
default:
302-
return fmt.Errorf("Lua encoder NYI -- %s", node.Tag)
306+
return fmt.Errorf("lua encoder NYI -- %s", node.Tag)
303307
}
304308
default:
305-
return fmt.Errorf("Lua encoder NYI -- %s", node.Tag)
309+
return fmt.Errorf("lua encoder NYI -- %s", node.Tag)
306310
}
307311
}
308312

pkg/yqlib/encoder_properties.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (pe *propertiesEncoder) doEncode(p *properties.Properties, node *CandidateN
107107
case AliasNode:
108108
return pe.doEncode(p, node.Alias, path, nil)
109109
default:
110-
return fmt.Errorf("Unsupported node %v", node.Tag)
110+
return fmt.Errorf("unsupported node %v", node.Tag)
111111
}
112112
}
113113

0 commit comments

Comments
 (0)