always-specify-types
Same as always_specify_types in Dart lints
- Group
- Style
- Path
lint/style/always-specify-types- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 8 of 512
Requires explicit type annotations everywhere a type could be inferred.
This is the opposite of omit-local-variable-types: every variable,
loop variable, pattern variable, and parameter needs a declared type;
collection literals need explicit type arguments; and generic types need
their type arguments spelled out instead of defaulting to dynamic.
var count = 0; // flagged
final names = []; // flagged (twice: declaration and literal)
List items = <int>[]; // flagged: raw generic type
int count = 0; // ok
Raw generic interface types (classes, mixins, enums, extension types, and
FutureOr) and their generic typedefs need explicit arguments in
annotations, inheritance clauses, casts, object patterns (also in pattern
assignments), constructor invocations, and type literals (print(Box),
'$Box', case Box:). is checks, constructor tear-offs, static member
accesses, and declarations with @optionalTypeArgs are exempt. Loaded
declaration metadata supplies generic arity; SDK-free analysis retains the
existing identity fallback.
Diagnostic ranges follow the analyzer's syntax anchors: collection literals and variable patterns highlight their first token, while unmodified untyped parameters highlight the entire parameter (including attached documentation, metadata, and defaults).
Invalid
var count = 0;
final String name = 'x';
const limit = 3;
List raw = <int>[];
class Box<T> {
final T value;
Box(this.value);
}
class Holder {
final items = <int>[];
Map lookup = <String, int>{};
Box box = Box<int>(1);
}
void f(x, int y) {
var local = 1;
final List<int> list = [];
final Set<int> set = {};
final Map<String, int> map = {};
for (var i = 0; i < 2; i++) {}
for (final e in list) {}
final Box<int> b = Box(1);
final (int a, String s) = (1, '');
final (int c, d) = (1, 2);
if (y case final z) {}
final g = (v) => v;
}
set value(v) {}var count = 0;final String name = 'x';const limit = 3;const limit = 3;List raw = <int>[];class Holder { final items = <int>[]; final items = <int>[]; Map lookup = <String, int>{}; Map lookup = <String, int>{}; Box box = Box<int>(1); void f(x, int y) {void f(x, int y) { var local = 1; var local = 1; final List<int> list = []; final List<int> list = []; final Set<int> set = {}; final Set<int> set = {}; final Map<String, int> map = {}; final Map<String, int> map = {}; for (var i = 0; i < 2; i++) {} for (var i = 0; i < 2; i++) {} for (final e in list) {} for (final e in list) {} final Box<int> b = Box(1); final (int a, String s) = (1, ''); final (int c, d) = (1, 2); final (int c, d) = (1, 2); if (y case final z) {} if (y case final z) {} final g = (v) => v; if (y case final z) {} final g = (v) => v; set value(v) {}Valid
int count = 0;
final String name = 'x';
const int limit = 3;
List<int> typed = <int>[];
class Box<T> {
final T value;
Box(this.value);
}
class Plain {
final int id;
Plain(this.id);
}
class Holder {
final List<int> items = <int>[];
Map<String, int> lookup = <String, int>{};
Box<int> box = Box<int>(1);
Plain plain = Plain(1);
}
void f(Object o, int y, void Function(int) cb) {
int local = 1;
final List<int> list = <int>[];
final Map<String, int> map = <String, int>{};
for (int i = 0; i < 2; i++) {}
for (final int e in list) {}
final Box<int> b = Box<int>(1);
final (int a, String s) = (1, '');
if (o is List) {}
if (o is Box) {}
if (y case final int z) {}
final int Function(int) g = (int v) => v;
int x;
x = 1;
int p;
(p, _) = (1, 2);
print(<Object>[local, map, a, s, b, g, x, p]);
}
set value(int v) {}Configure always-specify-types
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"always-specify-types": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/always-specify-types: <reason>More style rules
- annotate-overrides
annotate_overridesrecommendedRequires
@overrideon members that override an inherited declaration. - arguments-ordering
Named arguments follow their resolved parameter declaration order by default.
- avoid-abbreviations-in-doc-comments
avoid_abbreviations_in_doc_commentsFlags Latin abbreviations in doc comments.
- avoid-annotating-with-dynamic
avoid_annotating_with_dynamicFlags parameters explicitly annotated with
dynamic. - 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.