Skip to content

call_method_written_out

Reports a function value called through its call method, such as onDone.call(result). Call the function itself.

Tier
advisory
Scope
Dart
Lowest preset
recommended
Fix
deletes .call

A call that names the call method of a value of a function type: onDone.call(result).

It does not report:

  • ?.call, which has no shorter form;
  • a cascade;
  • a value of the type Function or dynamic;
  • a call of an extension;
  • an object whose class declares a call method, such as loginUseCase.call(params) or a code builder’s refer('print').call([]). There call names what the object does, and writing it says that an object is called.

A function is called by writing its arguments after it. .call says nothing more, and makes the reader look for a method that is not there.

Violating
void finish(void Function(int) onDone) => onDone.call(1);
Corrected
void finish(void Function(int) onDone) => onDone(1);

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// The generated client documents this callback by its call method.
// ignore: assay/call_method_written_out

// ignore_for_file: assay/call_method_written_out silences it in a whole file, and // ignore: call_method_written_out without the prefix works too. See Suppressions.