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

Add a validator to force an empty line before and after a block

Open astronati opened this issue 8 years ago • 5 comments

Expected behaviour The linter should inform developer if there are missing empty lines before and after a block.

Bad

.classname {
  text-transform: uppercase;
  .child {
    text-align: center;
  }
}

Good

.classname {
  text-transform: uppercase;

  .child {
    text-align: center;
  }

}

astronati avatar Oct 07 '16 09:10 astronati

Would this be different from the EmptyLineBetweenBlocks linter?

abea avatar Oct 07 '16 15:10 abea

An other blank line is added after the block not only before. When you have a lot of block within your scss file, adding a blank line after each of them helps to read better the code

astronati avatar Oct 07 '16 15:10 astronati

I never saw the benefit of having an empty line after the last child element. Doesn't seem to be a convention afaik.

wouter-muller avatar Oct 11 '16 12:10 wouter-muller

The validator would allow to do this:

.#{$namespace}list-table {
  @include list-table($namespace);

  .#{$namespace}list-table-body {

    .#{$namespace}list-table-row {

      .#{$namespace}list-table-cell {
        border-top: 0.0625rem solid;
      }

    }

  }

}

Instead of this that IMHO is harder to read even to figure out where is the } of the list-table-row:

.#{$namespace}list-table {
  @include list-table($namespace);

  .#{$namespace}list-table-body {
    .#{$namespace}list-table-row {
      .#{$namespace}list-table-cell {
        border-top: 0.0625rem solid;
      }
    }
  }
}

astronati avatar Oct 11 '16 14:10 astronati

While this convention is certainly a bit out of the ordinary (I've never seen a codebase that enforced spacing after a block), I am happy to accept a pull request with tests adding support for this to EmptyLineBetweenBlocks via some configuration option (for example, empty_line_before_and_after). Thanks!

sds avatar Oct 13 '16 06:10 sds