Closed lukehutch closed 6 months ago
We have an 'unnecessary_statements' lint, which could perhaps inform whether to remove the right side as well.
Even if that isn't great, or needs design work, I think we should err on safety and just remove the assignment, not the right side.
Not sure what we'd do with multiple variables in a declaration. Or assignment patterns. Something like:
void f() {
var x = 1, y = 2;
print(x);
}
We could change this to:
void f() {
var x = 1;
2; // unless we can declare this is an unnecessary statement.
print(x);
}
🤷
Given the following code:
the analyzer gives a fix suggestion of
Remove unused local variable
. Unfortunately the result of running this action is:Since VS Code runs this action on save, it's a good way to lose code that has side effects, if you habitually hit Ctrl+S all the time like I do.
I would expect the result to be the following, assuming the analyzer can't actually tell if the function call has any side effects or not (and the fix should probably be renamed
Remove unused local variable declaration
in this case):Dart info: