sdk
sdk copied to clipboard
`void_checks` quick-fix suggestion
Repro:
void foo(void _) {}
void bar({void value}) {}
void main() {
foo(0);
bar(value: 0);
}
When the value is required, we should replace it with null, and when it isn't, we should remove the given parameter.
CC @bwilkerson
Both of those fixes seem reasonable, but I probably wouldn't spend time working on them. I suspect that the number of parameters with a value of void is exceedingly small. (If I'm wrong I'd be happy to change my mind.)
The real value would be a lint that would prevent the use of void as (a) the type of a local variable, parameter, field, or top-level variable or as the return type of a getter. (I might make an exception for a parameter if the method overrides another method, as I could imagine a use case for that, though I'd find a different solution.)
We already have a fix for avoid_redundant_argument_values, which with some small tweaks should work here.
void bar({int myValue = 0}) {
bar(myValue: 0); // <- Remove parameter
}
The real value would be a lint that would prevent the use of void as (a) the type of a local variable, parameter, field, or top-level variable or as the return type of a getter. (I might make an exception for a parameter if the method overrides another method, as I could imagine a use case for that, though I'd find a different solution.)
Agreed. If you ever think this should be done with some priority, please let me know so I can help on this too. Do you want me to open another issue just so this doesn't get lost?
For related discussions, see
- https://github.com/dart-lang/sdk/issues/58053
- https://github.com/dart-lang/sdk/issues/58765
I added a question to one of them.