目录

unnecessary_null_aware_operator_on_extension_on_nullable

Unnecessary null aware operator on extension on a nullable type.

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

详情

#

Avoid null aware operators for members defined in an extension on a nullable type.

BAD:

dart
extension E on int? {
  int m() => 1;
}
f(int? i) => i?.m();

GOOD:

dart
extension E on int? {
  int m() => 1;
}
f(int? i) => i.m();

使用方法

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - unnecessary_null_aware_operator_on_extension_on_nullable