postcss-scss icon indicating copy to clipboard operation
postcss-scss copied to clipboard

Parse multiline silent comments as unified blocks

Open nex3 opened this issue 5 years ago • 3 comments

Currently this package parses each line of a silent //-style comment as a separate Comment object. In practice, users usually think of comments on adjacent lines as part of a single block, so it would be useful if this parser represented them as a single comment object. This would make downstream processing like documentation generation or https://github.com/stylelint/stylelint/issues/4886 easier as well.

Note: Dart Sass also internally represents adjacent (block-level) silent comment lines as a single object, so you can look to its parsing logic for inspiration.

nex3 avatar Aug 10 '20 21:08 nex3

Yeap. It will be a nice feature.

PR is welcome since after PostCSS 8 release I will busy with Browserslist.

ai avatar Aug 10 '20 21:08 ai

I think proposed change would be unfortunate for tools, which use control comments (stylelint, Autoprefixer, Prettier, etc).

In CSS we have 3 separate comment:

/* a */
/* stylelint-disable */
/* b */

If we convert them to Sass:

// a
// stylelint-disable
// b

And then back to CSS (virtually, it just easier to understand what grouping of comments would do in postcss-scss):

/* a
stylelint-disable
b */

This is completely different thing, which is not important for Sass compiler, but is important for other tools. All these tools would need to change their code to parse every comment if there a line which starts with control words, etc.

hudochenkov avatar Sep 14 '20 20:09 hudochenkov

It's specifically for stylelint that we're trying to add this. I'd expect an inline comment that's intended to be a distinct chunk of text from another adjacent inline comment to be separated by an empty line.

nex3 avatar Sep 14 '20 22:09 nex3