Skip to content

Commit

Permalink
Upgrade to go 1.16, use go:embed for loading default rules (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinelfring committed Mar 27, 2021
1 parent 54b580d commit 391fce2
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 367 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-actions-up-to-date-with-dependabot
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
4 changes: 0 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ jobs:
steps:
- name: Pull new module version
uses: andrewslotin/go-proxy-pull-action@v1.0.0
- name: Pull new module version
uses: andrewslotin/go-proxy-pull-action@v1.0.0
with:
goproxy: https://gocenter.io
18 changes: 5 additions & 13 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.15.x]
go-version: [1.16.x]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: Tests
Expand Down Expand Up @@ -41,12 +41,12 @@ jobs:
name: Build
strategy:
matrix:
go-version: [1.15.x]
go-version: [1.16.x]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: ‘2’
fetch-depth: '2'

- name: Setup Go
uses: actions/setup-go@v2
Expand All @@ -64,10 +64,6 @@ jobs:
run: |
go mod download
- name: Check that go generate produced no diff
run: |
go generate -x ./... && git diff --exit-code
- name: Run Unit tests
run: |
go test -race -covermode=atomic -coverprofile=coverage.txt ./...
Expand All @@ -80,13 +76,9 @@ jobs:
lint:
strategy:
matrix:
go-version: [1.15.x]
go-version: [1.16.x]
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.31
- uses: golangci/golangci-lint-action@v2
2 changes: 1 addition & 1 deletion .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16

- name: Login docker.io
run: docker login -u celfring -p ${{ secrets.DOCKER_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/woke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16

- uses: actions/cache@v2
with:
Expand Down
3 changes: 1 addition & 2 deletions .wokeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pkg/**/*_test.go
pkg/rule/default.go
internal/rule/default.yaml
pkg/rule/default.yaml
example.yaml
README.md
testdata
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ This has whitelist from stdin

### Rules

A set of default rules is provided in [`pkg/rule/default.go`](https://github.com/get-woke/woke/blob/main/pkg/rule/default.go).
A set of default rules is provided in [`pkg/rule/default.yaml`](https://github.com/get-woke/woke/blob/main/pkg/rule/default.yaml).

Configure your custom rules config in `.woke.yaml` or `.woke.yml`. `woke` uses the following precedence order. Each item takes precedence over the item below it:

Expand Down
2 changes: 1 addition & 1 deletion dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM golang:1.15
FROM golang:1.16

RUN apt-get update && apt-get install -y inotify-tools

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/get-woke/woke

go 1.15
go 1.16

require (
github.com/fatih/color v1.10.0
Expand Down
95 changes: 0 additions & 95 deletions internal/rule/default.yaml

This file was deleted.

104 changes: 0 additions & 104 deletions internal/rule/gen.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func parsePathTests(t *testing.T) {
Filename: filename,
Results: []result.Result{
result.LineResult{
Rule: &rule.WhitelistRule,
Rule: &rule.TestRule,
Violation: "whitelist",
Line: "i have a whitelist",
StartPosition: &token.Position{
Expand Down Expand Up @@ -163,7 +163,7 @@ func parsePathTests(t *testing.T) {
Filename: filename,
Results: []result.Result{
result.LineResult{
Rule: &rule.WhitelistRule,
Rule: &rule.TestRule,
Violation: "whitelist",
Line: "i have a whitelist here",
StartPosition: &token.Position{
Expand Down
2 changes: 1 addition & 1 deletion pkg/parser/violations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGenerateFileViolations(t *testing.T) {
Results: make([]result.Result, 1),
}
expected.Results[0] = result.LineResult{
Rule: &rule.WhitelistRule,
Rule: &rule.TestRule,
Violation: "whitelist",
Line: tc.line,
StartPosition: &token.Position{
Expand Down
2 changes: 1 addition & 1 deletion pkg/printer/githubactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestFormatResultForGitHubAction(t *testing.T) {
testResult := result.LineResult{
Rule: &rule.WhitelistRule,
Rule: &rule.TestRule,
Violation: "whitelist",
StartPosition: &token.Position{
Filename: "my/file",
Expand Down
2 changes: 1 addition & 1 deletion pkg/printer/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func TestJSON_Print(t *testing.T) {
assert.NoError(t, p.Print(buf, res))
got := buf.String()

expected := `{"Filename":"foo.txt","Results":[{"Rule":{"Name":"blacklist","Terms":["blacklist","black-list","blacklisted","black-listed"],"Alternatives":["denylist","blocklist"],"Note":"","Severity":"warning","Options":{"WordBoundary":false}},"Violation":"blacklist","Line":"this blacklist must change","StartPosition":{"Filename":"foo.txt","Offset":0,"Line":1,"Column":6},"EndPosition":{"Filename":"foo.txt","Offset":0,"Line":1,"Column":15},"Reason":"` + "`blacklist`" + ` may be insensitive, use ` + "`denylist`" + `, ` + "`blocklist`" + ` instead"}]}` + "\n"
expected := `{"Filename":"foo.txt","Results":[{"Rule":{"Name":"whitelist","Terms":["whitelist","white-list","whitelisted","white-listed"],"Alternatives":["allowlist"],"Note":"","Severity":"warning","Options":{"WordBoundary":false}},"Violation":"whitelist","Line":"this whitelist must change","StartPosition":{"Filename":"foo.txt","Offset":0,"Line":1,"Column":6},"EndPosition":{"Filename":"foo.txt","Offset":0,"Line":1,"Column":15},"Reason":"` + "`whitelist`" + ` may be insensitive, use ` + "`allowlist`" + ` instead"}]}` + "\n"
assert.Equal(t, expected, got)
}
6 changes: 3 additions & 3 deletions pkg/printer/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func generateFileResult() *result.FileResults {
func generateResults(filename string) []result.Result {
return []result.Result{
result.LineResult{
Rule: &rule.BlacklistRule,
Violation: "blacklist",
Line: "this blacklist must change",
Rule: &rule.TestRule,
Violation: "whitelist",
Line: "this whitelist must change",
StartPosition: &token.Position{
Filename: filename,
Offset: 0,
Expand Down
8 changes: 4 additions & 4 deletions pkg/result/fileresult_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (
)

func TestFileResult_String(t *testing.T) {
rs := FindResults(&rule.WhitelistRule, "my/file", "this has the term whitelist", 1)
rs := FindResults(&rule.TestRule, "my/file", "this has the term whitelist", 1)
fr := FileResults{Filename: "my/file", Results: rs}
assert.Equal(t, "my/file\n my/file:1:18-my/file:1:27 warning `whitelist` may be insensitive, use `allowlist` instead", fr.String())

rs = FindResults(&rule.WhitelistRule, "my/file", "this has no rule violations", 1)
rs = FindResults(&rule.TestRule, "my/file", "this has no rule violations", 1)
fr = FileResults{Filename: "my/file", Results: rs}
assert.Equal(t, "my/file", fr.String())
}

func TestFileResult_Sort(t *testing.T) {
rs1 := FindResults(&rule.WhitelistRule, "my/file", "this has a few whitelist white-list whitelist", 1)
rs2 := FindResults(&rule.WhitelistRule, "my/file", "this whitelist has a few white-list whitelist", 2)
rs1 := FindResults(&rule.TestRule, "my/file", "this has a few whitelist white-list whitelist", 1)
rs2 := FindResults(&rule.TestRule, "my/file", "this whitelist has a few white-list whitelist", 2)

rs := append(rs2, rs1...)

Expand Down
Loading

0 comments on commit 391fce2

Please sign in to comment.