use-function-type-syntax-for-parameters
Same as use_function_type_syntax_for_parameters in Dart lints
- Group
- Style
- Path
lint/style/use-function-type-syntax-for-parameters- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 491 of 512
Flags an old-style function-typed parameter written with inline parameter syntax.
Dart lets you declare a function-typed parameter two ways. The legacy form
inlines the callee's own parameter list — void f(int g(int x)) — while the
modern generic function type syntax writes the type up front:
void f(int Function(int) g). The modern form is preferred because it reads
as an ordinary typed parameter, composes with nullability (Function(int)?),
and keeps the parameter name in its usual place. The rule detects the old form
by the nested parameter list the parser attaches to it; the modern form parses
as a plain parameter with a function type and is not flagged. Rewrite using
Function type syntax. Diagnostics cover the complete parameter declaration.
Invalid
// Old-style function-typed parameters.
void forEach(int f(int x)) {}
void run(void cb()) {}
int apply(int g(int a, int b)) => g(1, 2);
void sortBy(bool compare(int a, int b)) {}
void schedule(void task(), int delay) {}
class C {
void method(String fn(int x)) {}
}// Old-style function-typed parameters.void forEach(int f(int x)) {}void forEach(int f(int x)) {}void run(void cb()) {}void run(void cb()) {}int apply(int g(int a, int b)) => g(1, 2);int apply(int g(int a, int b)) => g(1, 2);void sortBy(bool compare(int a, int b)) {}void sortBy(bool compare(int a, int b)) {}void schedule(void task(), int delay) {}class C { void method(String fn(int x)) {}Valid
// Modern generic function type syntax for parameters, plus plain params.
void forEach(int Function(int x) f) {}
void run(void Function() cb) {}
int apply(int Function(int, int) g) => g(1, 2);
void sortBy(bool Function(int, int) compare) {}
void plain(int a, String b) {}
class C {
void method(void Function() fn) {}
}Configure use-function-type-syntax-for-parameters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"use-function-type-syntax-for-parameters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/use-function-type-syntax-for-parameters: <reason>More style rules
- use-if-null-to-convert-nulls-to-bools
use_if_null_to_convert_nulls_to_boolsrecommendedPrefers
??to comparing a nullableboolagainst a boolean literal. - use-late-for-private-fields-and-variables
use_late_for_private_fields_and_variablesFlags a private nullable field or top-level variable that is only ever assigned non-null values and read through
!, so it could belatewith a non-nullable type. - use-named-constants
use_named_constantsrecommendedPrefers a class's predefined static constant to constructing an equal constant.
- use-raw-strings
use_raw_stringsFlags string literals whose only escapes are
\\and\$, which a raw string would express without any backslash. - use-setters-to-change-properties
use_setters_to_change_propertiesFlags one-parameter
voidmethods that only assign that parameter to a field. - use-spacer-as-expanded-child
use_spacer_as_expanded_childrecommendedflutterFlags an
Expandedwrapping an emptySizedBoxorContainerthat should be aSpacer. - use-string-in-part-of-directives
use_string_in_part_of_directivesrecommendedFlags a
part ofdirective that names its library instead of using a string URI. - use-super-parameters
use_super_parametersrecommendedPrefer super parameters when a constructor only forwards parameters to its superclass.