spec/scss_lint/linter/indentation_spec.rb in scss-lint-0.33.0 vs spec/scss_lint/linter/indentation_spec.rb in scss-lint-0.34.0

- old
+ new

@@ -1,252 +1,312 @@ require 'spec_helper' describe SCSSLint::Linter::Indentation do context 'when a line at the root level is indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } $var: 5px; $other: 10px; - CSS + SCSS it { should_not report_lint line: 1 } it { should report_lint line: 2 } end context 'when a line in a rule set is properly indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { margin: 0; } - CSS + SCSS it { should_not report_lint } end context 'when lines in a rule set are not properly indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { margin: 0; padding: 1em; opacity: 0.5; } - CSS + SCSS it { should report_lint line: 2 } it { should_not report_lint line: 3 } it { should report_lint line: 4 } end context 'when selector of a nested rule set is not properly indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { em { font-style: italic; } } - CSS + SCSS it { should report_lint line: 2 } it { should_not report_lint line: 3 } it { should_not report_lint line: 4 } end context 'when multi-line selector of a nested rule set is not properly indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { b, em, i { font-style: italic; } } - CSS + SCSS it { should report_lint line: 2 } it { should_not report_lint line: 3 } it { should_not report_lint line: 4 } it { should_not report_lint line: 5 } end context 'when a property is on the same line as its rule selector' do - let(:css) { 'h1 { margin: 5px; }' } + let(:scss) { 'h1 { margin: 5px; }' } it { should_not report_lint } end context 'when an argument list spans multiple lines' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } @include mixin(one, two, three); - CSS + SCSS it { should_not report_lint } end context 'when an argument list of an improperly indented script spans multiple lines' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { @include mixin(one, two, three); } - CSS + SCSS it { should report_lint line: 2 } it { should_not report_lint line: 3 } it { should_not report_lint line: 4 } end context 'when an if statement is incorrectly indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } $condition: true; @if $condition { padding: 0; } - CSS + SCSS it { should report_lint line: 2 } end context 'when an if statement is accompanied by a correctly indented else statement' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } @if $condition { padding: 0; } @else { margin: 0; } - CSS + SCSS it { should_not report_lint } end context 'when @at-root directive contains correctly indented children' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } .block { @at-root { .something {} } } - CSS + SCSS it { should_not report_lint } end context 'when @at-root directive with an inline selector contains correctly indented children' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } .block { @at-root .something { .something-else {} } } - CSS + SCSS it { should_not report_lint } end context 'when @at-root directive with no inline selector contains comment' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } @at-root { // A comment that causes a crash .something-else {} } - CSS + SCSS it { should_not report_lint } end context 'when the indentation width has been explicitly set' do let(:linter_config) { { 'width' => 3 } } - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { margin: 0; padding: 5px; } - CSS + SCSS it { should report_lint line: 2 } it { should_not report_lint line: 3 } end context 'when there are selectors across multiple lines' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } .class1, .class2 { margin: 0; padding: 5px; } - CSS + SCSS it { should_not report_lint } end context 'when there are selectors across multiple lines with a single line block' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } .class1, .class2 { margin: 0; } - CSS + SCSS it { should_not report_lint } end context 'when a comment node precedes a node' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } // A comment $var: 1; - CSS + SCSS it { should_not report_lint } end context 'when a line is indented with tabs' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { \tmargin: 0; } - CSS + SCSS it { should report_lint line: 2 } end context 'when a line contains a mix of tabs and spaces' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { \tmargin: 0; } - CSS + SCSS it { should report_lint line: 2 } end context 'when tabs are preferred' do let(:linter_config) { { 'character' => 'tab', 'width' => 1 } } context 'and the line is indented correctly' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { \tmargin: 0; } - CSS + SCSS it { should_not report_lint } end context 'and the line is incorrectly indented' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { \t\tmargin: 0; } - CSS + SCSS it { should report_lint line: 2 } end context 'and the line is indented with spaces' do - let(:css) { <<-CSS } + let(:scss) { <<-SCSS } p { margin: 0; } - CSS + SCSS + + it { should report_lint line: 2 } + end + end + + context 'when indentation in non-nested code is allowed' do + let(:linter_config) do + { 'allow_non_nested_indentation' => true, + 'character' => 'space', + 'width' => 2, + } + end + + context 'and non-nested code is indented' do + let(:scss) { <<-SCSS } + .component {} + .component__image {} + .component__text {} + .component-subblock {} + .component-subblock__text {} + .component-category {} + .component-other {} + SCSS + + it { should_not report_lint } + end + + context 'and nested code is indented too much' do + let(:scss) { <<-SCSS } + .component { + .component__image {} + .component__text {} + .component-subblock {} + } + SCSS + + it { should_not report_lint line: 2 } + it { should_not report_lint line: 3 } + it { should report_lint line: 4 } + end + + context 'and nested code is indented too little' do + let(:scss) { <<-SCSS } + .component { + .component__image {} + .component__text {} + .component-subblock {} + } + SCSS + + it { should_not report_lint line: 2 } + it { should_not report_lint line: 3 } + 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 end end