Skip to content

Commit 538112e

Browse files
committed
chore: CI and linter
1 parent 85531ac commit 538112e

26 files changed

+542
-311
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
11+
main:
12+
name: Main Process
13+
runs-on: ubuntu-latest
14+
env:
15+
GO_VERSION: 1.19
16+
GOLANGCI_LINT_VERSION: v1.50.0
17+
CGO_ENABLED: 0
18+
19+
steps:
20+
21+
# https://github.com/marketplace/actions/setup-go-environment
22+
- name: Set up Go ${{ env.GO_VERSION }}
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: ${{ env.GO_VERSION }}
26+
27+
# https://github.com/marketplace/actions/checkout
28+
- name: Check out code
29+
uses: actions/checkout@v2
30+
with:
31+
fetch-depth: 0
32+
33+
# https://github.com/marketplace/actions/cache
34+
- name: Cache Go modules
35+
uses: actions/cache@v2
36+
with:
37+
path: ~/go/pkg/mod
38+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
39+
restore-keys: |
40+
${{ runner.os }}-go-
41+
42+
- name: Check and get dependencies
43+
run: |
44+
go mod tidy
45+
git diff --exit-code go.mod
46+
git diff --exit-code go.sum
47+
48+
# https://golangci-lint.run/usage/install#other-ci
49+
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
50+
run: |
51+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
52+
golangci-lint --version
53+
54+
- name: Make
55+
run: make

.github/workflows/go-cross.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Go Matrix
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
jobs:
9+
10+
cross:
11+
name: Go
12+
runs-on: ${{ matrix.os }}
13+
env:
14+
CGO_ENABLED: 0
15+
16+
strategy:
17+
matrix:
18+
go-version: [ 1.19, 1.x ]
19+
os: [ubuntu-latest, macos-latest, windows-latest]
20+
21+
steps:
22+
# https://github.com/marketplace/actions/setup-go-environment
23+
- name: Set up Go ${{ matrix.go-version }}
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: ${{ matrix.go-version }}
27+
28+
# https://github.com/marketplace/actions/checkout
29+
- name: Checkout code
30+
uses: actions/checkout@v2
31+
32+
# https://github.com/marketplace/actions/cache
33+
- name: Cache Go modules
34+
uses: actions/cache@v2
35+
with:
36+
# In order:
37+
# * Module download cache
38+
# * Build cache (Linux)
39+
# * Build cache (Mac)
40+
# * Build cache (Windows)
41+
path: |
42+
~/go/pkg/mod
43+
~/.cache/go-build
44+
~/Library/Caches/go-build
45+
%LocalAppData%\go-build
46+
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
47+
restore-keys: |
48+
${{ runner.os }}-${{ matrix.go-version }}-go-
49+
50+
- name: Test
51+
run: go test -v -cover ./...
52+
53+
- name: Build
54+
run: go build -v -ldflags "-s -w" -trimpath

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Release a tag"
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
7+
jobs:
8+
release:
9+
name: Release Process
10+
runs-on: ubuntu-latest
11+
env:
12+
GO_VERSION: 1.19
13+
CGO_ENABLED: 0
14+
15+
steps:
16+
17+
# https://github.com/marketplace/actions/setup-go-environment
18+
- name: Set up Go ${{ env.GO_VERSION }}
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: ${{ env.GO_VERSION }}
22+
23+
# https://github.com/marketplace/actions/checkout
24+
- name: Check out code
25+
uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0
28+
29+
# https://goreleaser.com/ci/actions/
30+
- name: Run GoReleaser
31+
uses: goreleaser/goreleaser-action@v2
32+
with:
33+
version: latest
34+
args: release --rm-dist
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ bin/
33
vendor/
44

55
.idea/
6+
/misspell
67

78
# editor turds
89
*~

