Skip to content

Commit 9123d34

Browse files
authored
Merge pull request #66 from jacobbednarz/golint-swap
cleanup CI
2 parents 574e8c2 + 72f8fca commit 9123d34

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

.github/workflows/lint.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- reopened
7+
- synchronize
8+
- ready_for_review
9+
jobs:
10+
golangci-lint:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: golangci-lint
16+
uses: golangci/golangci-lint-action@v3
17+
with:
18+
version: latest
19+
args: "--config .golintci.yaml"

.github/workflows/test.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
on: [push, pull_request]
1+
on: [pull_request]
22
name: Test
3-
env:
4-
GOPROXY: "https://proxy.golang.org"
3+
54
jobs:
65
test:
76
strategy:
87
matrix:
9-
go-version: [1.18, 1.19]
8+
go-version: [1.17, 1.18, 1.19]
109
os: [ubuntu-latest, macos-latest, windows-latest]
1110
runs-on: ${{ matrix.os }}
1211
steps:
13-
- name: Install Go
12+
- name: setup go
1413
uses: actions/setup-go@v3
1514
with:
1615
go-version: ${{ matrix.go-version }}
17-
- name: Checkout code
16+
- name: checkout code
1817
uses: actions/checkout@v3
19-
- name: Format
20-
run: gofmt -d .
21-
- name: Lint
22-
if: matrix.os != 'windows-latest'
23-
run: |
24-
go get -v -u golang.org/x/lint/golint
25-
$(go env GOPATH)/bin/golint -set_exit_status .
26-
- name: Vet
27-
run: go vet $(go list ./... | grep -v /vendor/)
28-
- name: Test
18+
- name: test
2919
run: go test -v -race ./...

.golintci.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
run:
2+
# timeout for analysis, e.g. 30s, 5m, default is 1m
3+
timeout: 1m
4+
5+
# exit code when at least one issue was found, default is 1
6+
issues-exit-code: 1
7+
8+
# include test files or not, default is true
9+
tests: true
10+
11+
# default is true. Enables skipping of directories:
12+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
13+
skip-dirs-use-default: true
14+
15+
modules-download-mode: readonly
16+
17+
linters:
18+
enable:
19+
- bodyclose # ensure HTTP response bodies are successfully closed.
20+
- contextcheck # check we are passing context an inherited context.
21+
- gofmt # checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification.
22+
- errname # checks that sentinel errors are prefixed with the `Err`` and error types are suffixed with the `Error``.
23+
- errorlint # used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
24+
- godot # check if comments end in a period.
25+
- misspell # finds commonly misspelled English words in comments.
26+
- nilerr # checks that there is no simultaneous return of nil error and an invalid value.
27+
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes.
28+
- unparam # reports unused function parameters.
29+
- whitespace # detection of leading and trailing whitespace.
30+
31+
output:
32+
format: colored-line-number

csp_collector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ var (
5454
log.FieldKeyMsg: "message",
5555
}
5656

57-
// Path to file which has blocked URI's per line
57+
// Path to file which has blocked URI's per line.
5858
blockedURIfile string
5959

60-
// Default URI Filter list
60+
// Default URI Filter list.
6161
ignoredBlockedURIs = []string{
6262
"resource://",
6363
"chromenull://",
@@ -85,7 +85,7 @@ var (
8585
"bdvideo://error",
8686
}
8787

88-
// TCP Port to listen on
88+
// TCP Port to listen on.
8989
listenPort int
9090
)
9191

@@ -219,7 +219,7 @@ func handleViolationReport(w http.ResponseWriter, r *http.Request) {
219219

220220
func validateViolation(r CSPReport) error {
221221
for _, value := range ignoredBlockedURIs {
222-
if strings.HasPrefix(r.Body.BlockedURI, value) == true {
222+
if strings.HasPrefix(r.Body.BlockedURI, value) {
223223
err := fmt.Errorf("blocked URI ('%s') is an invalid resource", value)
224224
return err
225225
}

csp_collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestValidateNonHttpDocumentURI(t *testing.T) {
183183
DocumentURI: "about",
184184
}}
185185
validateErr := validateViolation(report)
186-
if validateErr.Error() != fmt.Sprintf("document URI ('about') is invalid") {
186+
if validateErr.Error() != "document URI ('about') is invalid" {
187187
t.Errorf("expected error to include correct message string but it didn't")
188188
}
189189
}

0 commit comments

Comments
 (0)