Skip to content
This repository has been archived by the owner on Jan 17, 2018. It is now read-only.

Commit

Permalink
Fix TrailingSemicolon linter for @includes with blocks
Browse files Browse the repository at this point in the history
This fixes sds#198

A recent commit [1] generalized the TrailingSemicolon linter to also
check `@extend` and `@include`. This commit did not take into account
`@include`s with a block. @Steffen185 provided a simple repro case:

  $ cat test.scss
  body {
    @include foo {
      background: #f00;
    }
  }
  $ scss-lint test.scss
  test.scss:2 [W] TrailingSemicolon: Declaration should not have a space
  before the terminating semicolon

I took this case and added it to the spec for the TrailingSemicolon
linter. The fix included checking the `@include` for children, and in
such case continue checking children. There was already code for this
scenario for props, so I just refactored a bit to make use of the same
solution.

[1]: sds@58689b1d18c7449509168f

Change-Id: If8f178d7b36a048bb7c00e75b0738b9efe0530ed
Reviewed-on: http://gerrit.causes.com/40988
Tested-by: jenkins <[email protected]>
Reviewed-by: Shane da Silva <[email protected]>
  • Loading branch information
Henric Trotzig authored and trotzig committed Jul 28, 2014
1 parent 7cca882 commit b4e70aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/scss_lint/linter/trailing_semicolon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ module SCSSLint
class Linter::TrailingSemicolon < Linter
include LinterRegistry

def visit_prop(node)
if has_nested_properties?(node)
yield # Continue checking children
else
check_semicolon(node)
end
end

def visit_extend(node)
check_semicolon(node)
end

def visit_mixin(node)
def visit_variable(node)
check_semicolon(node)
end

def visit_variable(node)
check_semicolon(node)
def visit_possible_parent(node)
if has_nested_properties?(node)
yield # Continue checking children
else
check_semicolon(node)
end
end

alias_method :visit_mixin, :visit_possible_parent
alias_method :visit_prop, :visit_possible_parent

private

def has_nested_properties?(node)
Expand Down
12 changes: 12 additions & 0 deletions spec/scss_lint/linter/trailing_semicolon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@
it { should report_lint line: 2 }
end

context 'when @include takes a block' do
let(:css) { <<-CSS }
.foo {
@include bar {
border: 0;
}
}
CSS

it { should_not report_lint }
end

context 'when @extend ends with a semicolon' do
let(:css) { <<-CSS }
.foo {
Expand Down

0 comments on commit b4e70aa

Please sign in to comment.