目录

prefer_double_quotes

Prefer double quotes where they won't require escape sequences.

此规则自 Dart 2.4 版本起可用。

此规则提供 快速修复

_不兼容规则:prefer_single_quotes _

详情

#

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

That means strings with a double quote may use apostrophes so that the double quote isn't escaped (note: we don't lint the other way around, ie, a double quoted string with an escaped double quote 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 single quote somewhere. So single 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
useStrings(
    'should be double quote',
    r'should be double quote',
    r\'''should be double quotes\''')

GOOD:

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

使用方法

#

要启用 prefer_double_quotes 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 prefer_double_quotes

analysis_options.yaml
yaml
linter:
  rules:
    - prefer_double_quotes