---
title: Avoid unnecessary braces in string interpolations
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid unnecessary braces in string interpolations
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Avoid unnecessary braces in string interpolations

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `dart-code-quality/unnecessary-brace-in-string-interps`

**Language:** Dart

**Severity:** Notice

**Category:** Code Style

## Description{% #description %}

When a string interpolation contains only a simple identifier, the curly braces are unnecessary. Replace `${variable}` with `$variable` to reduce visual noise.

Braces are only needed when the interpolated expression contains dots, calls, operators, or other constructs that cannot be parsed as a bare identifier, such as `${user.name}` or `${getCount()}`.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dart
void main() {
  var name = 'Alice';
  var count = 42;
  var flag = true;
  const _tag = 'TAG';
  var a = 'Hello ${name}!';
  var b = 'Count: ${count}';
  var c = 'Flag: ${flag}';
  var d = '${_tag}: some message';
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```dart
void main() {
  var name = 'Alice';
  var greeting = 'Hello $name';
  var count = 42;
  var msg = 'Count: $count items';
  var obj = Object();
  var msg1 = 'Value: ${obj.toString()}';
  var a = 1;
  var b = 2;
  var msg2 = 'Sum: ${a + b}';

  // Underscore-prefixed identifier without braces — already correct form
  const _tag = 'TAG';
  final insecureBytes = <int>[];
  print('$_tag: Insecure bytes: ${insecureBytes.toString()}');
}

class Grid {
  final int width;
  final int height;
  final int bombCount;
  Grid(this.width, this.height, this.bombCount);
  // Braces required: '$widthh' and '$heightm' would read as wrong identifiers
  String toString() => 'w${width}h${height}m$bombCount';
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 