prefer-correct-callback-field-name

Group
Style
Path
lint/style/prefer-correct-callback-field-name
Default
Off, opt in
Origin
Falcon
Rule
335 of 512

Match callback field names to a configured regular expression.

name-pattern must be a valid regex. Missing or empty patterns leave the rule inactive. Leading privacy underscores are ignored. Resolved function fields, including aliases and Function, must match; proven non-function fields must not match. Unknown, dynamic and enclosing type-parameter types are excluded, as are inferred, static and annotated fields. Classes with supertypes are skipped to preserve inherited field/getter contracts.

Invalid

example.dartdart
typedef Callback = void Function();
class Callbacks {
  final void Function() tap;
  void Function(int)? _changed;
  Function? work;
  Callback? alias;
  String onValue = '';
  Callbacks(this.tap);
}
This callback field does not match `^on[A-Z]|^builder$|.*Builder$`; rename it to match the configured pattern.
2class Callbacks {
3 final void Function() tap;
This callback field does not match `^on[A-Z]|^builder$|.*Builder$`; rename it to match the configured pattern.
3 final void Function() tap;
4 void Function(int)? _changed;
This callback field does not match `^on[A-Z]|^builder$|.*Builder$`; rename it to match the configured pattern.
4 void Function(int)? _changed;
5 Function? work;
This callback field does not match `^on[A-Z]|^builder$|.*Builder$`; rename it to match the configured pattern.
5 Function? work;
6 Callback? alias;
This non-function field matches callback pattern `^on[A-Z]|^builder$|.*Builder$`; rename it so it does not match.
6 Callback? alias;
7 String onValue = '';

Valid

example.dartdart
typedef Callback = void Function();
class Callbacks {
  final void Function() onTap;
  void Function(int)? _onChanged;
  Callback? onAlias;
  Function? onUntypedFunction;
  static void Function()? staticCallback;
  final inferred = () {};
  int count = 0;
  Callbacks(this.onTap);
}
abstract class Contract {
  void Function() get tap;
}
class Implementation implements Contract {
  final void Function() tap;
  Implementation(this.tap);
}
class Box<Callback> {
  final Callback value;
  Box(this.value);
}

Configure prefer-correct-callback-field-name

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-correct-callback-field-name": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/prefer-correct-callback-field-name: <reason>