Skip to content

Commit

Permalink
build(linters): list of linter todo's (hybridgroup#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas committed Jul 6, 2023
1 parent a2e06b8 commit 0648f66
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.52.2
version: v1.53.3

# Optional: working directory, useful for monorepos
# working-directory: v2
Expand Down
111 changes: 108 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,118 @@ run:
- platforms/opencv

linters:
# Enable specific linter
# currently active linters:
#
#INFO [lintersdb] Active 35 linters: [asasalint asciicheck bidichk contextcheck decorder depguard durationcheck errcheck exportloopref
# gocheckcompilerdirectives gomoddirectives gomodguard goprintffuncname gosimple govet grouper importas ineffassign mirror musttag
# nilerr nilnil nolintlint nosprintfhostport prealloc reassign revive staticcheck tagalign tenv testableexamples tparallel typecheck unused wastedassign]

enable-all: true

# https://golangci-lint.run/usage/linters/#enabled-by-default
# note: typecheck can not be disabled, it is used to check code compilation
enable:
- nolintlint
disable:
# deprecated
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
# not used for any reason
- execinquery # not needed (no sql)
- exhaustive # not used (we allow incomplete usage of enum switch, e.g. with default case)
- forbidigo # not used (we allow print statements)
- ginkgolinter # not needed (enforces standards of using ginkgo and gomega)
- gochecknoglobals # not used (we allow definition of unexposed variables at top level)
- godot # not used (seems to be counting peas)
- godox # not used (we have many TODOs, so not useful)
- goerr113 # not used (we allow error creation at return statement)
- gofumpt # not used (we use "go fmt" or "gofmt" not gofumpt"
- gosmopolitan # not needed (report i18n/l10n anti-patterns)
- ireturn # not used (we allow return interfaces)
- loggercheck # not needed (relates to kitlog, klog, logr, zap)
- paralleltest # not used
- promlinter # not needed (prometheus metrics naming)
- rowserrcheck # not needed (sql related)
- sqlclosecheck # not needed (sql related)
- testpackage # not needed, we use the same name for test package to have access to unexposed items
- wrapcheck # not needed (we allow errors from interface methods)
- zerologlint # not needed (related to zerolog package)
# important to have
- gofmt # important to prevent "format tsunami" ("gofmt -s -w" missed), disabled due to "https://github.com/golangci/golangci-lint-action/issues/535"
- makezero # very important (find/reduce bugs, e.g. in robot_work_test.go)
- nakedret # very useful together with "nonamedreturns" (reduce bugs)
- nonamedreturns # very useful (reduce bugs)
- unconvert # very useful (reduce bugs, simplify code)
- unparam # very useful (reduce bugs, simplify code)
# useful for the future
- bodyclose # maybe useful (reduce bugs), exclusions for tests needed
- containedctx # useful (structs are not for context wrapping)
- cyclop # useful with some tweeks (better understandable code), see also gocyclo
- dogsled # useful with some tweeks (e.g. exclude tests)
- dupl # useful with some tweeks (reduce bugs and lines of code)
- dupword # useful with some tweeks, but not important
- errchkjson # useful (reduce bugs)
- errname # useful for common style
- errorlint # useful (reduce bugs), but suppress the "Use `%w` to format errors" check
- exhaustruct # useful with some exclusions for existing code (e.g. mavlink/common/common.go)
- forcetypeassert # useful (reduce bugs)
- funlen # useful with some tweeks (reduce bugs, simplify code, better understandable code)
- gci # useful (improve readability)
- gochecknoinits # useful (reduce bugs, simplify bug catching)
- gocognit # useful with some tweeks (better understandable code)
- goconst # useful (reduce bugs)
- gocritic # useful with some exclusions for existing code (e.g. mavlink/common/common.go)
- gocyclo # useful with some tweeks (better understandable code)
- goheader # useful, if we introduce a common header (e.g. for copyright)
- goimports # useful (common style), but not important
- gomnd # useful with some exclusions for existing code (e.g. mavlink.go)
- gosec # useful (security)
- interfacebloat # useful with some exclusions at usage of external packages
- lll # useful with some exclusions for existing code (e.g. mavlink/common/common.go)
- maintidx # useful with some tweeks (better understandable code), maybe use instead "gocyclo", "gocognit" , "cyclop"
- misspell # useful (better understandable code), but not important
- nestif # useful (reduce bugs, simplify code, better understandable code)
- nlreturn # more common style, but could become annoying
- noctx # maybe good (show used context explicit)
- predeclared # useful (reduce bugs)
- stylecheck # useful with some tweaking (e.g. underscores in names should be allowed - we use it for constants retrieved from C/C++)
- tagliatelle # maybe useful with some tweaking or excluding
- thelper # useful
- usestdlibvars # useful
- varnamelen # maybe useful with some tweaking, but many findings
- whitespace # more common style, but could become annoying
- wsl # more common style, but could become annoying

