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
recommended

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

example.dartdart
// 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]);
}
Remove the unnecessary braces in this string interpolation and use `$name` instead.
2void examples(int count, String name) {
3 final a = 'total: ${count}';
Remove the unnecessary braces in this string interpolation and use `$name` instead.
3 final a = 'total: ${count}';
4 final b = 'hi ${name}!';
Remove the unnecessary braces in this string interpolation and use `$name` instead.
4 final b = 'hi ${name}!';
5 final c = '${count} items';
Remove the unnecessary braces in this string interpolation and use `$name` instead.
5 final c = '${count} items';
6 final d = 'a ${name}.b';
Remove the unnecessary braces in this string interpolation and use `$name` instead.
6 final d = 'a ${name}.b';
7 final e = "value=${count}";
Remove the unnecessary braces in this string interpolation and use `$name` instead.
7 final e = "value=${count}";
8 final f = 'label ${name}';

Valid

example.dartdart
// 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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "unnecessary-brace-in-string-interps": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/unnecessary-brace-in-string-interps: <reason>