function-always-returns-same-value
Warns when a function always returns the same constant value (e.g. true
).
Returning the same constant value from all return branches is usually a bug.
Example
❌ Bad:
// LINT: This function always returns the same value. Try checking it for a potential mistake.
bool withFlag(bool someCondition, bool another) {
if (someCondition) {
return true;
} else if (another) {
return true;
}
return true;
}
// LINT: This function always returns the same value. Try checking it for a potential mistake.
String withString(int value) {
if (value == 2) {
print('hello');
return 'hi';
} else {
return 'hi';
}
}
✅ Good:
bool withFlag(bool someCondition, bool another) {
if (someCondition) {
return true;
} else if (another) {
return false;
}
return true;
}
String withString(int value) {
if (value == 2) {
print('hello');
return 'hello';
} else {
return 'hi';
}
}