avoid-print
Same as avoid_print in Dart lints
- Group
- Suspicious
- Path
lint/suspicious/avoid-print- Default
- On (recommended)
- Origin
- Dart lints
- Domain
- flutter
- Rule
- 114 of 512
Flags calls and callback arguments resolving to dart:core's print.
Lexical bindings and members declared in the enclosing body shadow it.
Calls guarded by Flutter's kDebugMode are exempt within the same function body.
Diagnostics underline the print identifier, not the invocation or its arguments.
Invalid
// Bad: calls to the top-level print function.
void main() {
print('hello');
print(42);
const value = 7;
print(value);
print('sum: ${value + 1}');
final list = [1, 2, 3];
list.forEach((e) => print(e));
print('done');
}
// A local shadow declared in a try, catch or finally body is scoped to that
// body and must not suppress the call after the statement.
void scopedShadow() {
try {
void print(Object? value) {}
print('shadowed');
} catch (_) {
void print(Object? value) {}
print('shadowed');
} finally {
void print(Object? value) {}
print('shadowed');
}
print('real');
}void main() { print('hello'); print('hello'); print(42); const value = 7; print(value); print(value); print('sum: ${value + 1}'); final list = [1, 2, 3]; list.forEach((e) => print(e)); list.forEach((e) => print(e)); print('done'); } print('real');Valid
// Good: no calls to the top-level print function.
void main() {
debugPrint('hello');
logger.info('message');
final printer = Printer();
printer.print('doc');
stdout.write('line');
final summary = describe();
logger.info(summary);
}
void debugPrint(String s) {}
class Printer {
void print(String s) {}
}
class Logger {
void info(String s) {}
}
final logger = Logger();
final stdout = StringSink();
class StringSink {
void write(String s) {}
}
String describe() => 'ok';
void shadowedByParameter(void Function(Object?) print) {
print('user function');
}
class HasPrintMember {
void print(Object? value) {}
void run() {
print('member');
}
}Configure avoid-print
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-print": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-print: <reason>More suspicious rules
- avoid-referencing-subclasses
Keeps base classes independent from their transitive subclasses.
- avoid-returning-null-for-void
avoid_returning_null_for_voidrecommendedFlags
return null;(and=> nullbodies) in synchronousvoidfunctions and asynchronousFuture<void>functions. - avoid-shadowed-extension-methods
Flags extension instance methods and accessors hidden by their target's members.
- avoid-shadowing
Flags local bindings and parameters that hide an enclosing type's member.
- avoid-shadowing-type-parameters
avoid_shadowing_type_parametersrecommendedFlags a type parameter that shadows a type parameter of an enclosing declaration.
- avoid-suspicious-super-overrides
Finds getters hiding fields supplied via the immediate super constructor's
this.formals or declaring primary-constructor parameters. - avoid-throw-in-catch-block
avoid-throw-in-catch-blockFlags
throwstatements inside acatchblock. - avoid-top-level-members-in-teststest
Requires public declarations in test files, except main, to be private.