Skip to content

Commit 8b61a4e

Browse files
authored
bringing linter up to date (#95)
1 parent 58f2e47 commit 8b61a4e

8 files changed

Lines changed: 137 additions & 106 deletions

File tree

.github/workflows/lint.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
- v1
6+
pull_request:
7+
branches:
8+
- "**"
9+
name: Linter
10+
jobs:
11+
golangci:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
path: src/github.com/unrolled/secure
17+
- uses: golangci/golangci-lint-action@v4
18+
with:
19+
working-directory: src/github.com/unrolled/secure

.github/workflows/test.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ on:
66
pull_request:
77
branches:
88
- "**"
9-
name: tests
9+
name: Tests
1010
jobs:
1111
tests:
1212
strategy:
1313
matrix:
14-
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x]
14+
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
1515
os: [ubuntu-latest]
1616
runs-on: ${{ matrix.os }}
1717
steps:
18-
- name: Install Go
19-
uses: actions/setup-go@v2
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
2020
with:
2121
go-version: ${{ matrix.go-version }}
22-
- name: Checkout code
23-
uses: actions/checkout@v2
24-
- name: Test
25-
run: make ci
22+
- run: make ci
2623
golangci:
2724
runs-on: ubuntu-latest
2825
steps:
29-
- uses: actions/checkout@v2
30-
- name: golangci-lint
31-
uses: golangci/golangci-lint-action@v2
26+
- uses: actions/checkout@v4
27+
with:
28+
path: src/github.com/unrolled/secure
29+
- uses: golangci/golangci-lint-action@v4
30+
with:
31+
working-directory: src/github.com/7shifts/seven-deploy

.golangci.yaml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
run:
2-
timeout: 5m
2+
timeout: 10m
3+
modules-download-mode: readonly
4+
allow-parallel-runners: true
35

46
linters:
57
enable-all: true
68
disable:
7-
# Deprecated linters
8-
- varcheck
9-
- exhaustivestruct
10-
- ifshort
11-
- structcheck
12-
- golint
13-
- maligned
14-
- interfacer
15-
- nosnakecase
16-
- deadcode
17-
- scopelint
18-
- rowserrcheck
19-
- sqlclosecheck
20-
- structcheck
21-
- wastedassign
22-
# Ignoring
23-
- lll
24-
- varnamelen
259
- paralleltest
26-
- testpackage
27-
- goerr113
10+
- gochecknoglobals
2811
- exhaustruct
29-
- nestif
12+
- wrapcheck
13+
- tagliatelle
14+
- depguard
15+
- ireturn
3016
- funlen
31-
- goconst
17+
- varnamelen
18+
- gomnd
19+
- execinquery
20+
- copyloopvar
21+
- intrange
22+
- gocognit
23+
- lll
3224
- cyclop
3325
- gocyclo
34-
- gocognit
26+
- testpackage
27+
- err113
28+
- nestif
3529
- maintidx
3630
- contextcheck
31+
- perfsprint

csp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type key int
1212

1313
const cspNonceKey key = iota
1414

15-
// CSPNonce returns the nonce value associated with the present request. If no nonce has been generated it returns an empty string.
15+
// CSPNonce returns the nonce value associated with the present request.
16+
// If no nonce has been generated it returns an empty string.
1617
func CSPNonce(c context.Context) string {
1718
if val, ok := c.Value(cspNonceKey).(string); ok {
1819
return val

csp_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ func TestCSPNonce(t *testing.T) {
2323
}{
2424
{Options{ContentSecurityPolicy: csp}, []string{"Content-Security-Policy"}},
2525
{Options{ContentSecurityPolicyReportOnly: csp}, []string{"Content-Security-Policy-Report-Only"}},
26-
{Options{ContentSecurityPolicy: csp, ContentSecurityPolicyReportOnly: csp}, []string{"Content-Security-Policy", "Content-Security-Policy-Report-Only"}},
26+
{
27+
Options{ContentSecurityPolicy: csp, ContentSecurityPolicyReportOnly: csp},
28+
[]string{"Content-Security-Policy", "Content-Security-Policy-Report-Only"},
29+
},
2730
}
2831

2932
for _, c := range cases {

cspbuilder/builder_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestContentSecurityPolicyBuilder_Build_SingleDirective(t *testing.T) {
4242
tt.directiveName: tt.directiveValues,
4343
},
4444
}
45+
4546
got, err := builder.Build()
4647
if (err != nil) != tt.wantErr {
4748
t.Errorf("ContentSecurityPolicyBuilder.Build() error = %v, wantErr %v", err, tt.wantErr)
@@ -92,6 +93,7 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
9293
builder := &Builder{
9394
Directives: tt.directives,
9495
}
96+
9597
got, err := builder.Build()
9698
if (err != nil) != tt.wantErr {
9799
t.Errorf("ContentSecurityPolicyBuilder.Build() error = %v, wantErr %v", err, tt.wantErr)
@@ -101,13 +103,15 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
101103

102104
{
103105
startsWithDirective := false
106+
104107
for directive := range tt.directives {
105108
if strings.HasPrefix(got, directive) {
106109
startsWithDirective = true
107110

108111
break
109112
}
110113
}
114+
111115
if !startsWithDirective {
112116
t.Errorf("ContentSecurityPolicyBuilder.Build() = '%v', does not start with directive name", got)
113117
}
@@ -116,6 +120,7 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
116120
if strings.HasSuffix(got, " ") {
117121
t.Errorf("ContentSecurityPolicyBuilder.Build() = '%v', ends on whitespace", got)
118122
}
123+
119124
if strings.HasSuffix(got, ";") {
120125
t.Errorf("ContentSecurityPolicyBuilder.Build() = '%v', ends on semi-colon", got)
121126
}

cspbuilder/directive_builder_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func TestBuildDirectiveFrameAncestors(t *testing.T) {
7979
for _, tt := range tests {
8080
t.Run(tt.name, func(t *testing.T) {
8181
sb := &strings.Builder{}
82+
8283
err := buildDirectiveFrameAncestors(sb, tt.values)
8384
if tt.wantErr && err != nil {
8485
return
@@ -222,6 +223,7 @@ func TestBuildDirectiveTrustedTypes(t *testing.T) {
222223
for _, tt := range tests {
223224
t.Run(tt.name, func(t *testing.T) {
224225
sb := &strings.Builder{}
226+
225227
err := buildDirectiveTrustedTypes(sb, tt.values)
226228
if tt.wantErr && err != nil {
227229
return

0 commit comments

Comments
 (0)