Skip to content

Commit 41e1e0d

Browse files
authored
Merge pull request #200 from cli/babakks/upgrade-golangci-lint
Upgrade Golangci-lint to `v2.6`
2 parents f51c104 + f6d1f60 commit 41e1e0d

File tree

18 files changed

+76
-40
lines changed

18 files changed

+76
-40
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
go mod tidy
2121
git diff --exit-code go.mod
2222
23-
- name: Lint
24-
uses: golangci/golangci-lint-action@v6
23+
- name: lint
24+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2525
with:
26-
version: v1.64
26+
version: v2.6.0
2727
problem-matchers: true

.golangci.yml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1+
version: "2"
12
linters:
23
enable:
3-
- gofmt
4-
- godot
4+
- godot
5+
settings:
6+
staticcheck:
7+
# Here, some checks are disabled (note the leading minus sign).
8+
checks:
9+
- all
10+
# These are disabled by the linter's default. We need to repeat them here
11+
# since we're overriding to disable more checks.
12+
- -ST1000
13+
- -ST1003
14+
- -ST1016
15+
- -ST1020
16+
- -ST1021
17+
- -ST1022
518

6-
linters-settings:
7-
godot:
8-
# comments to be checked: `declarations`, `toplevel`, or `all`
9-
scope: declarations
10-
# check that each sentence starts with a capital letter
11-
capital: true
19+
# This check is to enforce "omitting embedded fields from selector
20+
# expression". For example, `m.Kind` in favour of `m.Node.Kind` (where
21+
# `Node` is an embedded struct field of `m`)
22+
#
23+
# Disabled to keep the current explicit style.
24+
- -QF1008
25+
godot:
26+
# comments to be checked: `declarations`, `toplevel`, or `all`
27+
scope: declarations
28+
# check that each sentence starts with a capital letter
29+
capital: true
30+
exclusions:
31+
generated: lax
32+
presets:
33+
- comments
34+
- common-false-positives
35+
- legacy
36+
- std-error-handling
37+
formatters:
38+
enable:
39+
- gofmt
40+
exclusions:
41+
generated: lax
42+
issues:
43+
max-issues-per-linter: 0
44+
max-same-issues: 0

gh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func ExecContext(ctx context.Context, args ...string) (stdout, stderr bytes.Buff
3636
return
3737
}
3838

