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)
$_ is already ignored by the UnusedVariable checks.
Are you finding somewhere where it's not?
I forgot about $_ being supported. This would be a request for supporting $unused as a prefix, then (Or adding a configurable regex)
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.
Agreed – just encountered this today
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).
@TysonAndre that's handled with PossiblyUnusedParam vs UnusedParam
Psalm will now ignore any param beginning with $unused
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; }, []);
@weirdan @sserbin this is now fixed in master
hey @muglug
was this feature removed?
https://psalm.dev/r/5041b20cdb