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

cover: use Z instead of underscore for variable name separator #2995

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

sluongng
Copy link
Contributor

During the invocation of bazel coverage, rules_go will rewrite the
source fils using go tool cover -var ... so that the variable can be
extracted for coverage statistic after test execution. For more
information on this, review the relevant Official Go Team's blog post (1)

The variable used by rules_go is following the Cover_snake_case naming
convention, which is natural to starlark and python, but not Golang.
For this reason, some static analysis could get triggered by the usage
of snake case naming variable while running over coverage source code.

The correct solution for this problem should be to make rules_go's
static analysis framework nogo to NOT run on the generated source code
and instead only run on the original source code. However, replacing
underscore separators with character Z is a relatively cheap fix that
would let us unblock static analysis run during bazel coverage for
now. See discussion in (2) for more details.

(1): https://go.dev/blog/cover

(2): #2984

What type of PR is this?

Uncomment one line below and remove others.

Bug fix

Feature
Documentation
Other

What does this PR do? Why is it needed?

Which issues(s) does this PR fix?

Fixes #2982

Replaces #2984

During the invocation of `bazel coverage`, rules_go will rewrite the
source fils using `go tool cover -var ...` so that the variable can be
extracted for coverage statistic after test execution. For more
information on this, review the relevant Official Go Team's blog post (1)

The variable used by rules_go is following the `Cover_snake_case` naming
convention, which is natural to starlark and python, but not Golang.
For this reason, some static analysis could get triggered by the usage
of snake case naming variable while running over coverage source code.

The correct solution for this problem should be to make rules_go's
static analysis framework `nogo` to NOT run on the generated source code
and instead only run on the original source code.  However, replacing
underscore separators with character `Z` is a relatively cheap fix that
would let us unblock static analysis run during `bazel coverage` for
now.  See discussion in (2) for more details.

(1): https://go.dev/blog/cover

(2): bazelbuild#2984
@sluongng
Copy link
Contributor Author

created #2996 to propose a longer term fix.

I would still suggest to merge this first as 2996 can take some iterations to get right

@robfig robfig merged commit bd7fbcc into bazelbuild:master Nov 1, 2021
@robfig
Copy link
Contributor

robfig commented Nov 1, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Staticcheck failed during coverage run
2 participants