prefer_double_quotes
在不需要轉義序列的情況下,優先使用雙引號。
詳情
#在不需要額外轉義的情況下,**請**使用雙引號。
這意味著包含雙引號的字串可以使用單引號,這樣雙引號就不需要轉義了(注意:我們不會對反向情況進行 lint 檢查,即,包含轉義雙引號的雙引號字串不會被標記)。
在字串插值中包含字串的情況很少見,但並非不可能。在這種情況下,在某處使用單引號會更具可讀性。因此,在插值字串字面量內部或包含插值字串字面量時,允許使用單引號。可以說,字串插值內的字串應該作為其自己的一種 lint 規則。
不好
dart
useStrings(
'should be double quote',
r'should be double quote',
r\'''should be double quotes\''')好
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 規則與以下規則不相容
啟用
#要啟用 prefer_double_quotes 規則,請在您的 analysis_options.yaml 檔案中的 linter > rules 下新增 prefer_double_quotes
analysis_options.yaml
yaml
linter:
rules:
- prefer_double_quotes如果您改為使用 YAML map 語法配置 linter 規則,請在 linter > rules 下新增 prefer_double_quotes: true
analysis_options.yaml
yaml
linter:
rules:
prefer_double_quotes: true