The Wayback Machine - https://web.archive.org/web/20211228090746/https://github.com/stylelint/stylelint/issues/5262
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 ignore: ["rules"] / ["at-rules"] to block-opening-brace-*-after #5262

Open
SandwichTech opened this issue Apr 26, 2021 · 4 comments
Open

Add ignore: ["rules"] / ["at-rules"] to block-opening-brace-*-after #5262

SandwichTech opened this issue Apr 26, 2021 · 4 comments

Comments

@SandwichTech
Copy link

@SandwichTech SandwichTech commented Apr 26, 2021

When using single-line formatting, it would helpful if the selectors for at-rules could pushed to a new line. For example:

.container { padding: 0; margin: 5px }
@media (min-width: 992px) {
    .container { padding: 5px; margin: 0 }}

A proposed solution would be to add at-rule exceptions for the block-opening-brace-newline-after rule. Or a separate at-rule-opening-brace-newline-after rule might be simpler.

@jeddy3
Copy link
Member

@jeddy3 jeddy3 commented Apr 27, 2021

@SandwichTech Thanks for the request.

To confirm, you'd like:

  • all rule-sets to be on a single line (regardless of how declarations they contain)
  • all at-rules to be on multiple lines

Is that correct?

If so, we can add ignore options to the block-opening-brace-*-after rules:

  • ignore: ["rules"] to block-opening-brace-newline-after
  • ignore: ["at-rules"] to block-opening-brace-space-after

You'd then be able to configure the rules like so:

{
  "rules": {
    "block-opening-brace-newline-after": ["always", { "ignore": ["rules"] } ],
    "block-opening-brace-space-after": ["always", { "ignore": ["at-rules"] } ],
  }
}

@SandwichTech
Copy link
Author

@SandwichTech SandwichTech commented Apr 28, 2021

@jeddy3 I appreciate the quick response.

  1. Yes, declarations are all on one line. However, there is a newline after commas between selectors ('selector-list-comma-newline-after': 'always')
  2. Yes, all at-rules are multi-line.

@jeddy3 jeddy3 changed the title Newline after at-rule opening brace Add ignore: ["rules"] / ["at-rules"] to block-opening-brace-*-after Apr 28, 2021
@jeddy3
Copy link
Member

@jeddy3 jeddy3 commented Apr 28, 2021

Those options should be what you need then.

It should just be the case of wrapping this line in a conditional:

Like so:

if (!optionsMatches(options, 'ignore', 'rules') {
  root.walkRules(check); 
}

And updating the options validator (see a similar rule to how this is done).

Then doing the same for the other rule, but ignoring at-rules instead of rules.

I've labelled the issue as ready to implement. Please consider contributing if you have time.

There are steps on how to add a new option in the Developer guide.

@RhnSharma
Copy link

@RhnSharma RhnSharma commented May 16, 2021

I would like to take this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants