-
Notifications
You must be signed in to change notification settings - Fork 172
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
Prism wrongly complaining about an unused variable #3006
Comments
I hope this is the right place to ask. If not, please suggest me where / whom to write. |
Thank you for the report. A few points about what you brought up:
# This example is impossible to analyze statically and will always raise false positives
# because the parser has no way to know which runtime values are going to be available here
key = get_desired_key_from_database
local_variable_that_is_equal_to_one_two_three = { foo_bar: ... }.find do |k, v|
binding.local_variable_get(key) == 123
end
|
I've now updated my server version (gem) to 0.22.1 (sorry, I thought it were the latest version given that a previous bundle update didn't actually update it, but now it could update to latest, probably because I removed solargraph in between), but the issue persists.
Unfortunately, the only suggestions (quick fixes) are either 'Fix using Copilot' (leads to removing the assignment, which of course will cause an error), or 'Explain with Copilot (leads to the suggestions described in my first comment, also not helping). The warning is not suppressed and since I use Windows Terminal to execute, it seems that the warning is editor exclusive. |
This warning is not editor-only. These warnings mirror exactly the ones output by Ruby itself. For example: foo = 1
binding.local_variable_get(:foo) This script will warn:
Note that Ruby has two levels of warnings. The first are always output, the second are output with As you indicated, you can eliminate the warning using an _foo = 1
binding.local_variable_get(:_foo) would work. @vinistock I think it could potentially make sense in this rare case to support some kind of warning disabling feature, but it would be pretty niche to maintain, especially when there are workarounds. But if you wanted, something like |
Yes, I agree that it would be niche to maintain our own syntax for disabling warnings, especially stuff coming from the parser and not a linter. We could also allow users to configure the verbosity level, but I'm not sure how much value that brings. People would need to remember to match the verbosity level between their apps and the LSP, which feels prone to an inconsistent experience. If Ruby had some sort of configuration file, like a Regarding the quickfixes, Copilot adds those to all diagnostics, it's not the Ruby LSP adding those. |
Description
Ruby LSP Information
VS Code Version
1.96.2
Ruby LSP Extension Version
0.8.16
Ruby LSP Server Version
0.17.2
Ruby LSP Addons
Ruby Version
3.2.2
Ruby Version Manager
rvm
Installed Extensions
Click to expand
Ruby LSP Settings
Click to expand
Workspace
User
Reproduction steps
In a Ruby file containing an assigned and apparently unused variable, e.g.
foo = ...
I'm using this variable as a string param to
binding.local_variable_get
later on in the code (from a hash key), like:Prism will mark the assignment line wrongly as a warning ('assigned but unused variable - foo'). Copilot suggests me to either suppress this warning with rubocop (but rubocop has nothing to do with it - it will actually complain about Lint/RedundantCopDisableDirective: Unnecessary disabling of
Lint/UselessAssignment
) or use an underscore before the variable like_foo
(but this will break the code later on when I'll be usingk
- sure, I could implement a workaround, but it will be painful to implement this in other code parts as well, and I'm pretty much sure it is already reproduced more than once).Is there a way to disable Prism on the assignment line manually?
Code snippet or error message
The text was updated successfully, but these errors were encountered: