目次

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