one-member-abstracts
Same as one_member_abstracts in Dart lints
- Group
- Complexity
- Path
lint/complexity/one-member-abstracts- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 304 of 512
Flags abstract classes whose only member is a single abstract method.
Such a class is just a function type with extra ceremony; a top-level function or a function-typed parameter does the same job. Classes that extend, mix in, or implement another type, or that declare any field, getter, or setter, are left alone because they carry more than one member.
abstract class Predicate { bool test(Object o); } // flagged
typedef Predicate = bool Function(Object o); // ok
Invalid
abstract class Predicate {
bool test(Object value);
}
abstract class Loader {
const Loader();
Future<String> load(String path);
}
abstract interface class Formatter {
String format(int value);
}
abstract class Adder {
int operator +(int other);
}
abstract mixin class Runner {
void run();
}abstract class Predicate { abstract class Loader { abstract interface class Formatter { abstract class Adder { abstract mixin class Runner {Valid
class Concrete {
void run() {}
}
abstract class WithField {
int get id;
void run();
}
abstract class TwoMethods {
void start();
void stop();
}
abstract class Base {}
abstract class Extending extends Base {
void run();
}
abstract class Implementing implements Base {
void run();
}
abstract class WithBody {
void run() {}
}
abstract class WithState {
int count = 0;
void run();
}
abstract class WithSetter {
set value(int v);
void run();
}
abstract class Empty {}Configure one-member-abstracts
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"complexity": {
"one-member-abstracts": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/complexity/one-member-abstracts: <reason>More complexity rules
- prefer-conditional-assignment
prefer_conditional_assignmentrecommendedFlags
if (x == null) { x = y; }with no else branch. - prefer-conditional-expressions
prefer-conditional-expressionsFlags an
if/elsewhose branches each reduce to a single return or a single assignment to the same target. - prefer-expression-function-bodies
prefer_expression_function_bodiesFlags block function bodies that consist of a single
returnof a value. - prefer-extracting-callbacks
prefer-extracting-callbacksflutterFlags inline block-body callbacks passed to Widget constructors.
- prefer-for-elements-to-map-from-iterable
prefer_for_elements_to_map_fromIterablerecommendedFlags
Map.fromIterable(x, key: ..., value: ...). - prefer-if-elements-to-conditional-expressions
prefer_if_elements_to_conditional_expressionsPrefers collection
ifelements to conditional expressions in list and set literals. - prefer-if-null-operators
prefer_if_null_operatorsrecommendedFlags
x == null ? y : x(and the invertedx != null ? x : y). - prefer-immediate-return
prefer-immediate-returnFlags a local variable that is returned on the immediately following statement.