linters-settings:
depguard:
# Rules to apply.
#
# Variables:
# - File Variables
# you can still use and exclamation mark ! in front of a variable to say not to use it.
# Example !$test will match any file that is not a go test file.
#
# `$all` - matches all go files
# `$test` - matches all go test files
#
# - Package Variables
#
# `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
#
# Default: Only allow $gostd in all files.
rules:
main:
# Packages that are not allowed where the value is a suggestion.
deny:
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package

nolintlint:
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ version_check:

# Check for bad code style and other issues
fmt_check:
gofmt -l ./
gofmt -l -s .
golangci-lint run -v

# Fix bad code style (will only be executed, on version match)
fmt_fix: version_check
go fmt ./...
gofmt -l -s -w .

examples: $(EXAMPLES)

Expand Down
2 changes: 2 additions & 0 deletions platforms/joystick/bin/scanner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//go:build utils
// +build utils

//
// Do not build by default.
//
Expand Down
36 changes: 18 additions & 18 deletions platforms/joystick/joystick_dualshock3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,81 @@ var dualshock3Config = joystickConfig{
Name: "Dualshock3 Controller",
GUID: "1111",
Axis: []pair{
pair{
{
Name: "left_x",
ID: 0,
},
pair{
{
Name: "left_y",
ID: 1,
},
pair{
{
Name: "right_x",
ID: 3,
},
pair{
{
Name: "right_y",
ID: 4,
},
},
Buttons: []pair{
pair{
{
Name: "square",
ID: 3,
},
pair{
{
Name: "triangle",
ID: 2,
},
pair{
{
Name: "circle",
ID: 1,
},
pair{
{
Name: "x",
ID: 0,
},
pair{
{
Name: "up",
ID: 13,
},
pair{
{
Name: "down",
ID: 14,
},
pair{
{
Name: "left",
ID: 15,
},
pair{
{
Name: "right",
ID: 16,
},
pair{
{
Name: "l1",
ID: 4,
},
{
Name: "l2",
ID: 6,
},
pair{
{
Name: "r1",
ID: 5,
},
pair{
{
Name: "r2",
ID: 7,
},
pair{
{
Name: "start",
ID: 9,
},
pair{
{
Name: "select",
ID: 8,
},
pair{
{
Name: "home",
ID: 10,
},
Expand Down
44 changes: 22 additions & 22 deletions platforms/joystick/joystick_dualshock4.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,99 +4,99 @@ var dualshock4Config = joystickConfig{
Name: "Dualshock4 Controller",
GUID: "2222",
Axis: []pair{
pair{
{
Name: "left_x",
ID: 0,
},
pair{
{
Name: "left_y",
ID: 1,
},
pair{
{
Name: "right_x",
ID: 3,
},
pair{
{
Name: "right_y",
ID: 4,
},
pair{
{
Name: "l2",
ID: 2,
},
pair{
{
Name: "r2",
ID: 5,
},
},
Buttons: []pair{
pair{
{
Name: "square",
ID: 3,
},
pair{
{
Name: "triangle",
ID: 2,
},
pair{
{
Name: "circle",
ID: 1,
},
pair{
{
Name: "x",
ID: 0,
},
pair{
{
Name: "l1",
ID: 4,
},
pair{
{
Name: "l2",
ID: 6,
},
pair{
{
Name: "r1",
ID: 5,
},
pair{
{
Name: "r2",
ID: 7,
},
pair{
{
Name: "share",
ID: 8,
},
pair{
{
Name: "options",
ID: 9,
},
pair{
{
Name: "home",
ID: 10,
},
},
Hats: []hat{
hat{
{
Hat: 0,
Name: "down",
ID: 4,
},
hat{
{
Hat: 0,
Name: "up",
ID: 1,
},
hat{
{
Hat: 0,
Name: "left",
ID: 8,
},
hat{
{
Hat: 0,
Name: "right",
ID: 2,
},
hat{
{
Hat: 0,
Name: "released",
ID: 0,
Expand Down
Loading

0 comments on commit 0648f66

Please sign in to comment.