no-adjacent-strings-in-list
Same as no_adjacent_strings_in_list in Dart lints
- Group
- Correctness
- Path
lint/correctness/no-adjacent-strings-in-list- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 280 of 512
Flags adjacent string literals used as an element of a list or set literal.
Adjacent strings concatenate, so a missing comma between two elements silently merges them into one:
var list = <String>[
'a' // flagged: a comma is missing, the list has two elements
'b',
'c',
];
var list = <String>['a' + 'b', 'c']; // fine: concatenation is explicit
Also checked: the body of a for element, the then element of an if
element without else (or the else element when present), and constant
string elements of a list pattern in a switch statement case. Map
literals and parenthesized elements are not checked.
Invalid
void use(Object o) {}
void main(bool flag, List<String> xs) {
use(<String>[
'a'
'b',
'c',
]);
use(['x' 'y']);
use(<String>{'set' 'element'});
use([if (flag) 'then' 'element']);
use([if (flag) 'then' else 'else' 'element']);
use([for (var x in xs) 'body' 'part']);
switch (xs) {
case ['pattern' 'element']:
break;
}
}
void nestedCollectionContexts(bool flag, List<String> xs) {
use([
for (final x in xs)
if (flag)
for (final y in xs)
'nested' 'body',
]);
use([
if (flag)
if (flag) 'innerThen' else 'inner' 'else'
else
for (final x in xs)
'outer' 'else',
]);
use([
if (['condition' 'list'].isNotEmpty) 'body',
for (final x in ['header' 'list']) x,
...['spread' 'list'],
]);
} use(<String>[ 'a' ]); use(['x' 'y']); use(['x' 'y']); use(<String>{'set' 'element'}); use(<String>{'set' 'element'}); use([if (flag) 'then' 'element']); use([if (flag) 'then' 'element']); use([if (flag) 'then' else 'else' 'element']); use([if (flag) 'then' else 'else' 'element']); use([for (var x in xs) 'body' 'part']); switch (xs) { case ['pattern' 'element']: for (final y in xs) 'nested' 'body', if (flag) if (flag) 'innerThen' else 'inner' 'else' for (final x in xs) 'outer' 'else', use([ if (['condition' 'list'].isNotEmpty) 'body', if (['condition' 'list'].isNotEmpty) 'body', for (final x in ['header' 'list']) x, for (final x in ['header' 'list']) x, ...['spread' 'list'],Valid
void use(Object o) {}
void main(bool flag, List<String> xs) {
use(<String>['a' + 'b', 'c']);
use(['a', 'b']);
use([('paren' 'thesized')]);
use({'map' 'key': 'value' 'part'});
use([if (flag) 'then' 'quirk' else 'else']);
use([...xs]);
use('not' 'in a list');
switch (xs) {
case ['a', 'b']:
break;
}
}
void collectionContextsDoNotLeak(bool flag, List<String> xs) {
use([
if (('condition' 'text').isNotEmpty) 'body',
for (final x in ('header' 'text').split('')) x,
...('spread' 'text').split(''),
if (flag)
'outerThen' 'excluded'
else
if (flag) 'innerThen' else 'innerElse',
]);
use([
if (flag) 'excluded' 'then' else 'included',
for (final x in xs) ('parenthesized' 'body'),
]);
use('outside' 'collection');
}Configure no-adjacent-strings-in-list
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"no-adjacent-strings-in-list": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/no-adjacent-strings-in-list: <reason>More correctness rules
- no-import-cyclescross-file
Report mutually dependent components of imported or exported library files.
- no-logic-in-create-state
no_logic_in_create_staterecommendedflutterRequire
StatefulWidget.createStateto return only a fresh zero-argument FlutterStateconstruction. - no-self-assignments
no_self_assignmentsrecommendedFlags assignments of a variable to itself, such as
x = x;. - null-check-on-nullable-type-parameter
null_check_on_nullable_type_parameterrecommendedFlags a null assertion
x!on a nullable type parameterT?whose expected type isTorT?for a potentially nullableT, and null-assert patterns whose matched value is a nullable type parameter. - null-closures
null_closuresrecommendedReject literal
nullin the closure slots of curated SDK APIs. - prefer-correct-json-casts
Decode JSON containers using their actual runtime generic types.
- prefer-define-hero-tagflutter
Require an explicit heroTag on Flutter
FloatingActionButtonconstructors. - prefer-expect-latertest
Requires expectLater when a canonical expect call receives an unawaited Future.