目錄

noop_primitive_operations

無操作的基本運算。

此規則自 Dart 2.14 起可用。

此規則提供快速修正

詳細資訊

#

基本類型上的某些運算為等冪運算,可以移除。

不良範例

dart
doubleValue.toDouble();

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

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

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

請注意,字串開頭或結尾的空字串常值是允許的,因為它們通常用於在多行中格式化字串常值

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