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

Option to suppress UnusedVariable for certain variable names? #540

Closed
TysonAndre opened this issue Feb 23, 2018 · 10 comments
Closed

Option to suppress UnusedVariable for certain variable names? #540

TysonAndre opened this issue Feb 23, 2018 · 10 comments

Comments

@TysonAndre
Copy link
Contributor

TysonAndre commented Feb 23, 2018

It would be useful to be able to suppress $_ (EDIT: oh, that's supported already), and any variable name beginning with $unused

HHVM treats $_ as an unused variable - It doesn't analyze that variable's type, for example.

Sometimes an unused variable is unavoidable (e.g. foreach ($arr as $key => $unusedMyClassInstance) { use($key); }), or array destructuring assignments in php 7.0) (Edit: changed example)

@muglug
Copy link
Collaborator

muglug commented Feb 23, 2018

$_ is already ignored by the UnusedVariable checks.

Are you finding somewhere where it's not?

@TysonAndre
Copy link
Contributor Author

TysonAndre commented Feb 23, 2018

I forgot about $_ being supported. This would be a request for supporting $unused as a prefix, then (Or adding a configurable regex)

@weirdan
Copy link
Collaborator

weirdan commented Feb 26, 2018

It would be great if the same could be applied for UnusedParam, as often parameter list is dictated by interface and parameters could not be omitted even if they are unused. I would suggest $_ prefix for consistency with what's already there. This also has a precedent in TypeScript and, I think, Kotlin.

@muglug
Copy link
Collaborator

muglug commented Feb 26, 2018

Agreed – just encountered this today

@TysonAndre
Copy link
Contributor Author

Also, splitting issue types up for parameters based on the function/method/closure type ( (Private/Protected/Public)(/Final) and Closures) may be helpful. E.g. private methods should rarely ever need extra unused arguments (unless dynamically called), while public methods very often need unused parameters due to inheritance (as mentioned above).

@muglug
Copy link
Collaborator

muglug commented Feb 26, 2018

@TysonAndre that's handled with PossiblyUnusedParam vs UnusedParam

@muglug muglug closed this as completed in 80864b1 Feb 27, 2018
@muglug
Copy link
Collaborator

muglug commented Feb 27, 2018

Psalm will now ignore any param beginning with $unused

@weirdan
Copy link
Collaborator

weirdan commented Feb 27, 2018

sigh I actually hoped for prefix to be $_ (see example below) like in TypeScript, but ok.

array_map(function(string $_a, string $_b, string $c): string { return $c; }, []);

@muglug
Copy link
Collaborator

muglug commented Mar 2, 2018

@weirdan @sserbin this is now fixed in master

@mitelg
Copy link
Contributor

mitelg commented Oct 30, 2019

hey @muglug
was this feature removed?
https://psalm.dev/r/5041b20cdb

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

No branches or pull requests

4 participants