目录

noop_primitive_operations

Noop primitive operations.

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

此规则提供 快速修复

详情

#

Some operations on primitive types are idempotent and can be removed.

BAD:

dart
doubleValue.toDouble();

intValue.toInt();
intValue.round();
intValue.ceil();
intValue.floor();
intValue.truncate();

string.toString();
string = 'hello\n'
    ''
    'world';

'string with ${x.toString()}';

Note that the empty string literals at the beginning or end of a string are allowed, as they are typically used to format the string literal across multiple lines:

dart
// OK
string = ''
    'hello\n'
    'world\n';

// OK
string = 'hello\n'
    'world\n'
    '';

使用方法

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - noop_primitive_operations