-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
var-naming doesn't run on exported test functions #1124
Comments
@ivanvc its not a bug its a feature as some one said :P if you check source of var-naming rule you should notice:
that code check if func name is declared in file with _test.go suffix and has prefix from (Example, Test, Benchmark, Fuzz) then it should be skipped I made file var_naming_test.go with content:
and lint results were like this:
but when rename test file to var_naming.go then results looks like that:
so i think it work as expected (func name with prefix Test have special rights in *_test.go files, and they are excluded from lint results) i hope my answer helps you :) |
Hi @mfederowicz, thanks for your answer. The problem with skipping test case names is that we can end up with functions with I think the idea of a linter is to avoid unnecessary discussion on style if a project adheres to it. For example, refer to the comment that initiated this issue: etcd-io/etcd#18816 (comment). Thanks again. |
Hi @ivanvc thank you for reporting the issue. |
Thanks for explaining the reason behind it, @chavacava. I think the minimum would be to document this behavior so users don't need to dive deep into the source code to understand that it doesn't run on the test file's Test/Benchmark/Fuzz functions. Cheers, and thanks for the work on the review linter :) |
PR are welcome @ivanvc |
Thanks for the discussion. I think I also face the issues a few times. I have never reached the point to report it. I'm glad to read the context and the discussion led to document it. But then, here I am, suggesting something Maybe this "legacy golint" behavior could be disabled via a configuration parameter for this rule |
hmm @chavacava maybe it is not a bad idea to add aditional config flag for example
should not bother them :P but of course give me info what you think about it? |
If a flag is added, it must be backward compatible i.e. its default value shall make the rule behave as it currently behaves (skip tests) thus |
so
thats correct @chavacava? If its ok when back from work, I prepare PR for that :) |
Hi, thanks for the great work on revive. I checked the documentation and issues from
var-naming
, but couldn't find anything that explained this behavior. I'm unsure if it is intentional not to check exported test functions.Describe the bug
The var-naming run doesn't run on exported test functions. i,e,.
func TestValidIpAddress(t *testing.T)
. However, when unexporting the function it runs as expected.To Reproduce
Steps to reproduce the behavior:
var_naming_test.go
revive
(with the default settings), i.e.revive ./... && echo $?
Expected behavior
It should have failed because of the wrong casing in the function name. i.e.,
For example, when unexporting the test function (
testValidIp
) the linter fails as expected.Logs
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
We first identified this issue in our CI environment (as part of
golangci-lint
) and I was able to reproduce it locally. Ref: etcd-io/etcd#18816 (comment)The text was updated successfully, but these errors were encountered: