Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added golangci-lint and multiple fixes for all kind of checks #84

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ jobs:
swagger-editor-url: http://localhost/
definition-file: docs/openapi.yaml

GolangCI:
runs-on: ubuntu-latest
name: Code Lint
permissions:
# Required: allow read access to the content for analysis.
contents: read
# Optional: allow write access to checks to allow the action to annotate code in the PR.
checks: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable # Linter will use go.mod file to adjust the rules properly

- name: Generate code
run: ONLYGEN=1 ./build.sh

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60

Build:
runs-on: ubuntu-latest
steps:
Expand Down
158 changes: 158 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
run:
concurrency: 4
timeout: 10m
tests: false
allow-parallel-runners: true
allow-serial-runners: true

output:
show-stats: true

issues:
max-issues-per-linter: 0 # unlimited

linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
#- cyclop
- decorder
#- depguard
- dogsled
#- dupl
- dupword
- durationcheck
#- err113
#- errcheck # Maybe in the future?
- errchkjson
- errname
#- errorlint
- exhaustive
#- exhaustruct
- fatcontext
#- forbidigo
- forcetypeassert
#- funlen
#- gci
- ginkgolinter
- gocheckcompilerdirectives
#- gochecknoglobals
#- gochecknoinits
- gochecksumtype
#- gocognit
#- goconst
#- gocritic
#- gocyclo
#- godot
#- godox
- gofmt
#- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- intrange
#- ireturn
#- lll
- loggercheck
#- maintidx
- makezero
- mirror
- misspell
#- mnd
- musttag
#- nakedret
#- nestif
- nilerr
#- nilnil
#- nlreturn
- noctx
- nolintlint
#- nonamedreturns
- nosprintfhostport
- paralleltest
#- perfsprint
#- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
#- stylecheck
- tagalign
#- tagliatelle
- tenv
- testableexamples
- testifylint
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
#- varnamelen
- wastedassign
- whitespace
#- wrapcheck
#- wsl
- zerologlint

linters-settings:
gosec:
excludes:
- G115 # integer overflow conversion - disabled due to found no proper way to fix those
revive:
enable-all-rules: true
rules:
- name: comment-spacings
disabled: true
- name: line-length-limit
disabled: true
- name: add-constant
disabled: true
- name: unhandled-error
disabled: true
- name: cognitive-complexity
disabled: true
- name: bare-return
disabled: true
- name: modifies-value-receiver
disabled: true
- name: cyclomatic
disabled: true
- name: confusing-results
disabled: true
- name: function-length
disabled: true
- name: flag-parameter
disabled: true
- name: max-control-nesting
disabled: true
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,41 @@ Is relatively easy - you change logic, you run `./build.sh` to create a binary,
the PR when you think it's perfect enough. That will be great if you can ask in the discussions or
create an issue on GitHub to align with the current direction and the plans.

### Linting

Fish uses golangci-lint to execute a huge number of static checks and you can run it locally like:
```sh
$ golangci-lint run -v
```

It uses the configuration from .golangci.yml file.

### Integration tests

To verify that everything works as expected you can run integration tests like that:
```sh
$ FISH_PATH=$PWD/aquarium-fish.darwin_amd64 go test -v -failfast -parallel 4 ./tests/...
```

### Benchmarks

Fish contains a few benchmarks to make sure the performance of the node & cluster will be stable.
You can run them locally like that:
```sh
$ go test -bench . -benchmem '-run=^#' -cpu 1,2 ./...
goos: darwin
goarch: amd64
pkg: github.com/adobe/aquarium-fish/lib/crypt
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_hash_new 20 65924472 ns/op 67122440 B/op 180 allocs/op
Benchmark_hash_new-2 33 34709165 ns/op 67122834 B/op 181 allocs/op
Benchmark_hash_isequal 33 64242662 ns/op 67122424 B/op 179 allocs/op
Benchmark_hash_isequal-2 32 34741325 ns/op 67122526 B/op 179 allocs/op$
```

CI stores the previous results in branch gh-pages in json format. Unfortunately GitHub actions
workers perfromance is not stable, so it's recommended to execute the benchmarks on standaline.

### Profiling

Is available through pprof like that:
Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ PATH="$gopath/bin:$PATH" go generate -v ./lib/...
sed -i.bak 's/^type LabelDefinitions = /type LabelDefinitions /' lib/openapi/types/types.gen.go
rm -f lib/openapi/types/types.gen.go.bak

# If ONLYGEN is specified - skip the build
[ -z "$ONLYGEN" ] || exit 0

# Prepare version number as overrides during link
mod_name=$(grep '^module' "${root_dir}/go.mod" | cut -d' ' -f 2)
git_version="$(git describe --tags --match 'v*')$([ "$(git diff)" = '' ] || echo '-dirty')"
Expand Down
4 changes: 2 additions & 2 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ done
echo
echo '---------------------- GoFmt verify ----------------------'
echo
reformat=$(gofmt -l . 2>&1)
reformat=$(gofmt -l -s . 2>&1)
if [ "${reformat}" ]; then
echo "Please run 'gofmt -w .': \n${reformat}"
echo "Please run 'gofmt -s -w .': \n${reformat}"
errors=$((${errors}+$(echo "${reformat}" | wc -l)))
fi

Expand Down
Loading