prefer_ double_ quotes
Learn about the prefer_double_quotes linter rule.
Prefer double quotes where they won't require escape sequences.
Details
#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:
useStrings(
'should be double quote',
r'should be double quote',
r\'''should be double quotes\''')
GOOD:
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'}");
Incompatible rules
#
The prefer_double_quotes lint is incompatible
with the following rules:
Enable
#
To enable the prefer_double_quotes rule, add
prefer_double_quotes under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- prefer_double_quotes
If you're instead using the YAML map syntax to configure
linter rules, add
prefer_double_quotes: true under
linter > rules:
linter:
rules:
prefer_double_quotes: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.