目录

use_string_buffers

目录

Use string buffers to compose strings.

This rule is available as of Dart 2.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:

dart
String foo() {
  final buffer = '';
  for (int i = 0; i < 10; i++) {
    buffer += 'a'; // LINT
  }
  return buffer;
}

GOOD:

dart
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:

analysis_options.yaml
yaml
linter:
  rules:
    - use_string_buffers