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

Add linter configuration #7247

Merged
merged 12 commits into from Jan 7, 2021
Merged

Add linter configuration #7247

merged 12 commits into from Jan 7, 2021

Conversation

epk
Copy link
Contributor

@epk epk commented Jan 4, 2021

Description

Adding a linter configuration file for deterministic linting

Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
Signed-off-by: Aditya Sharma <git@adi.run>
@epk epk marked this pull request as ready for review January 5, 2021 00:22
@epk
Copy link
Contributor Author

epk commented Jan 5, 2021

Sorry about the excessive review pings

Copy link
Contributor

@shlomi-noach shlomi-noach left a 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
Comment on lines 10 to 19
enable:
# Defaults
- deadcode
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- varcheck
Copy link
Contributor

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)

Copy link
Contributor Author

@epk epk Jan 5, 2021

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
Comment on lines 1 to 27
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
Copy link
Contributor

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 Show resolved Hide resolved
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
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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>
Copy link
Contributor

@ajm188 ajm188 left a 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

@epk
Copy link
Contributor Author

epk commented Jan 6, 2021

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 :/

@shlomi-noach
Copy link
Contributor

I don't know why it is failing in the CI, running the linter locally it passes.

Also passes for me, but I notice:

$ $(go env GOPATH)/bin/golangci-lint --version
golangci-lint has version 1.31.0 built from 3d6d0e7 on 2020-09-07T15:14:41Z

so I'm using 1.31.0, and CI presumably uses 1.34? @epk Can you verify what your own local golangci-lint version is?

@epk
Copy link
Contributor Author

epk commented Jan 6, 2021

I don't know why it is failing in the CI, running the linter locally it passes.

Also passes for me, but I notice:

$ $(go env GOPATH)/bin/golangci-lint --version
golangci-lint has version 1.31.0 built from 3d6d0e7 on 2020-09-07T15:14:41Z

so I'm using 1.31.0, and CI presumably uses 1.34? @epk Can you verify what your own local golangci-lint version is?

I have the same version (1.34.1) locally:

~/src/vitess.io/vitess   epk/golangci-lint  $(go env GOPATH)/bin/golangci-lint --version
golangci-lint has version 1.34.1 built from d7dd233 on 2020-12-29T06:20:54Z
~/src/vitess.io/vitess   epk/golangci-lint  $(go env GOPATH)/bin/golangci-lint run go/...
~/src/vitess.io/vitess   epk/golangci-lint  echo $?
0

@shlomi-noach
Copy link
Contributor

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>
@shlomi-noach
Copy link
Contributor

shlomi-noach commented Jan 7, 2021

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>
@shlomi-noach
Copy link
Contributor

Pinned golang-lint version to 1.31.0

@shlomi-noach
Copy link
Contributor

Linter tests now passing

@shlomi-noach shlomi-noach merged commit 3e8a926 into vitessio:master Jan 7, 2021
@askdba askdba added this to the v9.0 milestone Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants