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