# prefer_single_quotes

Stable

Fix available

Only use double quotes for strings containing single quotes.

DO use single quotes where they wouldn't require additional escapes.

That means strings with an apostrophe may use double quotes so that the apostrophe isn't escaped (note: we don't lint the other way around, ie, a single quoted string with an escaped apostrophe is not flagged).

It's also rare, but possible, to have strings within string interpolations. In this case, it's much more readable to use a double quote somewhere. So double quotes are allowed either within, or containing, an interpolated string literal. Arguably strings within string interpolations should be its own type of lint.

**BAD:**

dart

```dart
useStrings(
    "should be single quote",
    r"should be single quote",
    r"""should be single quotes""")
```

**GOOD:**

dart

```dart
useStrings(
    'should be single quote',
    r'should be single quote',
    r\'''should be single quotes\''',
    "here's ok",
    "nested \${a ? 'strings' : 'can'} be wrapped by a double quote",
    'and nested \${a ? "strings" : "can be double quoted themselves"}');
```

The `prefer_single_quotes` lint is incompatible with the following rules:

- `prefer_double_quotes`

To enable the `prefer_single_quotes` rule, add `prefer_single_quotes` under **linter > rules** in your `analysis_options.yaml` file:

analysis_options.yaml

yaml

```yaml
linter:
  rules:
    - prefer_single_quotes
```

If you're instead using the YAML map syntax to configure linter rules, add `prefer_single_quotes: true` under **linter > rules**:

analysis_options.yaml

yaml

```yaml
linter:
  rules:
    prefer_single_quotes: true
```

Was this page's content helpful?

Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.

# prefer_single_quotes

## Details

## Incompatible rules

## Enable