Skip to content

Commit 3d32e71

Browse files
authored
Merge pull request #450 from thaJeztah/fix_linting
update actions, and fix linting issues
2 parents 0db51fd + 936b42e commit 3d32e71

26 files changed

Lines changed: 172 additions & 151 deletions

.github/workflows/ci.yaml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
name: CI
22

3-
on:
4-
push:
5-
branches: [master]
6-
pull_request:
3+
on: [push, pull_request]
4+
5+
# Default to 'contents: read', which grants actions to read commits. Any
6+
# permission not included is implicitly set to "none".
7+
#
8+
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
9+
permissions:
10+
contents: read
711

812
jobs:
913
test:
1014
name: Test
1115
runs-on: ubuntu-latest
16+
timeout-minutes: 20 # guardrails timeout
1217

1318
strategy:
1419
fail-fast: false
1520
matrix:
16-
go: ["1.12", "1.21", "1.22", "1.23"]
21+
go: ["1.12", "1.21", "1.22", "1.23", "oldstable", "stable"]
1722

1823
steps:
1924
- name: Checkout repository
20-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2126

2227
- name: Set up Go
23-
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
28+
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
2429
with:
2530
go-version: ${{ matrix.go }}
2631

@@ -32,17 +37,18 @@ jobs:
3237
lint:
3338
name: Lint
3439
runs-on: ubuntu-latest
40+
timeout-minutes: 20 # guardrails timeout
3541

3642
steps:
3743
- name: Checkout repository
38-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
44+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3945

4046
- name: Set up Go
41-
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
47+
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
4248
with:
43-
go-version: "1.23"
49+
go-version: "stable"
4450

4551
- name: Lint
46-
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
52+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
4753
with:
48-
version: v1.63.4
54+
version: v2.7

.golangci.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1+
version: "2"
2+
13
linters:
2-
disable-all: true
34
enable:
5+
- errorlint
46
- nolintlint
7+
- revive
8+
- unconvert
9+
- unparam
10+
settings:
11+
staticcheck:
12+
# Enable all options, with some exceptions.
13+
# For defaults, see https://golangci-lint.run/usage/linters/#staticcheck
14+
checks:
15+
- all
16+
- -QF1008 # Omit embedded fields from selector expression; https://staticcheck.dev/docs/checks/#QF1008
17+
- -ST1003 # Poorly chosen identifier; https://staticcheck.dev/docs/checks/#ST1003
18+
19+
formatters:
20+
enable:
21+
- gofmt

