avoid-redundant-pragma-inline
preset: recommended
Warns when a @pragma('vm:prefer-inline')
annotation has no effect.
The Dart compiler can't inline certain methods, even if they are annotated with @pragma("vm:prefer-inline")
.
Those include methods with a try
block, methods declared async
, async*
, sync*
and certain core library methods.
Example
❌ Bad:
class SomeClass {
('vm:prefer-inline') // LINT: This 'vm:pragma-inline' annotation has no effect. Try removing it.
Future<void> asyncMethod() async {
await good();
}
('vm:prefer-inline') // LINT: This 'vm:pragma-inline' annotation has no effect. Try removing it.
void methodWithTry() {
try {
// ...
} catch (_) {
print('error');
}
}
}
✅ Good:
class SomeClass {
('vm:prefer-inline')
Future<String> good() {
return Future.value('hello');
}
Future<void> asyncMethod() async {
await good();
}
void methodWithTry() {
try {
// ...
} catch (_) {
print('error');
}
}
}