tear_off_in_string
Reports a method or function named without a call where its text is shown, as in 'Total: $total'. Call it: 'Total: ${total()}'.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- calls the method or the function
What it reports
Section titled “What it reports”A method or function named without a call where its text is shown:
- in an interpolation:
'Total: $total'; - as an argument of a log call:
print(user.describe).
The text is “Closure: () => int from Function ‘total’”, never what the call gives. The violation covers the tear-off.
A log call is print, debugPrint, a function or method named log, a method of a class named Logger or ending in Logger, or a function or method you list in logging_calls.
It does not report:
- a tear-off given anywhere else, which is passed on on purpose: to
expect, toidentical, tomapinside the argument ofprint, or as a value of a map; - a variable or a field that holds a function;
- a getter.
A getter turned into a method, or a missing (), compiles without a word, since a function has a toString. The text shows a closure where a number or a name was meant.
Example
Section titled “Example”Text('Items: $count')Text('Items: ${count()}')The fix makes the call: '$total' becomes '${total()}', and print(user.describe) becomes print(user.describe()). It is offered where the method or function takes no required argument.
Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
logging_calls |
[] |
More functions and methods that write their arguments to a log, such as the methods of your own logger. print, debugPrint, log and the methods of a Logger count without it. |
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// The log names the callback on purpose.// ignore: assay/tear_off_in_stringprint(onDone);// ignore_for_file: assay/tear_off_in_string silences it in a whole file, and // ignore: tear_off_in_string without the prefix works too. See Suppressions.