bool_func_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestBoolFuncUsage(t *testing.T) {
5050
// regular boolfunc flag:
5151
// expect to see '--flag1' followed by the usageMessage, and no mention of a default value
5252
fset := NewFlagSet("unittest", ContinueOnError)
53-
fset.BoolFunc("flag1", "usage message", func(s string) error { return nil })
53+
fset.BoolFunc("flag1", "usage message", func(string) error { return nil })
5454
usage := fset.FlagUsagesWrapped(80)
5555

5656
usage = strings.TrimSpace(usage)
@@ -64,7 +64,7 @@ func TestBoolFuncUsage(t *testing.T) {
6464
// func flag, with a placeholder name:
6565
// if usageMesage contains a placeholder, expect '--flag2 {placeholder}'; still expect no mention of a default value
6666
fset := NewFlagSet("unittest", ContinueOnError)
67-
fset.BoolFunc("flag2", "usage message with `name` placeholder", func(s string) error { return nil })
67+
fset.BoolFunc("flag2", "usage message with `name` placeholder", func(string) error { return nil })
6868
usage := fset.FlagUsagesWrapped(80)
6969

7070
usage = strings.TrimSpace(usage)

bool_slice.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ func newBoolSliceValue(val []bool, p *[]bool) *boolSliceValue {
2222
// Set converts, and assigns, the comma-separated boolean argument string representation as the []bool value of this flag.
2323
// If Set is called on a flag that already has a []bool assigned, the newly converted values will be appended.
2424
func (s *boolSliceValue) Set(val string) error {
25-
2625
// remove all quote characters
2726
rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "")
2827

2928
// read flag arguments with CSV parser
3029
boolStrSlice, err := readAsCSV(rmQuote.Replace(val))
31-
if err != nil && err != io.EOF {
30+
if err != nil && err != io.EOF { //nolint:errorlint // not using errors.Is for compatibility with go1.12
3231
return err
3332
}
3433

@@ -60,7 +59,6 @@ func (s *boolSliceValue) Type() string {
6059

6160
// String defines a "native" format for this boolean slice flag value.
6261
func (s *boolSliceValue) String() string {
63-
6462
boolStrSlice := make([]string, len(*s.value))
6563
for i, b := range *s.value {
6664
boolStrSlice[i] = strconv.FormatBool(b)

bool_slice_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ func TestBSAsSliceValue(t *testing.T) {
184184
}
185185

186186
func TestBSBadQuoting(t *testing.T) {
187-
188187
tests := []struct {
189188
Want []bool
190189
FlagArg []string

bool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (v *triStateValue) IsBoolFlag() bool {
2626
}
2727

2828
func (v *triStateValue) Get() interface{} {
29-
return triStateValue(*v)
29+
return *v
3030
}
3131

3232
func (v *triStateValue) Set(s string) error {

bytes.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ func (bytesHex bytesHexValue) String() string {
1818
// Set implements pflag.Value.Set.
1919
func (bytesHex *bytesHexValue) Set(value string) error {
2020
bin, err := hex.DecodeString(strings.TrimSpace(value))
21-
2221
if err != nil {
2322
return err
2423
}
@@ -39,20 +38,18 @@ func newBytesHexValue(val []byte, p *[]byte) *bytesHexValue {
3938
}
4039

4140
func bytesHexConv(sval string) (interface{}, error) {
42-
4341
bin, err := hex.DecodeString(sval)
4442

4543
if err == nil {
4644
return bin, nil
4745
}
4846

49-
return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err)
47+
return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err.Error())
5048
}
5149

5250
// GetBytesHex return the []byte value of a flag with the given name
5351
func (f *FlagSet) GetBytesHex(name string) ([]byte, error) {
5452
val, err := f.getFlagType(name, "bytesHex", bytesHexConv)
55-
5653
if err != nil {
5754
return []byte{}, err
5855
}
@@ -119,7 +116,6 @@ func (bytesBase64 bytesBase64Value) String() string {
119116
// Set implements pflag.Value.Set.
120117
func (bytesBase64 *bytesBase64Value) Set(value string) error {
121118
bin, err := base64.StdEncoding.DecodeString(strings.TrimSpace(value))
122-
123119
if err != nil {
124120
return err
125121
}
@@ -140,19 +136,17 @@ func newBytesBase64Value(val []byte, p *[]byte) *bytesBase64Value {
140136
}
141137

142138
func bytesBase64ValueConv(sval string) (interface{}, error) {
143-
144139
bin, err := base64.StdEncoding.DecodeString(sval)
145140
if err == nil {
146141
return bin, nil
147142
}
148143

149-
return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err)
144+
return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err.Error())
150145
}
151146

152147
// GetBytesBase64 return the []byte value of a flag with the given name
153148
func (f *FlagSet) GetBytesBase64(name string) ([]byte, error) {
154149
val, err := f.getFlagType(name, "bytesBase64", bytesBase64ValueConv)
155-
156150
if err != nil {
157151
return []byte{}, err
158152
}

count.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func newCountValue(val int, p *int) *countValue {
1313
func (i *countValue) Set(s string) error {
1414
// "+1" means that no specific value was passed, so increment
1515
if s == "+1" {
16-
*i = countValue(*i + 1)
16+
*i = *i + 1
1717
return nil
1818
}
1919
v, err := strconv.ParseInt(s, 0, 0)

duration_slice.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pflag
22

33
import (
4-
"fmt"
54
"strings"
65
"time"
76
)
@@ -46,7 +45,7 @@ func (s *durationSliceValue) Type() string {
4645
func (s *durationSliceValue) String() string {
4746
out := make([]string, len(*s.value))
4847
for i, d := range *s.value {
49-
out[i] = fmt.Sprintf("%s", d)
48+
out[i] = d.String()
5049
}
5150
return "[" + strings.Join(out, ",") + "]"
5251
}
@@ -56,7 +55,7 @@ func (s *durationSliceValue) fromString(val string) (time.Duration, error) {
5655
}
5756

5857
func (s *durationSliceValue) toString(val time.Duration) string {
59-
return fmt.Sprintf("%s", val)
58+
return val.String()
6059
}
6160

6261
func (s *durationSliceValue) Append(val string) error {

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (e *InvalidSyntaxError) Error() string {
138138
return fmt.Sprintf("bad flag syntax: %s", e.specifiedFlag)
139139
}
140140

141-
// GetSpecifiedName returns the exact flag (with dashes) as it
141+
// GetSpecifiedFlag returns the exact flag (with dashes) as it
142142
// appeared in the parsed arguments.
143143
func (e *InvalidSyntaxError) GetSpecifiedFlag() string {
144144
return e.specifiedFlag

0 commit comments

Comments
 (0)