.golangci.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
run:
2+
timeout: 2m
3+
skip-files: []
4+
5+
linters-settings:
6+
govet:
7+
enable-all: true
8+
disable:
9+
- fieldalignment
10+
- shadow # FIXME(ldez) must be fixed
11+
gocyclo:
12+
min-complexity: 16
13+
goconst:
14+
min-len: 3
15+
min-occurrences: 3
16+
misspell:
17+
locale: US
18+
funlen:
19+
lines: -1
20+
statements: 40
21+
gofumpt:
22+
extra-rules: true
23+
depguard:
24+
list-type: blacklist
25+
include-go-root: false
26+
packages:
27+
- github.com/pkg/errors
28+
godox:
29+
keywords:
30+
- FIXME
31+
gocritic:
32+
enabled-tags:
33+
- diagnostic
34+
- style
35+
- performance
36+
disabled-checks:
37+
- sloppyReassign
38+
- rangeValCopy
39+
- octalLiteral
40+
- paramTypeCombine # already handle by gofumpt.extra-rules
41+
- exitAfterDefer # FIXME(ldez) must be fixed
42+
- ifElseChain # FIXME(ldez) must be fixed
43+
settings:
44+
hugeParam:
45+
sizeThreshold: 100
46+
forbidigo:
47+
forbid:
48+
- '^print(ln)?$'
49+
- '^panic$'
50+
- '^spew\.Print(f|ln)?$'
51+
- '^spew\.Dump$'
52+
53+
linters:
54+
enable-all: true
55+
disable:
56+
- deadcode # deprecated
57+
- exhaustivestruct # deprecated
58+
- golint # deprecated
59+
- ifshort # deprecated
60+
- interfacer # deprecated
61+
- maligned # deprecated
62+
- nosnakecase # deprecated
63+
- scopelint # deprecated
64+
- scopelint # deprecated
65+
- structcheck # deprecated
66+
- varcheck # deprecated
67+
- execinquery # not relevant (SQL)
68+
- rowserrcheck # not relevant (SQL)
69+
- sqlclosecheck # not relevant (SQL)
70+
- cyclop # duplicate of gocyclo
71+
- dupl
72+
- exhaustive
73+
- exhaustruct
74+
- forbidigo
75+
- gochecknoglobals
76+
- gochecknoinits
77+
- goerr113
78+
- gomnd
79+
- lll
80+
- nilnil
81+
- nlreturn
82+
- paralleltest
83+
- prealloc
84+
- testpackage
85+
- tparallel
86+
- varnamelen
87+
- wrapcheck
88+
- wsl
89+
- misspell
90+
- gosec # FIXME(ldez) must be fixed
91+
- errcheck # FIXME(ldez) must be fixed
92+
- nonamedreturns # FIXME(ldez) must be fixed
93+
- nakedret # FIXME(ldez) must be fixed
94+
95+
issues:
96+
exclude-use-default: false
97+
max-per-linter: 0
98+
max-same-issues: 0
99+
exclude:
100+
- 'ST1000: at least one file in a package should have a package comment'
101+
- 'package-comments: should have a package comment'
102+
exclude-rules:
103+
- path: .*_test.go
104+
linters:
105+
- funlen
106+
- goconst

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ RUN apk add --no-cache git make
88

99
# these are my standard testing / linting tools
1010
RUN /bin/true \
11-
&& go get -u github.com/golang/dep/cmd/dep \
12-
&& go get -u github.com/alecthomas/gometalinter \
13-
&& gometalinter --install \
1411
&& rm -rf /go/src /go/pkg
1512
#
1613
# * SCOWL word list

Makefile

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
CONTAINER=nickg/misspell
22

3+
default: lint test build
4+
35
install: ## install misspell into GOPATH/bin
46
go install ./cmd/misspell
57

6-
build: hooks ## build and lint misspell
7-
./scripts/build.sh
8+
build: ## build and lint misspell
9+
go build ./cmd/misspell
810

911
test: ## run all tests
10-
go test .
12+
go test -v .
13+
14+
lint: ## run linter
15+
golangci-lint run
1116

1217
# real publishing is done only by travis
1318
publish: ## test goreleaser
@@ -39,8 +44,8 @@ clean: ## clean up time
3944

