dart_style icon indicating copy to clipboard operation
dart_style copied to clipboard

Alignment with multiple adjacent strings

Open alan-knight opened this issue 11 years ago • 2 comments

This doesn't seem right. I'd expect the two later literal strings to be indented relative to the named argument. Or better yet, all 3 of the adjacent strings on separate lines, indented relative to the named arguments.

  method() => Intl.message("This comes from a method",
       name: 'method', desc: 'This is a method with a '
       'long description which spans '
       'multiple lines.');

alan-knight avatar Feb 25 '15 23:02 alan-knight

Another example.

      testHtml('DOM clobbering of attributes with multiple nodes', validator,
          "<form onmouseover='alert(1)'><input name='attributes'>"
          "<input name='attributes'>", "");

It's very unclear from this formatting that the last two arguments are two strings, the first the concatenation of two long adjacent strings and the second one empty. I'd prefer to have the second string on its own line, but even then it would seem confusing to have

   testHtml('DOM clobbering of attributes with multiple nodes', validator,
        "<form onmouseover='alert(1)'><input name='attributes'>"
        "<input name='attributes'>", 
        "");

I think I'd rather have subsequent lines of the adjacent string be indented.

alan-knight avatar Apr 01 '15 18:04 alan-knight

Aligning relative to a named argument only works well with short argument names. In the case of long argument names it can look really bad.

natebosch avatar Mar 06 '19 06:03 natebosch

In the forthcoming tall style, this code gets formatted as:

  method() => Intl.message(
    "This comes from a method",
    name: 'method',
    desc:
        'This is a method with a '
        'long description which spans '
        'multiple lines.',
  );

And:

      testHtml(
        'DOM clobbering of attributes with multiple nodes',
        validator,
        "<form onmouseover='alert(1)'><input name='attributes'>"
            "<input name='attributes'>",
        "",
      );

I think these both do a good job of making the argument lists clearer (obviously at the expense of more vertical height, hence the name "tall" style).

munificent avatar Aug 02 '24 00:08 munificent