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
特に記載がない限り、このサイトのドキュメントは Dart 3.5.3 を反映しています。最終更新日: 2024年7月3日。 ソースを表示 または 問題を報告する。