avoid-annotating-with-dynamic
Same as avoid_annotating_with_dynamic in Dart lints
- Group
- Style
- Path
lint/style/avoid-annotating-with-dynamic- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 14 of 512
Flags parameters explicitly annotated with dynamic.
An unannotated parameter is already dynamic (or inferred from an
override), so writing dynamic adds noise. This covers regular, field
(this.x), and super (super.x) formals, function-typed formals whose
return type is dynamic (dynamic f()), setter parameters, and the
parameters of function types. dynamic must resolve through dart:core:
a file that imports dart:core only with a prefix sees core.dynamic,
not a bare dynamic.
void log(dynamic value) {} // flagged
void log(value) {} // ok
Invalid
class Holder {
dynamic value;
Holder(dynamic this.value);
void set(dynamic v) {}
set current(dynamic v) {}
}
class Child extends Holder {
Child(dynamic super.value);
}
void log(dynamic message) {}
void named({dynamic extra}) {}
// A function-typed formal returning `dynamic` is annotated with `dynamic` too.
void callback(dynamic f()) {}
typedef Callback = void Function(dynamic event);
void main() {
final f = (dynamic x) => x;
print(f);
} dynamic value; Holder(dynamic this.value); Holder(dynamic this.value); void set(dynamic v) {} void set(dynamic v) {} set current(dynamic v) {}class Child extends Holder { Child(dynamic super.value); void log(dynamic message) {} void named({dynamic extra}) {}// A function-typed formal returning `dynamic` is annotated with `dynamic` too.void callback(dynamic f()) {} typedef Callback = void Function(dynamic event);void main() { final f = (dynamic x) => x;Valid
class Holder {
dynamic value;
Holder(this.value);
void set(v) {}
set current(v) {}
}
void log(Object? message) {}
void untyped(message) {}
dynamic decode(String json) => json;
typedef Legacy(event);
typedef Callback = void Function(Object? event);
void main() {
final f = (x) => x;
final List<dynamic> list = [];
dynamic local = 1;
print([f, list, local]);
}Configure avoid-annotating-with-dynamic
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-annotating-with-dynamic": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-annotating-with-dynamic: <reason>More style rules
- avoid-bloc-public-fieldsbloc
Keep package-confirmed Bloc instance fields private; inherited API overrides are allowed.
- avoid-bloc-public-methodsbloc
Enforce the package-confirmed Bloc convention.
- avoid-bool-literals-in-conditional-expressions
avoid_bool_literals_in_conditional_expressionsrecommendedFlags conditional expressions over
boolthat have aboolliteral branch. - avoid-catches-without-on-clauses
avoid_catches_without_on_clausesAvoid
catchclauses without anontype. - avoid-catching-errors
avoid_catching_errorsDon't explicitly catch
Erroror types that implement it. - avoid-double-and-int-checks
avoid_double_and_int_checksrecommendedAvoid checking a value for
doubleand then forint. - avoid-equals-and-hash-code-on-mutable-classes
avoid_equals_and_hash_code_on_mutable_classesFlags
==andhashCodeoverrides in classes not marked@immutable. - avoid-escaping-inner-quotes
avoid_escaping_inner_quotesFlags a string literal that escapes its own quote character when switching the outer quotes would remove every escape.