leading-newlines-in-multiline-strings

Same as leading_newlines_in_multiline_strings in Dart lints

Group
Style
Path
lint/style/leading-newlines-in-multiline-strings
Default
Off, opt in
Origin
Dart lints
Rule
250 of 512

Flags a multiline string spanning several lines whose text does not start with a line break right after the opening quotes.

Starting the text on its own line keeps every line aligned at the same indentation, and Dart drops that first line break from the value:

var s1 = '''{
  "a": 1
}''';      // flagged
var s2 = '''
{
  "a": 1
}''';      // preferred

Triple-quoted literals that stay on one line are not flagged.

Invalid

example.dartdart
void use(Object o) {}

void main() {
  var name = 'Ann';
   use('''{
  "a": 1
}''');
   use("""first line
second line""");
   use(r'''raw first
raw second''');
   use('''$name
interpolated''');
   use('a' '''b
adjacent part''');
}
Add a newline at the beginning of this multiline string.
4 var name = 'Ann';
5 use('''{
Add a newline at the beginning of this multiline string.
7}''');
8 use("""first line
Add a newline at the beginning of this multiline string.
9second line""");
10 use(r'''raw first
Add a newline at the beginning of this multiline string.
11raw second''');
12 use('''$name
Add a newline at the beginning of this multiline string.
13interpolated''');
14 use('a' '''b

Valid

example.dartdart
void use(Object o) {}

void main() {
  var name = 'Ann';
  use('''
{
  "a": 1
}''');
  use('''single line''');
  use("""
second""");
  use(r'''
raw''');
  use('''
$name''');
  use('not multiline');
}

Configure leading-newlines-in-multiline-strings

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "leading-newlines-in-multiline-strings": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/style/leading-newlines-in-multiline-strings: <reason>
  • library-annotationslibrary_annotationsrecommended

    Requires library-targeted metadata to attach to a library directive.

  • library-nameslibrary_namesrecommended

    Flags a library name that is not lowercase_with_underscores.

  • library-prefixeslibrary_prefixesrecommended

    Flags import prefixes that are not lower_case_with_underscores.

  • lines-longer-than-80-charslines_longer_than_80_chars

    Flags source lines longer than 80 characters.

  • map-keys-ordering

    Flags literal string map keys that violate the configured order.

  • matching-super-parametersmatching_super_parameters

    Flags positional super parameters named differently from the super constructor's corresponding parameter.

  • member-orderingmember-ordering

    Flags class members declared out of the configured order.

  • missing-whitespace-between-adjacent-stringsmissing_whitespace_between_adjacent_stringsrecommended

    Flags adjacent string literals that join two words without a space between them.