Skip to content

Commit c13a1d6

Browse files
committed
Add Linting
1 parent aa9b0e7 commit c13a1d6

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

.github/workflows/build.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ jobs:
2626
with:
2727
go-version-file: "go.mod"
2828

29+
- name: Lint
30+
uses: golangci/golangci-lint-action@v7
31+
with:
32+
version: latest
33+
2934
- name: Test
3035
run: go test ./...
3136

.golangci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "2"
2+
3+
run:
4+
timeout: 10m
5+
modules-download-mode: readonly
6+
7+
formatters:
8+
enable:
9+
- gofmt
10+
- goimports
11+
settings:
12+
goimports:
13+
local-prefixes:
14+
- github.com/staffbase/snapshot-operator
15+
16+
linters:
17+
default: none
18+
enable:
19+
- bodyclose
20+
- gosec
21+
- govet
22+
- ineffassign
23+
- noctx
24+
- staticcheck
25+
- unused
26+
- whitespace

yamllint-action.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func parseInput(r io.Reader) Report {
108108
Severity: severity,
109109
}
110110

111-
if _, exist := files[fileName]; exist == false {
111+
if _, exist := files[fileName]; exist {
112112
files[fileName] = &LinterResult{FilePath: fileName}
113113
}
114114

@@ -156,15 +156,15 @@ func handlePush(ctx context.Context, client *github.Client, report Report) error
156156
// find the action's checkrun
157157
checkName := os.Getenv("ACTION_NAME")
158158
result, _, err := client.Checks.ListCheckRunsForRef(ctx, owner, repoName, head, &github.ListCheckRunsOptions{
159-
CheckName: github.String(checkName),
160-
Status: github.String("in_progress"),
159+
CheckName: github.Ptr(checkName),
160+
Status: github.Ptr("in_progress"),
161161
})
162162
if err != nil {
163163
return err
164164
}
165165

166166
if len(result.CheckRuns) == 0 {
167-
return fmt.Errorf("Unable to find check run for action: %s", checkName)
167+
return fmt.Errorf("unable to find check run for action: %s", checkName)
168168
}
169169
checkRun := result.CheckRuns[0]
170170

@@ -177,12 +177,12 @@ func handlePush(ctx context.Context, client *github.Client, report Report) error
177177
if len(t.AssertionResults) > 0 {
178178
for _, a := range t.AssertionResults {
179179
annotations = append(annotations, &github.CheckRunAnnotation{
180-
Path: github.String(path),
181-
StartLine: github.Int(a.Line),
182-
EndLine: github.Int(a.Line),
183-
AnnotationLevel: github.String(a.Severity),
184-
Title: github.String(""),
185-
Message: github.String(a.Message),
180+
Path: github.Ptr(path),
181+
StartLine: github.Ptr(a.Line),
182+
EndLine: github.Ptr(a.Line),
183+
AnnotationLevel: github.Ptr(a.Severity),
184+
Title: github.Ptr(""),
185+
Message: github.Ptr(a.Message),
186186
})
187187
}
188188
}
@@ -202,8 +202,8 @@ func handlePush(ctx context.Context, client *github.Client, report Report) error
202202
}
203203

204204
output := &github.CheckRunOutput{
205-
Title: github.String("Result"),
206-
Summary: github.String(summary),
205+
Title: github.Ptr("Result"),
206+
Summary: github.Ptr(summary),
207207
Annotations: annotations[i:end],
208208
}
209209

0 commit comments

Comments
 (0)