unnecessary-raw-strings

Same as unnecessary_raw_strings in Dart lints

Group
Style
Path
lint/style/unnecessary-raw-strings
Default
On (recommended)
Origin
Dart lints
Rule
471 of 512
recommended

Flags raw string literals that contain no backslash or $.

A raw string only differs from a regular one when its text holds \ or $; otherwise the r prefix is noise:

var s1 = r'a b c';  // flagged
var s2 = 'a b c';   // preferred
var s3 = r'a \ b';  // fine: the backslash stays literal

Each part of an adjacent-string concatenation is checked on its own.

Invalid

example.dartdart
void use(Object o) {}

void main() {
  use(r'plain');
  use(r"double plain");
  use(r'''multi''');
  use(r'');
  use('ok' r'plain part');
}
Remove the unnecessary raw string prefix.
3void main() {
4 use(r'plain');
Remove the unnecessary raw string prefix.
4 use(r'plain');
5 use(r"double plain");
Remove the unnecessary raw string prefix.
5 use(r"double plain");
6 use(r'''multi''');
Remove the unnecessary raw string prefix.
6 use(r'''multi''');
7 use(r'');
Remove the unnecessary raw string prefix.
7 use(r'');
8 use('ok' r'plain part');

Valid

example.dartdart
void use(Object o) {}

void main() {
  use(r'a \ b');
  use(r'cost $5');
  use(r'\d+');
  use(r'''multi \n''');
  use('plain');
  use(r'$' 'plain');
}

Configure unnecessary-raw-strings

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

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

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

example.dartdart
// falcon-ignore lint/style/unnecessary-raw-strings: <reason>
  • unnecessary-string-escapesunnecessary_string_escapesrecommended

    Flags backslashes that do not affect a string's value.

  • unnecessary-string-interpolationsunnecessary_string_interpolationsrecommended

    Flags a string literal whose entire content is a single interpolation of a provably non-nullable String.

  • unnecessary-thisunnecessary_thisrecommended

    Flags a redundant this. qualifier on member access.

  • unreachable-from-mainunreachable_from_main

    Report public declarations that no entry point of an executable library reaches.

  • use-colored-boxuse_colored_boxrecommendedflutter

    Prefers ColoredBox over a Container that only paints a color behind its child.

  • use-decorated-boxuse_decorated_boxrecommendedflutter

    Prefers DecoratedBox over a Container that only decorates its child.

  • use-design-system-itemuse-design-system-itemflutter

    Flags construction of a widget or type that should be replaced by its design-system equivalent.

  • use-enumsuse_enums

    Flags classes that emulate an enum and could be declared as one.