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.6.0。頁面最後更新於 2024-07-03。 檢視原始碼或回報問題。