prefer-adjacent-string-concatenation
Same as prefer_adjacent_string_concatenation in Dart lints
- Group
- Style
- Path
lint/style/prefer-adjacent-string-concatenation- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 312 of 512
Flags two string literals joined with the + operator.
Dart concatenates adjacent string literals at compile time, so 'a' 'b' is
equivalent to 'a' + 'b' but without the runtime operator or the visual
noise. The rule fires only when both operands of an Add expression are
string literals; a literal added to any other expression is left alone, since
adjacency cannot express that. Prefer writing the pieces side by side, which
also reads naturally when splitting a long string across lines.
Invalid
// Bad: joining two string literals with `+` instead of writing them adjacent.
void examples() {
final a = 'foo' + 'bar';
final b = 'hello, ' + 'world';
final c = '' + 'x';
final d = 'line1\n' + 'line2';
final e = "a" + "b";
final f = 'value: ' + '${1}';
print([a, b, c, d, e, f]);
}void examples() { final a = 'foo' + 'bar'; final a = 'foo' + 'bar'; final b = 'hello, ' + 'world'; final b = 'hello, ' + 'world'; final c = '' + 'x'; final c = '' + 'x'; final d = 'line1\n' + 'line2'; final d = 'line1\n' + 'line2'; final e = "a" + "b"; final e = "a" + "b"; final f = 'value: ' + '${1}';Valid
// Good: no `+` join of two string literals.
void examples() {
const name = 'world';
final a = 'foo' 'bar'; // adjacent string literals
final b = 'hello ' + name; // right operand is not a literal
final c = name + 'x'; // left operand is not a literal
final d = 1 + 2; // not strings at all
final e = 'count: ' + 3.toString(); // right operand is not a literal
final f = ['a', 'b'].join(); // no `+` operator
print([a, b, c, d, e, f]);
}Configure prefer-adjacent-string-concatenation
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-adjacent-string-concatenation": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-adjacent-string-concatenation: <reason>More style rules
- prefer-align-over-containerflutter
Prefers
Alignover aContainerused only foralignment. - prefer-asserts-in-initializer-lists
prefer_asserts_in_initializer_listsFlags leading constructor-body asserts that could live in the initializer list.
- prefer-asserts-with-message
prefer_asserts_with_messageFlags
assertstatements and assert initializers that have no message. - prefer-async-await
prefer-async-awaitFlags
.then(...)future chains that should useasync/await. - prefer-async-callback
prefer_async_callbackflutterFlags the type
Future<void> Function()in favor of Flutter'sAsyncCallback. - prefer-bloc-event-suffixbloc
Enforce the package-confirmed Bloc convention.
- prefer-bloc-extensionsbloc
Prefer context.read/watch over
package:flutter_bloc's provider lookups. - prefer-bloc-state-suffixbloc
Enforce the package-confirmed Bloc convention.