Commit 8136905
committed
Handle problems detected by used linters
The problems in the code base detected by the linters that have been
integrated in GH-62 through GolangCI have been handled by refactoring
the affected implementations.
This helps to improve the overall code quality and prevents possible
errors.
1. Removed unused function parameters detected by unparam (1).
1. `(*cmdOptions).prepare` - `cmd` is unused:
cmd/snowsaw/bootstrap/bootstrap.go:51:30 (2)
```go
func (o *cmdOptions) prepare(cmd *cobra.Command, args []string) {
^
```
2. `(*cmdOptions).run` - `cmd` is unused:
cmd/snowsaw/bootstrap/bootstrap.go:100:26 (2)
```go
func (o *cmdOptions) run(cmd *cobra.Command, args []string) {
^
```
3. `(*cmdOptions).run` - `args` is unused:
cmd/snowsaw/bootstrap/bootstrap.go:100:46 (2)
```go
func (o *cmdOptions) run(cmd *cobra.Command, args []string) {
^
```
2. Improved function names and code flows detected by golint (3).
1. func `NewJsonEncoder` should be `NewJSONEncoder`:
pkg/config/encoder/json/json.go:34:6 (4)
```go
func NewJsonEncoder() Encoder {
^
```
2. var `ExtensionsJson` should be `ExtensionsJSON`:
pkg/config/encoder/constants.go:26:2 (5)
```go
ExtensionsJson = "json"
^
```
3. if block ends with a return statement, so drop this else and
outdent its block (move short variable declaration to its own line
if necessary): pkg/prt/printer.go:121:9 (6)
```go
} else {
^
```
4. exported func Load returns unexported type *builder.builder, which
can be annoying to use: pkg/config/builder/builder.go:39:32 (7)
```go
func Load(files ...*file.File) *builder {
^
```
3. Improved code style smells detected by gocritic (8).
1. assignOp: replace `format = format + "\n"` with `format += "\n"`:
pkg/prt/printer.go:179:4 (9)
```go
format = format + "\n"
^
```
2. paramTypeCombine: `func(v Verbosity, w io.Writer, prefix string,
format string, args ...interface{})` could be replaced with
`func(v Verbosity, w io.Writer, prefix, format string, args
...interface{})`: pkg/prt/printer.go:176:1 (10)
```go
func (p *printerConfig) withNewLine(v Verbosity, w io.Writer,
^
prefix string, format string, args ...interface{}) {
```
3. emptyStringTest: replace `len(parts[0]) == 0` with `parts[0] ==
""`: pkg/snowblock/task/shell/shell.go:165:5 (11)
```go
if len(parts[0]) == 0 {
^
```
4. elseif: can replace 'else {if cond {}}' with 'else if cond {}':
cmd/snowsaw/bootstrap/bootstrap.go:57:9 (12)
```go
} else {
^
```
4. Remove unnecessary type conversions detected by unconvert (13).
1. unnecessary conversion: pkg/prt/printer.go:132:16 (14)
```go
*v = Verbosity(l)
^
```
References:
(1) https://github.com/mvdan/unparam
(2) https://github.com/arcticicestudio/snowsaw/blob/9366c4a9c6d59dd0fccad12fbc413842ea751fa6/cmd/snowsaw/bootstrap/bootstrap.go#L51
(3) https://github.com/golang/lint
(4) https://github.com/arcticicestudio/snowsaw/blob/5aa483e7e5e45888254aa4d0143d2afb898b4332/pkg/config/encoder/json/json.go#L34
(5) https://github.com/arcticicestudio/snowsaw/blob/008edbcb509af2cb5ced942d679fa3845a4ec1e1/pkg/config/encoder/constants.go#L26
(6) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L121
(7) https://github.com/arcticicestudio/snowsaw/blob/dea6ab56b7410a8cbc8901818703d5ab1ace5c87/pkg/config/builder/builder.go#L39
(8) https://github.com/go-critic/go-critic
(9) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L179
(10) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L176
(11) https://github.com/arcticicestudio/snowsaw/blob/a78810b7ccb5ddb8e80929d54fb7c461a1b80a1c/pkg/snowblock/task/shell/shell.go#L165
(12) https://github.com/arcticicestudio/snowsaw/blob/9366c4a9c6d59dd0fccad12fbc413842ea751fa6/cmd/snowsaw/bootstrap/bootstrap.go#L57
(13) https://github.com/mdempsky/unconvert
(14) https://github.com/arcticicestudio/snowsaw/blob/79afc12ebc15620fd94e78416e0b49a68bbf2eb6/pkg/prt/printer.go#L132
Epic: GH-33
Resolves GH-801 parent a78810b commit 8136905
File tree
8 files changed
+25
-27
lines changed- cmd/snowsaw/bootstrap
- pkg
- config
- builder
- encoder
- json
- prt
- snowblock
- task/shell
8 files changed
+25
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
| 44 | + | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
| |||
97 | 95 | | |
98 | 96 | | |
99 | 97 | | |
100 | | - | |
| 98 | + | |
101 | 99 | | |
102 | 100 | | |
103 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
428 | 429 | | |
429 | 430 | | |
430 | 431 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | 121 | | |
| 122 | + | |
124 | 123 | | |
125 | 124 | | |
126 | 125 | | |
| |||
130 | 129 | | |
131 | 130 | | |
132 | 131 | | |
133 | | - | |
| 132 | + | |
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
| |||
174 | 173 | | |
175 | 174 | | |
176 | 175 | | |
177 | | - | |
| 176 | + | |
178 | 177 | | |
179 | 178 | | |
180 | | - | |
| 179 | + | |
181 | 180 | | |
182 | 181 | | |
183 | 182 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| |||
0 commit comments