39-
// Exec invokes a gh command in a subprocess with its stdin, stdout, and stderr streams connected to
39+
// ExecInteractive invokes a gh command in a subprocess with its stdin, stdout, and stderr streams connected to
4040
// those of the parent process. This is suitable for running gh commands with interactive prompts.
4141
func ExecInteractive(ctx context.Context, args ...string) error {
4242
ghExe, err := Path()

internal/git/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func Remotes() (RemoteSet, error) {
5151
return remotes, nil
5252
}
5353

54-
// Filter remotes by given hostnames, maintains original order.
54+
// FilterByHosts filters remotes by given hostnames, maintains original order.
5555
func (rs RemoteSet) FilterByHosts(hosts []string) RemoteSet {
5656
filtered := make(RemoteSet, 0)
5757
for _, remote := range rs {

internal/git/url.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func ParseURL(rawURL string) (u *url.URL, err error) {
6464
return
6565
}
6666

67-
// Extract GitHub repository information from a git remote URL.
67+
// RepoInfoFromURL extracts GitHub repository information from a git remote URL.
6868
func RepoInfoFromURL(u *url.URL) (host string, owner string, name string, err error) {
6969
if u.Hostname() == "" {
7070
return "", "", "", fmt.Errorf("no hostname detected")

internal/yamlmap/yaml_map.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func (m *Map) SetEntry(key string, value *Map) {
149149
m.AddEntry(key, value)
150150
}
151151

152+
// SetModified marks the map as modified.
153+
//
152154
// Note: This is a hack to introduce the concept of modified/unmodified
153155
// on top of gopkg.in/yaml.v3. This works by setting the Value property
154156
// of a MappingNode to a specific value and then later checking if the
@@ -166,14 +168,11 @@ func (m *Map) SetModified() {
166168
}
167169
}
168170

169-
// Traverse map using BFS to set all nodes as unmodified.
171+
// SetUnmodified traverses the map using BFS to set all nodes as unmodified.
170172
func (m *Map) SetUnmodified() {
171173
i := 0
172174
queue := []*yaml.Node{m.Node}
173-
for {
174-
if i > (len(queue) - 1) {
175-
break
176-
}
175+
for i < len(queue) {
177176
q := queue[i]
178177
i = i + 1
179178
if q.Kind != yaml.MappingNode {
@@ -184,14 +183,11 @@ func (m *Map) SetUnmodified() {
184183
}
185184
}
186185

187-
// Traverse map using BFS to searach for any nodes that have been modified.
186+
// IsModified traverses the map using BFS to search for any nodes that have been modified.
188187
func (m *Map) IsModified() bool {
189188
i := 0
190189
queue := []*yaml.Node{m.Node}
191-
for {
192-
if i > (len(queue) - 1) {
193-
break
194-
}
190+
for i < len(queue) {
195191
q := queue[i]
196192
i = i + 1
197193
if q.Kind != yaml.MappingNode {

pkg/api/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type HTTPErrorItem struct {
2727
Resource string
2828
}
2929

30-
// Allow HTTPError to satisfy error interface.
30+
// Error allows HTTPError to satisfy error interface.
3131
func (err *HTTPError) Error() string {
3232
if msgs := strings.SplitN(err.Message, "\n", 2); len(msgs) > 1 {
3333
return fmt.Sprintf("HTTP %d: %s (%s)\n%s", err.StatusCode, msgs[0], err.RequestURL, msgs[1])
@@ -55,7 +55,7 @@ type GraphQLErrorItem struct {
5555
Type string
5656
}
5757

58-
// Allow GraphQLError to satisfy error interface.
58+
// Error allows GraphQLError to satisfy error interface.
5959
func (gr *GraphQLError) Error() string {
6060
errorMessages := make([]string, 0, len(gr.Errors))
6161
for _, e := range gr.Errors {

pkg/api/graphql_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func DefaultGraphQLClient() (*GraphQLClient, error) {
2626
return NewGraphQLClient(ClientOptions{})
2727
}
2828

29-
// GraphQLClient builds a client to send requests to GitHub GraphQL API endpoints.
29+
// NewGraphQLClient builds a client to send requests to GitHub GraphQL API endpoints.
30+
//
3031
// As part of the configuration a hostname, auth token, default set of headers,
3132
// and unix domain socket are resolved from the gh environment configuration.
3233
// These behaviors can be overridden using the opts argument.

pkg/api/http_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func DefaultHTTPClient() (*http.Client, error) {
3737
return NewHTTPClient(ClientOptions{})
3838
}
3939

40-
// HTTPClient builds a client that can be passed to another library.
40+
// NewHTTPClient builds a client that can be passed to another library.
41+
//
4142
// As part of the configuration a hostname, auth token, default set of headers,
4243
// and unix domain socket are resolved from the gh environment configuration.
4344
// These behaviors can be overridden using the opts argument. In this instance

pkg/api/rest_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func DefaultRESTClient() (*RESTClient, error) {
2222
return NewRESTClient(ClientOptions{})
2323
}
2424

25-
// RESTClient builds a client to send requests to GitHub REST API endpoints.
25+
// NewRESTClient builds a client to send requests to GitHub REST API endpoints.
26+
//
2627
// As part of the configuration a hostname, auth token, default set of headers,
2728
// and unix domain socket are resolved from the gh environment configuration.
2829
// These behaviors can be overridden using the opts argument.

0 commit comments

Comments
 (0)