Skip to content

Fix CodeClimate formater panic #1078

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

Closed
wants to merge 1 commit into from

Conversation

l0nax
Copy link

@l0nax l0nax commented May 8, 2020

In pkg/golinters/unused.go:NewUnused() set 'LineRange.To' equal to
LineRange.From when the the end position returned by u.ProblemObject(..)
is not valid.

When using 'code-climate' as formatter golangci-lint will panic with
"index out of range [0] with length 0".
This is caused because DisplayPosition(..) from honnef.co/go/tools
will return a zeroed token.Position struct if the given token
position does not contain any line information.

There should not be any side effects by setting 'LineRange.To' equal to
'From' since the 'unused' linter (mostly) only "targets" ONE line and
not many. But even if 'unused' targets multiple lines there should be no
issues because the returned "End" position will then be set to a correct
value.

Fixes #979

In pkg/golinters/unused.go:NewUnused() set 'LineRange.To' equal to
LineRange.From when the end position returned by u.ProblemObject(..)
is not valid.

When using 'code-climate' as formatter `golangci-lint` will panic with
"index out of range [0] with length 0".
This is caused because DisplayPosition(..)[1] from honnef.co/go/tools
will return a zeroed token.Position struct if the given token
position does not contain any line information.

There should not be any side effects by setting 'LineRange.To' equal to
'From' since the 'unused' linter (mostly) only "targets" ONE line and
not many. But even if 'unused' targets multiple lines there should be no
issues because the returned "End" position will then be set to a correct
value.

[1]: https://github.com/dominikh/go-tools/blob/v0.0.1-2020.1.3/unused/unused.go#L496

Fixes: golangci#979

Signed-off-by: Francesco Emanuel Bennici <[email protected]>
@CLAassistant
Copy link

CLAassistant commented May 8, 2020

CLA assistant check
All committers have signed the CLA.

@jirfag
Copy link
Contributor

jirfag commented May 9, 2020

thank you,
but unused tests fail. Also, it would be great to have a test case for this bug.

@ernado
Copy link
Member

ernado commented May 11, 2020

We can't use this fix as is, because it breaks current workaround for --fix mode for unused linter.
Please fix corresponding test.

@SVilgelm SVilgelm added the stale No recent correspondence or work activity label Jul 12, 2020
@stale stale bot closed this Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale No recent correspondence or work activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Climate index out of range with unused linter since > v1.21.0
5 participants