use-raw-strings

Same as use_raw_strings in Dart lints

Group
Style
Path
lint/style/use-raw-strings
Default
Off, opt in
Origin
Dart lints
Rule
498 of 512

Flags string literals whose only escapes are \\ and \$, which a raw string would express without any backslash.

var s = 'A string with only \\ and \$'; // flagged
var s = r'A string with only \ and $';  // preferred
var s = 'tab\there \$';                 // fine: `\t` needs a regular string

Interpolated literals are not checked, since a raw string cannot interpolate. Each part of an adjacent-string concatenation is checked on its own.

Invalid

example.dartdart
void use(Object o) {}

void main() {
  use('A string with only \\ and \$');
  use('C:\\Users');
  use("costs \$5");
  use('''multi \\ line''');
  use('ok' 'part \\');
}
Use a raw string to avoid using escapes.
3void main() {
4 use('A string with only \\ and \$');
Use a raw string to avoid using escapes.
4 use('A string with only \\ and \$');
5 use('C:\\Users');
Use a raw string to avoid using escapes.
5 use('C:\\Users');
6 use("costs \$5");
Use a raw string to avoid using escapes.
6 use("costs \$5");
7 use('''multi \\ line''');
Use a raw string to avoid using escapes.
7 use('''multi \\ line''');
8 use('ok' 'part \\');

Valid

example.dartdart
void use(Object o) {}

void main() {
  var x = 1;
  use(r'A string with only \ and $');
  use('tab\there \$');
  use('it\'s');
  use('no escapes');
  use('\\ and $x');
  use('\n');
}

Configure use-raw-strings

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "use-raw-strings": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/use-raw-strings: <reason>