stylelint: Add ignoreBeforeAtRules: [] to block-closing-brace-newline-after

Clearly describe the bug

The block-closing-brace-newline-after rule has a neat ignoreAtRules option, which allows non-newline characters after an at-rule-associated }. The examples given are:

@if ($var) {
  color: pink;
} @else if ($var2) {
  color: red;
} @else {
  color: blue;
}
@if ($var) { color: pink; } @else { color: blue; }

This ignores too many violations. E.g. this also becomes considered clean code:

@if ($var) { color: pink; } p { margin: 2em; }

The ignoreAtRules option should only allow more at-rules after the } attached to an ignored at-rule. I can’t conceive of why one would allow a declaration after such an }, or a rule, etc. I think the option was written specifically to support Sass’s @if/@else.

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

block-closing-brace-newline-after

What CSS is needed to reproduce the bug?

@if ($var) { color: pink; } p { margin: 2em; }

What stylelint configuration is needed to reproduce the bug?

{
  "rules": {
    "block-closing-brace-newline-after": ["always", "ignoreAtRules": ["if", "else"]]
  }
}

Which version of stylelint are you using?

9.6.0

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

Node.js API using cli.js

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

Yes, it’s related to Sass nested properties.

What did you expect to happen?

block-closing-brace-newline-after to be flagged for the rule after the } associated with the @if.

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

No warnings were flagged.

If this is accepted as a bug, I can likely write a PR to fix it.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (18 by maintainers)

Most upvoted comments

@ermik Thanks for wanting to contribute

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

This is an example of a recent pull request to add an option to a rule.