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 config for golangci #943

Merged
merged 4 commits into from Mar 8, 2019
Merged

Add config for golangci #943

merged 4 commits into from Mar 8, 2019

Conversation

mstoykov
Copy link
Collaborator

@mstoykov mstoykov commented Mar 8, 2019

currently most checks are enabled but we are only fixing error going
forward and all current problems will stay and will be fixed as we
refactor the code around them.

currently most checks are enabled but we are only fixing error going
forward and all current problems will stay and will be fixed as we
refactor the code around them.
@mstoykov mstoykov requested a review from na-- March 8, 2019 09:48
@codecov
Copy link

codecov bot commented Mar 8, 2019

Codecov Report

Merging #943 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #943   +/-   ##
=======================================
  Coverage   70.35%   70.35%           
=======================================
  Files         118      118           
  Lines        9111     9111           
=======================================
  Hits         6410     6410           
  Misses       2294     2294           
  Partials      407      407

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 917a796...7527200. Read the comment docs.

.golangci.yml Outdated Show resolved Hide resolved
.golangci.yml Show resolved Hide resolved
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how golangci will work when this is merged in master, but maybe we also need new: true here, so we're not buried by all of the old issues

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I understand new means only for what is currently not committed or if there is nothing the last commit. Which is not what we want - we want when this is a PR for it to look at what it will be merge and check against it which .. maybe golangci.com does ? maybe it just runs with --new by default ... Maybe they can write it somewhere on their page ... Given that this is how everybody uses it and at least in some of them they have issues in master but master is still green I would guess golangci does the right thing™
Looking at https://golangci.com/r/github.com/loadimpact/k6/pulls/943 they make a patch and then analyse that ... they also git clone with depth 1 so ... maybe they are doing what --new will do by default ... I will need to find a way to test this ... probably with a bogus PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we can just wait and see what happens when we merge this (or another) PR with master. Worst case, we have a "broken" commit, not the end of the world...

goling:
min-confidence: 0
gocyclo:
min-complexity: 25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

25 may be a bit low, considering that 30 is the default. I'm all for splitting apart huge methods, but I feel like this setting will be problematic if it complains when we want to make a change in one of the currently overly "complex" methods:

golangci-lint run --out-format=tab --disable-all --enable gocyclo --max-issues-per-linter 0 --max-same-issues 0 ./...                                                       :(
js/modules/k6/html/elements_test.go:87:1  gocyclo  cyclomatic complexity 112 of func `TestElements` is high (> 25)
js/modules/k6/html/html_test.go:65:1      gocyclo  cyclomatic complexity 97 of func `TestParseHTML` is high (> 25)
js/modules/k6/http/request.go:172:1       gocyclo  cyclomatic complexity 64 of func `(*HTTP).parseRequest` is high (> 25)
converter/har/converter.go:61:1           gocyclo  cyclomatic complexity 61 of func `Convert` is high (> 25)
js/modules/k6/html/element_test.go:56:1   gocyclo  cyclomatic complexity 50 of func `TestElement` is high (> 25)
js/modules/k6/http/request.go:402:1       gocyclo  cyclomatic complexity 50 of func `(*HTTP).request` is high (> 25)
js/modules/k6/ws/ws.go:82:1               gocyclo  cyclomatic complexity 44 of func `(*WS).Connect` is high (> 25)
core/local/local.go:152:1                 gocyclo  cyclomatic complexity 40 of func `(*Executor).Run` is high (> 25)
js/common/bridge_test.go:291:1            gocyclo  cyclomatic complexity 40 of func `TestBind` is high (> 25)
lib/options.go:302:1                      gocyclo  cyclomatic complexity 37 of func `(Options).Apply` is high (> 25)
js/common/bridge.go:116:1                 gocyclo  cyclomatic complexity 32 of func `Bind` is high (> 25)
js/bundle_test.go:48:1                    gocyclo  cyclomatic complexity 28 of func `TestNewBundle` is high (> 25)

I guess having at at 30 won't help all that much...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ... I dunno I suppose leaving it at 25 is fine for as I am not getting all the way up to 50+ ... //nolint will be the tool for the job it seems :(
I will probably need to merge this in #907 in order to //nolint some the method in js/modules/k6/http/request.go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm OK to leave it at 25... Rising it to 50 would be absurd, and even that won't be enough. And from what I remember, most of those errors above are actually problematic functions that we're slowly working on splitting up and refactoring... My only issue with needing to add //nolint:gocyclo to them for a small change will be that we might forget to eventually remove those //nolint statements... We'll see how it goes I guess, in any case, it will still be better than the current situation 😄

.golangci.yml Outdated
run:
deadline: 5m
skip-files:
- ".*gen_elements.*\\.go$"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. gen_elements.go is the hand-written file and elements_gen_test.go is also a hand-written test file. The only generated file is elements_gen.go 😄 And even then, I don't think we should exclude any of these files from the linter.

The only files we should exclude are the rice-box ones, since they're just static embedded content. The rest are actual Go code, and it doesn't matter if they're generated or not, they shouldn't have linter issues unless there's a very good reason. And for those with good reasons, //nolint should suffice

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding //nolint to a generated file will be hard ... especially if we are not the ones generating it which is not the case. On the other hand golangci-lint automatically removes all autogenerated files it detects ... which obviously doesn't work in this case :)

Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mstoykov mstoykov merged commit 6bb227c into master Mar 8, 2019
@mstoykov mstoykov deleted the addGolangCIConfig branch March 8, 2019 13:48
@na-- na-- mentioned this pull request Mar 8, 2019
@mstoykov mstoykov mentioned this pull request Mar 25, 2019
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

2 participants