-
Notifications
You must be signed in to change notification settings - Fork 424
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
Buildifier: Variables prefixed with _
should be ignored by unused-variable
checks
#1044
Comments
Would it help if buildifier ignores such variables only if they are defined together with another variable? Because if you write
(and don't use both) I think it's still valid to warn about unused variables, WDYT? |
In the case of _compilation_ctx, cc_compilation_outputs = cc_common.compile(...) I don't think it's valid to warn on |
Sorry, I meant both variables with underscores:
or just
(all variables in the examples are unused). The formal criteria would be "don't warn if an unused variable starts with an underscore and is defined in the same statement with another used variable". I agree with your usecase but don't think that suppressing the warning for all variables starting with |
That would work for me. One other case I've found is in function arguments def _wasm_bindgen_transition(_settings, _attr):
return {"//command_line_option:platforms": str(Label("//rust/platform:wasm"))}
wasm_bindgen_transition = transition(
implementation = _wasm_bindgen_transition,
inputs = [],
outputs = ["//command_line_option:platforms"],
) I would expect this to not yield any warnings since I don't have control over the API of the function here. If both the examples were to be addressed then I'd feel comfortable enabling the new warning (and I'd really like to since I think it's a very good thing to have). edit: |
@UebelAndre feel free to review #1047, it should cover all of the cases described above.
in fact it's not new, it was just not implemented properly and because of that didn't catch most of the cases, not it should be more reliable and useful. |
This looks perfect! Thank you so much for the quick change!
Yeah, sorry about that, I realized that some time later yesterday but forgot to update the ticket. It felt new because we just started seeing the defects. |
@vladmos What do you expect the turn-around time to be for getting the changes merged and cutting a new release? |
I'll release 5.0.1 with the fix tomorrow.
No worries, I just wanted to explain why an existing warning suddenly started yielding a lot of (hopefully not false positive) warnings. Because of primitive implementation it was only detecting unused constants in BUILD files and disabled completely for .bzl files because some variables defined there can be imported from other files. Now it's supposed to handle such cases correctly and e.g. warn about unused local variables inside functions. |
Once again, thank you so much! |
You're welcome, please let me know if you see any other examples of warnings that are rather noisy than useful (especially if that's a false positive finding), I refactored a dozen of different warning categories so it's expected that some new warnings appear. |
I and seemingly other contributors to
rules_rust
(and surely other rules) have had the expectation that variables prefixed with_
were unused. Needing to additionally annotate variables with a comment feels unnecessary and can increase the burden of reviewers where a user may call some native or external macro which returns multiple values but without a_
prefix it's unclear which is actually unused.vs
The latter makes it clear that a specific result of this external function is not used and allows the warning to catch cases where the second variable becomes unused, this informing users the entire snippet can be removed.
The text was updated successfully, but these errors were encountered: