Skip to content

Commit

Permalink
chore: linting and cleanup (bxcodec#70)
Browse files Browse the repository at this point in the history
* chore: cleanup project

* chore: delete unused file

* chore: update README

* chore: fix typo

* chore: add github action

* chore: add github action

* chore: rename the file

* chore: try GH action

* chore: fix docker compose
  • Loading branch information
bxcodec authored Dec 9, 2022
1 parent 4cbd13b commit 7b8cd9b
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 155 deletions.
37 changes: 37 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root
root = "."
tmp_dir = "tmp_app"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp_app/app/engine ./app/."
# Binary file yields from `cmd`.
bin = "tmp_app/app"
# Customize binary.
full_bin = "./tmp_app/app/engine"
# This log file places in your tmp_dir.
log = "air_errors.log"
# Watch these filename extensions.
include_ext = ["go", "yaml", "toml"]
# Ignore these filename extensions or directories.
exclude_dir = ["tmp_app", "tmp"]
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms

[log]
# Show log time
time = true

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine
*.out
24 changes: 24 additions & 0 deletions .github/workflows/gotest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Go Test

on:
push:
branches: ["main", "chore/upgrade-linter"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Linter
run: make lint

- name: Test
run: make tests
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ _*
*.test
.DS_Store
engine
bin/
bin/
*.out
200 changes: 125 additions & 75 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,80 +1,130 @@
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 20
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 5
misspell:
locale: US
lll:
line-length: 160
# tab width in spaces. Default to 1.
tab-width: 1
funlen:
lines: 120
statements: 50
linters-settings:
dupl:
threshold: 300
funlen:
lines: 200
statements: 55
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- performance
- style
- opinionated
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- hugeParam
gocyclo:
min-complexity: 20
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- "0"
- "1"
- "2"
- "3"
ignored-functions:
- strings.SplitN
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 160
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- deadcode
- errcheck
- funlen
- goconst
# - gocritic
- gocyclo
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
disable-all: true
enable:
- asciicheck
- bodyclose
# - deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- ineffassign
- lll
- misspell
- nakedret
- noctx
# - nolintlint
- staticcheck
# - structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- revive
# - varcheck
- whitespace

run:
# default concurrency is a available CPU number
concurrency: 2

skip-dirs:
# - test/testdata_etc
skip-files:
# - .*_test.go
# don't enable:
#
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl

issues:
exclude-rules:
- path: internal/(cache|renameio)/
linters:
- lll
- gochecknoinits
- gocyclo
- funlen
- path: .*_test.go
linters:
- funlen
exclude-use-default: false
exclude:
- should have a package comment
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- dupl
- goconst

# - path: pkg/xerrors/xerrors.go
# text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
- path: app
text: "don't use `init` function"
run:
timeout: 5m
go: "1.17"
skip-dirs:
# - */mocks
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Builder
FROM golang:1.14.2-alpine3.11 as builder
FROM golang:1.19.4-alpine3.17 as builder

RUN apk update && apk upgrade && \
apk --update add git make
apk --update add git make bash build-base

WORKDIR /app

COPY . .

RUN make engine
RUN make build

# Distribution
FROM alpine:latest
Expand All @@ -21,6 +21,6 @@ WORKDIR /app

EXPOSE 9090

COPY --from=builder /app/engine /app
COPY --from=builder /app/engine /app/

CMD /app/engine
Loading

0 comments on commit 7b8cd9b

Please sign in to comment.