use_string_buffers
Use string buffers to compose strings.
This rule is available as of Dart 2.0.0.
Details
DO use string buffers to compose strings.
In most cases, using a string buffer is preferred for composing strings due to its improved performance.
BAD:
String foo() {
final buffer = '';
for (int i = 0; i < 10; i++) {
buffer += 'a'; // LINT
}
return buffer;
}
GOOD:
String foo() {
final buffer = StringBuffer();
for (int i = 0; i < 10; i++) {
buffer.write('a');
}
return buffer.toString();
}
Usage
To enable the use_string_buffers
rule,
add use_string_buffers
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- use_string_buffers