Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint for loud comments on nested style rules #893

Open
Goodwine opened this issue Dec 6, 2023 · 4 comments
Open

Add lint for loud comments on nested style rules #893

Goodwine opened this issue Dec 6, 2023 · 4 comments

Comments

@Goodwine
Copy link

Goodwine commented Dec 6, 2023

Input

.foo {
  /* Hello! */
  .bar {
    a: b;
  }
}

Output (playground)

.foo {
  /* Hello! */      <------ Issue: User expected comment to appear above `.foo .bar`.
}
.foo .bar {
  a: b;
}

Context

Sass loud comments (/* */) within a rule declaration are not "connected" to anything. They don't "belong" to the subsequent node. So when Sass compiles nested comments and rules to CSS, it "splits" the loud comment away from the nested rule block that the author intended, as shown in the example above.

This could cause issues for libraries like Autoprefixer or RTLCSS that depend on these "loud comments" being positioned at the top of a specific line or block. For instance:

.foo {
  /* rtl:ignore */
  .bar {
    a: b;
  }

  float: left;
}

Which produces:

.foo {
  /* rtl:ignore */
  float: left;      <----- BUG: This is now ignored by RTLCSS, but that wasn't intended.
}
.foo .bar {
  a: b;
}
@Goodwine
Copy link
Author

Goodwine commented Dec 6, 2023

BTW I'm looking to work on this this week unless :)

@kristerkari
Copy link
Collaborator

kristerkari commented Dec 8, 2023

@Goodwine Thanks for the detailed description!

Looking at what you wrote, I started wondering if the problem is maybe a bit too specific to RTLCSS to be added as a rule to this library. I understand that your problem is related to Sass, but I bet that most of the users of stylelint-scss are not using RTLCSS.

Could this idea instead be turned into a separate stylelint plugin that would be published in npm? Stylelint supports the postcss-scss customSyntax, so it's really easy to make a rule support SCSS.

@Goodwine
Copy link
Author

Since this affects any loud comment (not just RTLCSS), would it make sense to still implement this lint check as part of this repo if it was made more generic?

For example:

  • check: Any loud comment that appears immediately before a nested style-rule or at-rule
  • finding text: "A loud comment (/**/) over a nested rule does not follow the rule when Sass compiles to CSS. Use a quiet comment (//) or unnest the rule." (or better wording)
  • auto-fix: transforms to quiet comment

@Goodwine Goodwine changed the title Add lint for rtl:ignore comment directives on nested style rules Add lint for loud comments on nested style rules Sep 9, 2024
@Goodwine
Copy link
Author

Goodwine commented Sep 9, 2024

I have updated the description of the issue to be more generic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants