跳到主要內容

noop_primitive_operations

穩定
提供修正

Noop 原始運算。

詳細資訊

#

某些原始類型上的運算具有等冪性,可以移除。

錯誤範例

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

如果您改為使用 YAML map 語法來設定 linter 規則,請在 linter > rules 下新增 noop_primitive_operations: true

analysis_options.yaml
yaml
linter:
  rules:
    noop_primitive_operations: true