prefer-generic-function-type-aliases
Same as prefer_generic_function_type_aliases in Dart lints
- Group
- Style
- Path
lint/style/prefer-generic-function-type-aliases- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 364 of 512
Flags old-style function typedefs written with inline parameter syntax.
Dart's original typedef form, typedef int F(int x);, predates generic
function types and cannot express a function type in every position the
modern syntax can. Rewriting it as typedef F = int Function(int); is more
uniform, composes with generics, and reads consistently with other type
aliases. Legacy declarations retain their written formal parameter list in
the syntax tree, distinguishing them from modern aliases.
Invalid
// Old-style (non-generic) function typedefs.
typedef int Compare(int a, int b);
typedef void Callback(String msg);
typedef bool Predicate(Object o);
typedef String Formatter(int value);
typedef num Reducer(num a, num b);
typedef void Handler();// Old-style (non-generic) function typedefs.typedef int Compare(int a, int b);typedef int Compare(int a, int b);typedef void Callback(String msg);typedef void Callback(String msg);typedef bool Predicate(Object o);typedef bool Predicate(Object o);typedef String Formatter(int value);typedef String Formatter(int value);typedef num Reducer(num a, num b);typedef num Reducer(num a, num b);typedef void Handler();Valid
// Modern generic function type syntax, plus non-function aliases.
typedef Compare = int Function(int a, int b);
typedef Callback = void Function(String msg);
typedef Predicate<T> = bool Function(T value);
typedef IntList = List<int>;
typedef Json = Map<String, dynamic>;
typedef VoidFn = void Function();
// A `typedef` token inside a triple-quoted string is not a declaration.
const doc = '''
It's a typedef int Compare(int a, int b); in prose only.
''';Configure prefer-generic-function-type-aliases
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-generic-function-type-aliases": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-generic-function-type-aliases: <reason>More style rules
- prefer-getter-over-method
Prefer getters for synchronous, zero-argument methods that only read a field.
- prefer-initializing-formals
prefer_initializing_formalsrecommendedPrefer initializing formals when a parameter is copied directly into its field.
- prefer-inlined-adds
prefer_inlined_addsrecommendedFlags an
addcascade on a list literal whose element could be written inline. - prefer-int-literals
prefer_int_literalsFlags a whole-number double literal, such as
1.0, where the context type isdoubleso the int literal1means the same value. - prefer-interpolation-to-compose-strings
prefer_interpolation_to_compose_stringsrecommendedPrefers string interpolation to composing strings with
+. - prefer-is-empty
prefer_is_emptyrecommendedFlags
.lengthcomparisons equivalent to a.isEmptycheck. - prefer-is-not-empty
prefer_is_not_emptyrecommendedFlags
.lengthcomparisons equivalent to a.isNotEmptycheck. - prefer-is-not-operator
prefer_is_not_operatorrecommendedFlags a negated type test
!(x is T)that should use theis!operator.