prefer-correct-handler-name

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

Match callback handler methods to a configured regular expression.

Nonempty valid regex name-pattern enables the rule. ignore-public (default false) exempts public methods. Direct method tear-offs passed as positional or named arguments are checked, including unqualified references unless shadowed by a lexical binding. Only ordinary unannotated methods declared on an enclosing class without supertypes are checked. Global functions, arbitrary object methods and closure wrappers are excluded. Leading privacy underscores are ignored.

Invalid

example.dartdart
void listen({required void Function() onTap}) {}
void consume(void Function() callback) {}
class Controller {
  void tap() {}
  void work() {}
  void positionalWork() {}
  void install() {
    listen(onTap: this.tap);
    listen(onTap: this.tap);
    listen(onTap: work);
    consume(positionalWork);
  }
}
This callback handler does not match `^handle[A-Z]`; rename it to match the configured pattern.
3class Controller {
4 void tap() {}
This callback handler does not match `^handle[A-Z]`; rename it to match the configured pattern.
4 void tap() {}
5 void work() {}
This callback handler does not match `^handle[A-Z]`; rename it to match the configured pattern.
5 void work() {}
6 void positionalWork() {}

Valid

example.dartdart
void listen({required void Function() onTap}) {}
void consume(void Function() callback) {}
void globalWork() {}
class Controller {
  void _handleTap() {}
  void ordinaryMethod() {}
  void install(void Function() ordinaryMethod) {
    listen(onTap: this._handleTap);
    consume(this._handleTap);
    listen(onTap: () {});
    listen(onTap: ordinaryMethod);
    consume(globalWork);
  }
}
class Child extends Controller {
  void ordinaryMethod() {}
  void wire() { listen(onTap: this.ordinaryMethod); }
}
abstract class HandlerContract {
  void tap();
}
class HandlerImplementation implements HandlerContract {
  void tap() {}
  void wire() { listen(onTap: tap); }
}

Configure prefer-correct-handler-name

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

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

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

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