Search code examples
cssstylelint

How to make stylelint prevent an empty line after the last brace in a nested block?


Which configuration settings are required to get this output:

.namespace {
   .title {}

   .item {}
}

I found a configuration for the empty line between the blocks, but nothing about preventing the last empty line in a nested block.

.namespace {
   .title {}
   --- rule-nested-empty-line-before ---
   .item {}
   --- But this empty line should throw a warning ---
}

Solution

  • The block-closing-brace-empty-line-before rule was added in [email protected]. You can disallow or allow an empty line before the closing brace of a block using this rule.

    As you wish to disallow an empty line, you should use the "never" primary option e.g.

    "block-closing-brace-empty-line-before": "never"
    

    This will enforce the following code style:

    .namespace {
      .item {}
    }