unnecessary-brace-in-string-interps
Same as unnecessary_brace_in_string_interps in Dart lints
- Group
- Style
- Path
lint/style/unnecessary-brace-in-string-interps- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 450 of 512
Flags ${x} string interpolations whose braces can be dropped.
When the interpolated expression is a single plain identifier and the character
immediately after the closing } cannot extend that identifier, ${name} is
equivalent to the leaner $name. The braces are still required for anything more
than a bare identifier (field access, calls, operators) or when the following
character would otherwise merge into the name, so those cases are left alone. Raw
strings and escaped \$ sequences are skipped, and a $ right after the } is
treated as extending the name so the braces are kept.
Invalid
// Bad: `${name}` where `name` is a simple identifier and the braces are not needed.
void examples(int count, String name) {
final a = 'total: ${count}';
final b = 'hi ${name}!';
final c = '${count} items';
final d = 'a ${name}.b';
final e = "value=${count}";
final f = 'label ${name}';
print([a, b, c, d, e, f]);
}void examples(int count, String name) { final a = 'total: ${count}'; final a = 'total: ${count}'; final b = 'hi ${name}!'; final b = 'hi ${name}!'; final c = '${count} items'; final c = '${count} items'; final d = 'a ${name}.b'; final d = 'a ${name}.b'; final e = "value=${count}"; final e = "value=${count}"; final f = 'label ${name}';Valid
// Good: braces are needed, or there are none to remove.
void examples(int count, String name, Map<String, int> m) {
final a = 'total: $count'; // no braces
final b = 'items: ${count}x'; // next char extends the identifier
final c = 'sum: ${count + 1}'; // expression, not a simple identifier
final d = 'field: ${m['a']}'; // index expression
final e = 'call: ${name.length}'; // member access
final f = 'literal text'; // no interpolation
final g = '${count}9'; // next char is a digit — would extend
final h = r'${notInterpolated}'; // raw string — not an interpolation
print([a, b, c, d, e, f, g, h]);
}Configure unnecessary-brace-in-string-interps
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"unnecessary-brace-in-string-interps": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/unnecessary-brace-in-string-interps: <reason>More style rules
- unnecessary-breaks
unnecessary_breaksrecommendedFlags a trailing
breakin a switch case that already ends implicitly. - unnecessary-constructor-name
unnecessary_constructor_namerecommendedFlags a redundant
.newon constructor declarations and invocations. - unnecessary-final
unnecessary_finalDon't use
finalfor local variables and parameters. - unnecessary-late
unnecessary_laterecommendedFlags a redundant
latemodifier on an initialized static or top-level variable. - unnecessary-library-directive
unnecessary_library_directiverecommendedFlags a
librarydirective that has neither a doc comment nor annotations. - unnecessary-library-name
unnecessary_library_namerecommendedFlags a
librarydirective that carries an explicit name. - unnecessary-new
unnecessary_newrecommendedFlags an explicit
newkeyword in an instance-creation expression. - unnecessary-null-aware-operator-on-extension-on-nullable
unnecessary_null_aware_operator_on_extension_on_nullableFlags a null-aware access whose member comes from an extension on a nullable type.