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
[apex] UnusedLocalVariable flags for variables which are using in SOQL/SOSL binds #4556
Comments
Thanks for reporting. The rule should support binding variables already. The implementation of the rule expects, that between the colon ( String unusedFlag = 'this string';
String query = 'SELECT Id FROM Account WHERE Name =: unusedFlag';
// ^
// | is this space allowed? |
Oh, and one more thing: You don't use the string yet in a query, so PMD can't know, that this string is supposed to be a SOQL/SOSL query... See also #2669 |
@adangel Thanks for the comments, Sorry I must have missed it in my example. Regardless of |
If we update the BINDING_VARIABLE regex to I have yet to test it, but i have opened a draft PR for it. Though even |
Note: Your screenshot shows, that it's never working - with or without a space. The problem seems to be, that https://github.com/ChuckJonas/vscode-apex-pmd still uses PMD 6.42.0 (see https://github.com/ChuckJonas/vscode-apex-pmd/tree/master/bin/pmd/lib) and support for binding vars in dynamic queries was added only with PMD 6.54.0 (see #2669).
That I can't reproduce. Are you sure, you are using PMD 7.0.0-rc2? The false positive with using a space before the colon is still valid though and needs to be fixed... |
Good catch @adangel I was on another device and I hadn't configured the pmd bin path. So this issue and suggestions are more for variable names with |
I'm reading this thread, and I'm not sure that @adangel question was answered: I write SOQL as: Technically, the spaces between (FWIW, most of the code I see types like I do, but that may be confirmation bias 😄 ) |
Affects PMD Version: 7.0.0-rc2
Rule: UnusedLocalVariable
Description:
Code Sample demonstrating the issue:
Expected outcome:
PMD reports a violation at line 1, but that's wrong. That's a false positive.
Running PMD through: [CLI]
The text was updated successfully, but these errors were encountered: