noop_primitive_operations
Noop primitive operations.
Details
#Some operations on primitive types are idempotent and can be removed.
BAD:
dart
doubleValue.toDouble();
intValue.toInt();
intValue.round();
intValue.ceil();
intValue.floor();
intValue.truncate();
string.toString();
string = 'hello\n'
''
'world';
'string with ${x.toString()}';
Note that the empty string literals at the beginning or end of a string are allowed, as they are typically used to format the string literal across multiple lines:
dart
// OK
string = ''
'hello\n'
'world\n';
// OK
string = 'hello\n'
'world\n'
'';
Enable
#To enable the noop_primitive_operations
rule,
add noop_primitive_operations
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- noop_primitive_operations
If you're instead using the YAML map syntax to configure linter rules,
add noop_primitive_operations: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
noop_primitive_operations: true
除非另有说明,文档之所提及适用于 Dart 3.7.2 版本,本页面最后更新时间: 2025-03-07。 查看文档源码 或者 报告页面问题。