Skip to content

Commit

Permalink
Change Indentation arbitrary indentation rules for root nodes
Browse files Browse the repository at this point in the history
Previously we allowed only `RuleNode`s that were direct children of the
root node to be arbitrarily indented. Change this so that any node which
would normally have an indent of zero can be arbitrarily indented.
  • Loading branch information
sds committed Nov 23, 2015
1 parent fdd5cae commit 67c5fe5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
containing multiple sequences on a single line
* Fix `SpaceAfterVariableName` to not report lints for colons with spaces
inside map literals
* Change `Indentation` linter with `allow_non_nested_indentation` to allow
any node type to be arbitrarily indented as long as it a child of the root
document node (previously only rule set declarations were allowed)

## 0.42.2

Expand Down
19 changes: 8 additions & 11 deletions lib/scss_lint/linter/indentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,15 @@ def check_regular_indent(node, actual_indent)
def check_arbitrary_indent(node, actual_indent)
return if check_root_ruleset_indent(node, actual_indent)

if @indent == 0
unless node.is_a?(Sass::Tree::RuleNode) || actual_indent == 0
add_lint(node.line, lint_message(0, actual_indent))
return true
end
elsif !one_shift_greater_than_parent?(node, actual_indent)
parent_indent = node_indent(node_indent_parent(node)).length
expected_indent = parent_indent + @indent_width
# Allow any root-level node (i.e. one that would normally have an indent
# of zero) to have an arbitrary amount of indent
return if @indent == 0

add_lint(node.line, lint_message(expected_indent, actual_indent))
return true
end
return if one_shift_greater_than_parent?(node, actual_indent)
parent_indent = node_indent(node_indent_parent(node)).length
expected_indent = parent_indent + @indent_width
add_lint(node.line, lint_message(expected_indent, actual_indent))
true
end

# Allow rulesets to be indented any amount when the indent is zero, as long
Expand Down
10 changes: 1 addition & 9 deletions spec/scss_lint/linter/indentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
.component {}
.component__image {}
.component__text {}
$some-variable: 0;
.component-subblock {}
.component-subblock__text {}
.component-category {}
Expand Down Expand Up @@ -324,15 +325,6 @@
it { should report_lint line: 4 }
end

context 'and a non-nested non-ruleset is incorrectly indented' do
let(:scss) { <<-SCSS }
p {}
$var: one;
SCSS

it { should report_lint line: 2 }
end

context 'and a nested non-ruleset is correctly indented' do
let(:scss) { <<-SCSS }
.one {
Expand Down

0 comments on commit 67c5fe5

Please sign in to comment.