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
Add linter configuration #7247
Add linter configuration #7247
Conversation
Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
Sorry about the excessive review pings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for working on this, please see questions inline
.golangci.yml
Outdated
enable: | ||
# Defaults | ||
- deadcode | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- staticcheck | ||
- structcheck | ||
- typecheck | ||
- varcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you pick this specific list of flags? (To clarify, I'm not sure what the list should be)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran golangci-lint linters
in a directory without a .golangci.yml
present
~ golangci-lint linters
Enabled by your configuration linters:
deadcode: Finds unused code [fast: true, auto-fix: false]
errcheck: Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: true, auto-fix: false]
gosimple (megacheck): Linter for Go source code that specializes in simplifying a code [fast: true, auto-fix: false]
govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: true, auto-fix: false]
ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
staticcheck (megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: true, auto-fix: false]
structcheck: Finds unused struct fields [fast: true, auto-fix: false]
typecheck: Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false]
unused (megacheck): Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
varcheck: Finds unused global variables and constants [fast: true, auto-fix: false]
I removed errcheck
from the list as the previous CLI invocations had it disabled
.golangci.yml
Outdated
run: | ||
timeout: 10m | ||
|
||
linters-settings: | ||
goimports: | ||
local-prefixes: vitess.io/vitess | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
# Defaults | ||
- deadcode | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- staticcheck | ||
- structcheck | ||
- typecheck | ||
- varcheck | ||
|
||
# Extras | ||
- gofmt | ||
- goimports | ||
|
||
# https://github.com/golangci/golangci/wiki/Configuration | ||
service: | ||
golangci-lint-version: 1.34.x # use the fixed version to not introduce new linters unexpectedly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for fixed version
misc/git/hooks/golangci-lint
Outdated
fi | ||
|
||
#golangci-lint run --disable=ineffassign,unused,gosimple,staticcheck,errcheck,structcheck,varcheck,deadcode | ||
for gopackage in $gopackages | ||
do | ||
echo "Linting $gopackage" | ||
golangci-lint run --disable=errcheck --timeout=10m $gopackage | ||
golangci-lint run $gopackage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since errcheck
is removed, should we expect new linter errors on existing code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errcheck
is implicitly removed by the combination of disable-all: true
and errcheck
not being in the enable list in the config file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I wanted to ask: for the commit hook specifically, can we add the --fast
flag?
Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config looks good to me. looks like vtctl.go isn't goimports'ed yet
I don't know why it is failing in the CI, running the linter locally it passes. It also passed on a previous commit with no changes to the file since :/ |
Also passes for me, but I notice:
so I'm using |
I have the same version (1.34.1) locally:
|
and, on the server side? |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Have resolved merge conflicts and am further removing linter errors |
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Pinned |
Linter tests now passing |
Description
Adding a linter configuration file for deterministic linting