stylelint: Fix false positives for escaped multi-line in `string-no-newline`

Clearly describe the bug

I want to split large strings for aesthetic reasons with enabled string-no-newline rule.

There is the quote from the specs, including:

And also: “It is possible to break strings over several lines, for aesthetic or other reasons, but in such a case the newline itself has to be escaped with a backslash ().”

But for some reason escaped newlines are forbidden in Stylelint.

Which rule, if any, is the bug related to?

string-no-newline

What CSS is needed to reproduce the bug?

background-image: url(
  "data:image/svg+xml;utf8,\
  <svg fill='black' height='24' \
    viewBox='0 0 24 24' width='24' \
    xmlns='http://www.w3.org/2000/svg'\
  ><path d='M7 9l5 5 5-5z'/></svg>"
);

What stylelint configuration is needed to reproduce the bug?

extends: stylelint-config-standard

Which version of stylelint are you using?

9.10.1

How are you running stylelint: CLI, PostCSS plugin, Node.js API?

CLI with stylelint assets/styles/.

Does the bug relate to non-standard syntax (e.g. SCSS, Less etc.)?

No.

What did you expect to happen?

No warnings to be flagged.

What actually happened (e.g. what warnings or errors did you get)?

The following warnings were flagged:

 116:197  ✖  Expected line length to be no more than 80 characters                                               max-line-length

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 19 (9 by maintainers)

Most upvoted comments

@Gitoffthelawn please refrain making this thread longer with off topic questions 😃 There are a lot of people in this thread and they all get notifications and/or emails each time you post something. This causes a lot of noise.

There is also a playground at openstyles/stylelint-bundle: https://raw.githack.com/openstyles/stylelint-bundle/master/demo/index.html

This definitely is not a PostCSS issue 😃 I checked it multiple times.


I wasn’t aware of this issue otherwise I would have submitted a patch here earlier. Thank you for pinging me here @rgpublic


Worth noting that the tests for this aspect are currently incorrect: https://github.com/stylelint/stylelint/blob/cb3a7f8d5e89f2e467a4166293c17d3c2d1e72cc/lib/rules/string-no-newline/__tests__/index.mjs#L16-L18

This only has \\n which is an escaped newline. What it should be instead is \\\n -> an escaped backslash and a newline.

Because the test is incorrect the actual rule also has bugs because it is testing the wrong things.


Luckily this is something that I have already fixed by writing a spec compliant tokenizer 😄 The spec has a very specific branch and error for this case.

So we can simply passthrough the tokenizer error to the stylelint report.

I’ll submit a patch later today.

I couldn’t say @Gitoffthelawn without a reproduction 😃

If the issue is still present after everything has been released and updated you should open a new issue, then we can investigate further.