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

Fix gocov formatting issue #479 #480

Merged
merged 1 commit into from
Dec 6, 2021

Conversation

georgethebeatle
Copy link
Contributor

This PR fixes issue #479

The formatter used to assume that the number of statements always equals
the number of lines in a block. This is not true when there are blank
lines for example. This change colours by line number rather than by
statement.

Fixes issue codeclimate#479

The formatter used to assume that the number of statements always equals
the number of lines in a block. This is not true when there are blank
lines for example. This change colours by line number rather than by
statement.

Co-authored-by: Georgi Sabev <georgethebeatle@gmail.com>
Co-authored-by: Danail Branekov <danailster@gmail.com>
@CLAassistant
Copy link

CLAassistant commented Dec 3, 2021

CLA assistant check
All committers have signed the CLA.

@@ -70,14 +69,15 @@ func (r Formatter) Format() (formatters.Report, error) {
}
blocks[lstIdx].Count += b.Count
}
lineNum := 1
Copy link
Contributor

Choose a reason for hiding this comment

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

can't start lines be 0 ? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They used to, but we changed them to be 1-based for better readability (lines in an editor start from 1 usually). This way for lineNum < b.StartLine reads like "do this and that for all lines before start of block". If lines are zero-based the statement becomes for lineNum < b.StartLine - 1 which at least for me is harder to read. But I can change it to start from zero if you prefer it that way :).

Copy link
Contributor

@fede-moya fede-moya Dec 6, 2021

Choose a reason for hiding this comment

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

oh, I see. Thanks for the explanation. However, there might be folks out there using the test-reportoer downloading it's latest version. If they haven't upgraded the gocov version they are using, things will start to behave differently for them once we merge this. Could we make it to be for lineNum < b.StartLine - 1 for this reason ? I mean, for backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is actually backwards compatible this way. Iterating from 0 to startLine - 1 is effectively the same as iterating from 1 to startLine. The index itself is not used anywhere, but is just a counter, so it cannot affect anything user facing.

Copy link
Contributor

Choose a reason for hiding this comment

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

facepalm-really

Copy link
Contributor

@fede-moya fede-moya left a comment

Choose a reason for hiding this comment

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

@georgethebeatle thanks for the contribution, this is a nice catch 👏🏼 . Sorry took us some time to review, we have been busy these days.

Only left a minor comment.

Copy link
Contributor

@fede-moya fede-moya left a comment

Choose a reason for hiding this comment

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

Great work - thank you!

@fede-moya fede-moya merged commit 3da41fd into codeclimate:master Dec 6, 2021
@fede-moya
Copy link
Contributor

@georgethebeatle this has been release already, it would be great if you could confirm that it has addressed the issue that you reported successfully 👍🏼

@georgethebeatle
Copy link
Contributor Author

Thanks for the quick reaction @fede-moya. The release behaves as expected and we are already using it!

@georgethebeatle georgethebeatle deleted the pr-fix-gocov-formatting branch December 8, 2021 22:03
@fede-moya
Copy link
Contributor

fede-moya commented Dec 8, 2021

@georgethebeatle ooh great - Thanks for sharing that 🙌🏼 . Regards!

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.

3 participants