noop_primitive_operations
Noop primitive operations.
This rule is available as of Dart 2.14.
This rule has a quick fix available.
Details
#Some operations on primitive types are idempotent and can be removed.
BAD:
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:
// OK
string = ''
'hello\n'
'world\n';
// OK
string = 'hello\n'
'world\n'
'';
Usage
#To enable the noop_primitive_operations
rule, add noop_primitive_operations
under linter > rules in your analysis_options.yaml
file:
linter:
rules:
- noop_primitive_operations
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2024-07-03. View source or report an issue.