inline_pragma_without_body
Reports an inlining pragma on a declaration that has no body to inline. Delete the pragma, or put it on the member that has the body.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- deletes the pragma, with its line where it stands alone on it
What it reports
Section titled “What it reports”A pragma of dart:core that asks to inline a body, on a declaration that has none. The violation is on the annotation.
- The pragmas are
vm:prefer-inline,dart2js:prefer-inline,dart2js:tryInlineandwasm:prefer-inline. - The declarations are an abstract method, getter or setter, and a class, mixin, enum, extension, extension type or typedef.
It does not report:
- an
externalmember, whose body is written elsewhere; - a field or a variable;
- any other pragma;
- a class of your own named
pragma.
The fix is not offered where a comment stands before the pragma.
A compiler inlines the body of the function a call reaches. An abstract member has none, and an override does not take the pragma over, so the pragma asks for nothing.
Example
Section titled “Example”abstract class Shape { @pragma('vm:prefer-inline') double area();}abstract class Shape { double area();}Rule parameters
Section titled “Rule parameters”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. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why it stays as written here.// ignore: inline_pragma_without_body// ignore_for_file: assay/inline_pragma_without_body silences it in a whole file, and // ignore: assay/inline_pragma_without_body with the prefix works too. See Suppressions.