unnecessary-string-escapes
Same as unnecessary_string_escapes in Dart lints
- Group
- Style
- Path
lint/style/unnecessary-string-escapes- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 473 of 512
Flags backslashes that do not affect a string's value.
Raw strings are exempt. In triple-quoted strings, escaping the delimiter quote is only necessary in runs of three quotes or at the closing delimiter.
Invalid
// Bad: backslash escapes that do nothing in the given string context.
void examples() {
final a = "\'";
final b = '\"';
final c = '\a';
final d = 'x\dy';
final e = "50\%";
final f = '\-';
print([a, b, c, d, e, f]);
print('''one\'quote''');
print("""one\"quote""");
print('''opposite\"quote''');
print('''unknown\q''');
print('''$a\'quote''');
print('''\'$a''');
print('''\' 'end''');
}void examples() { final a = "\'"; final a = "\'"; final b = '\"'; final b = '\"'; final c = '\a'; final c = '\a'; final d = 'x\dy'; final d = 'x\dy'; final e = "50\%"; final e = "50\%"; final f = '\-'; print([a, b, c, d, e, f]); print('''one\'quote'''); print('''one\'quote'''); print("""one\"quote"""); print("""one\"quote"""); print('''opposite\"quote'''); print('''opposite\"quote'''); print('''unknown\q'''); print('''unknown\q'''); print('''$a\'quote'''); print('''$a\'quote'''); print('''\'$a'''); print('''\'$a'''); print('''\' 'end''');Valid
// Good: every backslash escape is meaningful (or the string is raw).
void examples() {
final a = 'it\'s'; // escaping the delimiter quote is required
final b = "she said \"hi\""; // escaping the delimiter quote is required
final c = 'line1\nline2'; // \n is a newline
final d = 'tab\there'; // \t is a tab
final e = 'cost: \$5'; // \$ escapes interpolation
final f = 'back\\slash'; // \\ is a literal backslash
final g = r'\d+\w*'; // raw string — backslashes are literal, never flagged
final h = 'emoji \u{1F600}'; // \u is a unicode escape
final i = 'plain text';
print([a, b, c, d, e, f, g, h, i]);
print('''three\'\'\'quotes''');
print('''two''\'quotes''');
print('''closing\'''');
print("""closing\"""");
print('''escaped\\backslash\nnewline''');
print(r'''raw\q\'quotes''');
print('''${"nested"}''');
}Configure unnecessary-string-escapes
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"unnecessary-string-escapes": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/unnecessary-string-escapes: <reason>More style rules
- unnecessary-string-interpolations
unnecessary_string_interpolationsrecommendedFlags a string literal whose entire content is a single interpolation of a provably non-nullable
String. - unnecessary-this
unnecessary_thisrecommendedFlags a redundant
this.qualifier on member access. - unreachable-from-main
unreachable_from_mainReport public declarations that no entry point of an executable library reaches.
- use-colored-box
use_colored_boxrecommendedflutterPrefers
ColoredBoxover aContainerthat only paints a color behind its child. - use-decorated-box
use_decorated_boxrecommendedflutterPrefers
DecoratedBoxover aContainerthat only decorates its child. - use-design-system-item
use-design-system-itemflutterFlags construction of a widget or type that should be replaced by its design-system equivalent.
- use-enums
use_enumsFlags classes that emulate an enum and could be declared as one.
- use-existing-destructuring
Reuse or extend an existing record destructuring instead of rereading a field.