prefer-single-quotes
Same as prefer_single_quotes in Dart lints
- Group
- Style
- Path
lint/style/prefer-single-quotes- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 405 of 512
Flags double-quoted string literals that could use single quotes without needing an escape.
Only use double quotes for strings whose text contains a single quote:
useStrings("should be single quote", r"should be single quote"); // flagged
useStrings('should be single quote', "it's fine"); // fine
Raw and multiline literals are checked too. An interpolated literal is left alone when an interpolated expression contains another string literal, and a literal nested inside another literal's interpolation is never flagged, since swapping the quotes there would clash with the outer delimiters. Each part of an adjacent-string concatenation is checked on its own.
Invalid
void use(Object o) {}
void main() {
var name = 'Ann';
use("double");
use(r"raw double");
use("hello $name");
use("""multiline""");
use('single' "double");
use("${name.length} chars");
} var name = 'Ann'; use("double"); use("double"); use(r"raw double"); use(r"raw double"); use("hello $name"); use("hello $name"); use("""multiline"""); use("""multiline"""); use('single' "double"); use('single' "double"); use("${name.length} chars");Valid
import 'dart:core';
void use(Object o) {}
void main() {
var name = 'Ann';
use('single');
use("it's");
use("it\'s escaped");
use("Hello ${name.isEmpty ? 'x' : 'y'}");
use('outer ${"nested"}');
use('a ${"b ${"c"}"} d ${"e"}');
use("contains '$name'");
use(r'raw');
}
void patternStrings(Object value) {
switch (value) {
case 'a${"b"}':
case 'a${"b ${"c"}"}':
break;
}
}Configure prefer-single-quotes
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-single-quotes": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-single-quotes: <reason>More style rules
- prefer-sized-box-squareflutter
Prefers SizedBox.square for an unnamed Flutter
SizedBoxwhose explicit width and height are stable variable reads or numeric literals with identical token spelling. - prefer-spread-collections
prefer_spread_collectionsrecommendedFlags an
addAllcascade on a collection literal that a spread would express. - prefer-switch-expression
Prefer switch expressions for exhaustive switches that only return or assign a value.
- prefer-test-matcherstest
Recommends Matcher expectations and direct type, equality, or ordering matchers.
- prefer-trailing-comma
prefer-trailing-commaFlags multi-line argument lists that are missing a trailing comma.
- prefer-transform-over-containerflutter
Prefers
Transformover aContainerused only fortransform. - prefer-type-over-var
Prefer explicit types over
varin ordinary variable declarations. - prefer-typing-uninitialized-variables
prefer_typing_uninitialized_variablesrecommendedFlags uninitialized variables declared without a type annotation.