Skip to content

Commit

Permalink
Merge pull request #66 from jacobbednarz/golint-swap
Browse files Browse the repository at this point in the history
cleanup CI
  • Loading branch information
jacobbednarz committed Aug 17, 2022
2 parents 574e8c2 + 72f8fca commit 9123d34
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Lint
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
jobs:
golangci-lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: "--config .golintci.yaml"
22 changes: 6 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
on: [push, pull_request]
on: [pull_request]
name: Test
env:
GOPROXY: "https://proxy.golang.org"

jobs:
test:
strategy:
matrix:
go-version: [1.18, 1.19]
go-version: [1.17, 1.18, 1.19]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
- name: setup go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
- name: checkout code
uses: actions/checkout@v3
- name: Format
run: gofmt -d .
- name: Lint
if: matrix.os != 'windows-latest'
run: |
go get -v -u golang.org/x/lint/golint
$(go env GOPATH)/bin/golint -set_exit_status .
- name: Vet
run: go vet $(go list ./... | grep -v /vendor/)
- name: Test
- name: test
run: go test -v -race ./...
32 changes: 32 additions & 0 deletions .golintci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 1m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

modules-download-mode: readonly

linters:
enable:
- bodyclose # ensure HTTP response bodies are successfully closed.
- contextcheck # check we are passing context an inherited context.
- gofmt # checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification.
- errname # checks that sentinel errors are prefixed with the `Err`` and error types are suffixed with the `Error``.
- errorlint # used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- godot # check if comments end in a period.
- misspell # finds commonly misspelled English words in comments.
- nilerr # checks that there is no simultaneous return of nil error and an invalid value.
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes.
- unparam # reports unused function parameters.
- whitespace # detection of leading and trailing whitespace.

output:
format: colored-line-number
8 changes: 4 additions & 4 deletions csp_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ var (
log.FieldKeyMsg: "message",
}

// Path to file which has blocked URI's per line
// Path to file which has blocked URI's per line.
blockedURIfile string

// Default URI Filter list
// Default URI Filter list.
ignoredBlockedURIs = []string{
"resource://",
"chromenull://",
Expand Down Expand Up @@ -85,7 +85,7 @@ var (
"bdvideo://error",
}

// TCP Port to listen on
// TCP Port to listen on.
listenPort int
)

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

func validateViolation(r CSPReport) error {
for _, value := range ignoredBlockedURIs {
if strings.HasPrefix(r.Body.BlockedURI, value) == true {
if strings.HasPrefix(r.Body.BlockedURI, value) {
err := fmt.Errorf("blocked URI ('%s') is an invalid resource", value)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion csp_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestValidateNonHttpDocumentURI(t *testing.T) {
DocumentURI: "about",
}}
validateErr := validateViolation(report)
if validateErr.Error() != fmt.Sprintf("document URI ('about') is invalid") {
if validateErr.Error() != "document URI ('about') is invalid" {
t.Errorf("expected error to include correct message string but it didn't")
}
}
Expand Down

0 comments on commit 9123d34

Please sign in to comment.