4045
ci: ## run test like travis-ci does, requires docker
4146
docker run --rm \
42-
-v $(PWD):/go/src/github.com/client9/misspell \
43-
-w /go/src/github.com/client9/misspell \
47+
-v $(PWD):/go/src/github.com/golangci/misspell \
48+
-w /go/src/github.com/golangci/misspell \
4449
${CONTAINER} \
4550
make build falsepositives
4651

@@ -52,23 +57,17 @@ docker-pull: ## pull latest test image
5257

5358
docker-console: ## log into the test image
5459
docker run --rm -it \
55-
-v $(PWD):/go/src/github.com/client9/misspell \
56-
-w /go/src/github.com/client9/misspell \
60+
-v $(PWD):/go/src/github.com/golangci/misspell \
61+
-w /go/src/github.com/golangci/misspell \
5762
${CONTAINER} sh
5863

59-
.git/hooks/pre-commit: scripts/pre-commit.sh
60-
cp -f scripts/pre-commit.sh .git/hooks/pre-commit
61-
.git/hooks/commit-msg: scripts/commit-msg.sh
62-
cp -f scripts/commit-msg.sh .git/hooks/commit-msg
63-
hooks: .git/hooks/pre-commit .git/hooks/commit-msg ## install git precommit hooks
64-
6564
.PHONY: help ci console docker-build bench
6665

6766
# https://www.client9.com/self-documenting-makefiles/
6867
help:
6968
@awk -F ':|##' '/^[^\t].+?:.*?##/ {\
7069
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
7170
}' $(MAKEFILE_LIST)
72-
.DEFAULT_GOAL=help
71+
.DEFAULT_GOAL=default
7372
.PHONY=help
7473

ascii.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package misspell
22

3-
// ByteToUpper converts an ascii byte to upper cases
4-
// Uses a branchless algorithm
3+
// ByteToUpper converts an ascii byte to upper cases.
4+
// Uses a branch-less algorithm.
55
func ByteToUpper(x byte) byte {
66
b := byte(0x80) | x
77
c := b - byte(0x61)
@@ -10,24 +10,24 @@ func ByteToUpper(x byte) byte {
1010
return x - (e >> 2)
1111
}
1212

13-
// ByteToLower converts an ascii byte to lower case
14-
// uses a branchless algorithm
13+
// ByteToLower converts an ascii byte to lower case.
14+
// Uses a branch-less algorithm.
1515
func ByteToLower(eax byte) byte {
1616
ebx := eax&byte(0x7f) + byte(0x25)
1717
ebx = ebx&byte(0x7f) + byte(0x1a)
1818
ebx = ((ebx & ^eax) >> 2) & byte(0x20)
1919
return eax + ebx
2020
}
2121

22-
// ByteEqualFold does ascii compare, case insensitive
22+
// ByteEqualFold does ascii compare, case insensitive.
2323
func ByteEqualFold(a, b byte) bool {
2424
return a == b || ByteToLower(a) == ByteToLower(b)
2525
}
2626

2727
// StringEqualFold ASCII case-insensitive comparison
2828
// golang toUpper/toLower for both bytes and strings
2929
// appears to be Unicode based which is super slow
30-
// based from https://codereview.appspot.com/5180044/patch/14007/21002
30+
// based from https://codereview.appspot.com/5180044/patch/14007/21002.
3131
func StringEqualFold(s1, s2 string) bool {
3232
if len(s1) != len(s2) {
3333
return false
@@ -47,9 +47,7 @@ func StringEqualFold(s1, s2 string) bool {
4747
return true
4848
}
4949

50-
// StringHasPrefixFold is similar to strings.HasPrefix but comparison
51-
// is done ignoring ASCII case.
52-
// /
50+
// StringHasPrefixFold is similar to strings.HasPrefix but comparison is done ignoring ASCII case.
5351
func StringHasPrefixFold(s1, s2 string) bool {
5452
// prefix is bigger than input --> false
5553
if len(s1) < len(s2) {

0 commit comments

Comments
 (0)