Skip to main content

avoid-unnecessary-parentheses

effort: 2m
has IDE fix
has auto-fix
pro+

Suggests removing unnecessary parentheses.

Example

❌ Bad:

void fn(List<int> input, List<int>? another) async {
// LINT: Unnecessary parentheses. Try removing them.
final _ = [...(input)];

// LINT: Unnecessary parentheses. Try removing them.
final _ = (input.isEmpty) ? true : false;

final toolPath = another != null
// LINT: Unnecessary parentheses. Try removing them.
? input.isEmpty ? input : (await input)
// LINT: Unnecessary parentheses. Try removing them.
: (input);
}

bool f(int a) {
return (a.isEven); // LINT: Unnecessary parentheses. Try removing them.
}

✅ Good:

void fn(List<int> input, List<int>? another) async {
final _ = [...input];
final _ = input.isEmpty ? true : false;

final toolPath = another != null
? input.isEmpty ? input : await input
: input;
}

bool f(int a) {
return a.isEven;
}