目录

avoid_print

Avoid print calls in production code.

此规则自 Dart 2.5 版本起可用。

_规则集:flutter _

此规则提供 快速修复

详情

#

DO avoid print calls in production code.

For production code, consider using a logging framework. If you are using Flutter, you can use debugPrint or surround print calls with a check for kDebugMode

BAD:

dart
void f(int x) {
  print('debug: $x');
  ...
}

GOOD:

dart
void f(int x) {
  debugPrint('debug: $x');
  ...
}

GOOD:

dart
void f(int x) {
  log('log: $x');
  ...
}

GOOD:

dart
void f(int x) {
  if (kDebugMode) {
      print('debug: $x');
  }
  ...
}

使用方法

#

要启用 avoid_print 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 avoid_print

analysis_options.yaml
yaml
linter:
  rules:
    - avoid_print