noop_primitive_operations
无操作原始操作。
详情
#原始类型上的某些操作是幂等的,可以移除。
错误示例
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 映射语法配置 linter 规则,请在 linter > rules 下添加 noop_primitive_operations: true
analysis_options.yaml
yaml
linter:
rules:
noop_primitive_operations: true
除非另有说明,否则本网站上的文档反映的是 Dart 3.7.1 版本。页面上次更新于 2025-03-07。 查看源代码 或 报告问题。