Skip to content

Commit

Permalink
bringing linter up to date (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
unrolled authored Jun 21, 2024
1 parent 58f2e47 commit 8b61a4e
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 106 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
push:
branches:
- master
- v1
pull_request:
branches:
- "**"
name: Linter
jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: src/github.com/unrolled/secure
- uses: golangci/golangci-lint-action@v4
with:
working-directory: src/github.com/unrolled/secure
22 changes: 11 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ on:
pull_request:
branches:
- "**"
name: tests
name: Tests
jobs:
tests:
strategy:
matrix:
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x]
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: make ci
- run: make ci
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- uses: actions/checkout@v4
with:
path: src/github.com/unrolled/secure
- uses: golangci/golangci-lint-action@v4
with:
working-directory: src/github.com/7shifts/seven-deploy
43 changes: 19 additions & 24 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
run:
timeout: 5m
timeout: 10m
modules-download-mode: readonly
allow-parallel-runners: true

linters:
enable-all: true
disable:
# Deprecated linters
- varcheck
- exhaustivestruct
- ifshort
- structcheck
- golint
- maligned
- interfacer
- nosnakecase
- deadcode
- scopelint
- rowserrcheck
- sqlclosecheck
- structcheck
- wastedassign
# Ignoring
- lll
- varnamelen
- paralleltest
- testpackage
- goerr113
- gochecknoglobals
- exhaustruct
- nestif
- wrapcheck
- tagliatelle
- depguard
- ireturn
- funlen
- goconst
- varnamelen
- gomnd
- execinquery
- copyloopvar
- intrange
- gocognit
- lll
- cyclop
- gocyclo
- gocognit
- testpackage
- err113
- nestif
- maintidx
- contextcheck
- perfsprint
3 changes: 2 additions & 1 deletion csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type key int

const cspNonceKey key = iota

// CSPNonce returns the nonce value associated with the present request. If no nonce has been generated it returns an empty string.
// CSPNonce returns the nonce value associated with the present request.
// If no nonce has been generated it returns an empty string.
func CSPNonce(c context.Context) string {
if val, ok := c.Value(cspNonceKey).(string); ok {
return val
Expand Down
5 changes: 4 additions & 1 deletion csp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ func TestCSPNonce(t *testing.T) {
}{
{Options{ContentSecurityPolicy: csp}, []string{"Content-Security-Policy"}},
{Options{ContentSecurityPolicyReportOnly: csp}, []string{"Content-Security-Policy-Report-Only"}},
{Options{ContentSecurityPolicy: csp, ContentSecurityPolicyReportOnly: csp}, []string{"Content-Security-Policy", "Content-Security-Policy-Report-Only"}},
{
Options{ContentSecurityPolicy: csp, ContentSecurityPolicyReportOnly: csp},
[]string{"Content-Security-Policy", "Content-Security-Policy-Report-Only"},
},
}

for _, c := range cases {
Expand Down
5 changes: 5 additions & 0 deletions cspbuilder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestContentSecurityPolicyBuilder_Build_SingleDirective(t *testing.T) {
tt.directiveName: tt.directiveValues,
},
}

got, err := builder.Build()
if (err != nil) != tt.wantErr {
t.Errorf("ContentSecurityPolicyBuilder.Build() error = %v, wantErr %v", err, tt.wantErr)
Expand Down Expand Up @@ -92,6 +93,7 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
builder := &Builder{
Directives: tt.directives,
}

got, err := builder.Build()
if (err != nil) != tt.wantErr {
t.Errorf("ContentSecurityPolicyBuilder.Build() error = %v, wantErr %v", err, tt.wantErr)
Expand All @@ -101,13 +103,15 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {

{
startsWithDirective := false

for directive := range tt.directives {
if strings.HasPrefix(got, directive) {
startsWithDirective = true

break
}
}

if !startsWithDirective {
t.Errorf("ContentSecurityPolicyBuilder.Build() = '%v', does not start with directive name", got)
}
Expand All @@ -116,6 +120,7 @@ func TestContentSecurityPolicyBuilder_Build_MultipleDirectives(t *testing.T) {
if strings.HasSuffix(got, " ") {
t.Errorf("ContentSecurityPolicyBuilder.Build() = '%v', ends on whitespace", got)
}

if strings.HasSuffix(got, ";") {
t.Errorf("ContentSecurityPolicyBuilder.Build() = '%v', ends on semi-colon", got)
}
Expand Down
2 changes: 2 additions & 0 deletions cspbuilder/directive_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestBuildDirectiveFrameAncestors(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sb := &strings.Builder{}

err := buildDirectiveFrameAncestors(sb, tt.values)
if tt.wantErr && err != nil {
return
Expand Down Expand Up @@ -222,6 +223,7 @@ func TestBuildDirectiveTrustedTypes(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sb := &strings.Builder{}

err := buildDirectiveTrustedTypes(sb, tt.values)
if tt.wantErr && err != nil {
return
Expand Down
Loading

0 comments on commit 8b61a4e

Please sign in to comment.