Skip to content

Commit

Permalink
Merge pull request #25 from covalenthq/feature/linter-improvements
Browse files Browse the repository at this point in the history
Applies ~60 golang linters to the entire codebase
  • Loading branch information
noslav authored Jan 22, 2022
2 parents e10ae82 + 84d70b3 commit 770b07f
Show file tree
Hide file tree
Showing 19 changed files with 903 additions and 478 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ permissions:
# pull-requests: read
jobs:
golangci:
name: lint
name: go-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
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.29
version: v1.43

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/hadolint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ on:

jobs:
linter:
name: lint-dockerfile
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2

- name: lint dockerfile
uses: brpaz/hadolint-action@master
with:
Expand Down
101 changes: 88 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,94 @@ run:

linters:
enable:
- staticcheck
disable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- structcheck
- typecheck
- unused
- varcheck

#-------------main-list--------------#
- deadcode # Finds unused code
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- gosimple # Linter for Go source code that specializes in simplifying a code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # Detects when assignments to existing variables are not used
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- structcheck # Finds unused struct fields
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unused # Checks Go code for unused constants, variables, functions and types
- varcheck # Finds unused global variables and constants
- stylecheck # Stylecheck is a replacement for golint
- gocritic # Provides diagnostics that check for bugs, performance and style issues. Extensible without recompilation through dynamic rules. Dynamic rules are written declaratively with AST patterns, filters, report message and optional suggestion.
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gosec # Inspects source code for security problems
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint
#------------extra-list-------------#
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk # Checks for dangerous unicode character sequences
- bodyclose # Checks whether HTTP response body is closed successfully
- depguard # Go linter that checks if package imports are in a list of acceptable packages
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dupl # Tool for code clone detection
- exhaustive # Check exhaustiveness of enum switch statements
- errorlint # Can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- exportloopref # Checks for pointers to enclosing loop variables
- goconst # Finds repeated strings that could be replaced by a constant
- gocyclo # Computes and checks the cyclomatic complexity of functions
- godox # Tool for detection of FIXME, TODO and other comment keywords
- goheader # Checks is file header matches to pattern
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
- goprintffuncname # Checks that printf-like functions are named with f at the end
- importas # Enforces consistent import aliases
- misspell # Finds commonly misspelled English words in comments
- nlreturn # Checks for a new line before return and branch statements to increase code clarity
- nilerr # Finds the code that returns nil even if it checks that the error is not nil
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
- nakedret # Finds naked returns in functions greater than a specified function length
- noctx # Noctx finds sending http request without context Context
- nolintlint # Reports ill-formed or insufficient nolint directives
- rowserrcheck # Checks whether Err of rows is checked successfully
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
- testpackage # Linter that makes you use a separate _test package
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- varnamelen # checks that the length of a variable's name matches its scope
- whitespace # Tool for detection of leading and trailing whitespace
- wrapcheck # Checks that errors returned from external packages are wrapped

disable:
# main-list
- contextcheck # Check the function whether use a non-inherited context
- cyclop # Checks function and package cyclomatic complexity
- durationcheck # Check for two durations multiplied together
- exhaustivestruct # Checks if all struct's fields are initialized
- forbidigo # Forbids identifiers
- forcetypeassert # finds forced type assertions
- funlen # Tool for detection of long functions\
- gci # Gci control golang package import order and make it always deterministic.
- gochecknoglobals # check that no global variables exist
- gochecknoinits # Checks that no init functions are present in Go code
- gocognit # Computes and checks the cognitive complexity of functions
- godot # Check if comments end in a period
- goerr113 # Golang linter to check the errors handling expressions
- gofumpt # Gofumpt checks whether code was gofumpt-ed
- gomnd # An analyzer to detect magic numbers
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
- ireturn # Accept Interfaces, Return Concrete Types
- lll # Reports long lines
- maintidx # Measures the maintainability index of each function
- makezero # Finds slice declarations with non-zero initial length
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
- prealloc # Finds slice declarations that could potentially be preallocated
- predeclared # Find code that shadows one of Go's predeclared identifiers
- promlinter # Check Prometheus metrics naming via promlint
- tagliatelle # Checks the struct tags.
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- testpackage # linter that makes you use a separate _test package
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
- wastedassign # wastedassign finds wasted assignment statements
- wsl # Whitespace Linter - Forces you to use empty lines!

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
max-same-issues: 0
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ run-agent-eth:
@echo "---- Running Agent from cmd/mqstoreagent ----"
@go run ./cmd/mqstoreagent/*.go \
--redis-url="redis://username:@localhost:6379/0?topic=replication#replicate" \
--codec-path="./codec/block-replica.avsc" \
--codec-path="./codec/block-ethereum.avsc" \
--binary-file-path="./bin/block-ethereum/" \
--gcp-svc-account="/Users/pranay/.config/gcloud/bsp-2.json" \
--replica-bucket="covalenthq-geth-block-specimen" \
Expand Down
Loading

0 comments on commit 770b07f

Please sign in to comment.