scss-lint 0.33.0 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +19 -1
- data/data/properties.txt +4 -0
- data/lib/scss_lint.rb +1 -0
- data/lib/scss_lint/cli.rb +4 -42
- data/lib/scss_lint/config.rb +1 -45
- data/lib/scss_lint/control_comment_processor.rb +47 -15
- data/lib/scss_lint/file_finder.rb +57 -0
- data/lib/scss_lint/linter/bang_format.rb +1 -1
- data/lib/scss_lint/linter/border_zero.rb +25 -9
- data/lib/scss_lint/linter/color_keyword.rb +3 -13
- data/lib/scss_lint/linter/color_variable.rb +36 -0
- data/lib/scss_lint/linter/declaration_order.rb +2 -2
- data/lib/scss_lint/linter/important_rule.rb +12 -0
- data/lib/scss_lint/linter/indentation.rb +7 -1
- data/lib/scss_lint/linter/property_count.rb +44 -0
- data/lib/scss_lint/linter/property_sort_order.rb +73 -19
- data/lib/scss_lint/linter/string_quotes.rb +9 -0
- data/lib/scss_lint/linter/variable_for_property.rb +20 -0
- data/lib/scss_lint/linter/vendor_prefixes.rb +3 -3
- data/lib/scss_lint/runner.rb +5 -7
- data/lib/scss_lint/utils.rb +34 -0
- data/lib/scss_lint/version.rb +1 -1
- data/spec/scss_lint/cli_spec.rb +1 -1
- data/spec/scss_lint/config_spec.rb +4 -203
- data/spec/scss_lint/engine_spec.rb +4 -4
- data/spec/scss_lint/file_finder_spec.rb +110 -0
- data/spec/scss_lint/linter/bang_format_spec.rb +28 -18
- data/spec/scss_lint/linter/border_zero_spec.rb +50 -16
- data/spec/scss_lint/linter/color_keyword_spec.rb +16 -16
- data/spec/scss_lint/linter/color_variable_spec.rb +102 -0
- data/spec/scss_lint/linter/comment_spec.rb +9 -9
- data/spec/scss_lint/linter/compass/property_with_mixin_spec.rb +10 -10
- data/spec/scss_lint/linter/debug_statement_spec.rb +4 -4
- data/spec/scss_lint/linter/declaration_order_spec.rb +80 -80
- data/spec/scss_lint/linter/duplicate_property_spec.rb +30 -30
- data/spec/scss_lint/linter/else_placement_spec.rb +16 -16
- data/spec/scss_lint/linter/empty_line_between_blocks_spec.rb +38 -38
- data/spec/scss_lint/linter/empty_rule_spec.rb +4 -4
- data/spec/scss_lint/linter/final_newline_spec.rb +6 -6
- data/spec/scss_lint/linter/hex_length_spec.rb +16 -16
- data/spec/scss_lint/linter/hex_notation_spec.rb +16 -16
- data/spec/scss_lint/linter/hex_validation_spec.rb +6 -6
- data/spec/scss_lint/linter/id_selector_spec.rb +10 -10
- data/spec/scss_lint/linter/import_path_spec.rb +45 -45
- data/spec/scss_lint/linter/important_rule_spec.rb +43 -0
- data/spec/scss_lint/linter/indentation_spec.rb +103 -43
- data/spec/scss_lint/linter/leading_zero_spec.rb +45 -45
- data/spec/scss_lint/linter/mergeable_selector_spec.rb +32 -32
- data/spec/scss_lint/linter/name_format_spec.rb +75 -41
- data/spec/scss_lint/linter/nesting_depth_spec.rb +14 -14
- data/spec/scss_lint/linter/placeholder_in_extend_spec.rb +12 -12
- data/spec/scss_lint/linter/property_count_spec.rb +104 -0
- data/spec/scss_lint/linter/property_sort_order_spec.rb +138 -48
- data/spec/scss_lint/linter/property_spelling_spec.rb +14 -14
- data/spec/scss_lint/linter/qualifying_element_spec.rb +26 -26
- data/spec/scss_lint/linter/selector_depth_spec.rb +26 -26
- data/spec/scss_lint/linter/selector_format_spec.rb +114 -114
- data/spec/scss_lint/linter/shorthand_spec.rb +32 -32
- data/spec/scss_lint/linter/single_line_per_property_spec.rb +10 -10
- data/spec/scss_lint/linter/single_line_per_selector_spec.rb +24 -24
- data/spec/scss_lint/linter/space_after_comma_spec.rb +60 -60
- data/spec/scss_lint/linter/space_after_property_colon_spec.rb +44 -44
- data/spec/scss_lint/linter/space_after_property_name_spec.rb +6 -6
- data/spec/scss_lint/linter/space_before_brace_spec.rb +119 -119
- data/spec/scss_lint/linter/space_between_parens_spec.rb +48 -48
- data/spec/scss_lint/linter/string_quotes_spec.rb +74 -62
- data/spec/scss_lint/linter/trailing_semicolon_spec.rb +53 -54
- data/spec/scss_lint/linter/trailing_zero_spec.rb +34 -34
- data/spec/scss_lint/linter/unnecessary_mantissa_spec.rb +10 -10
- data/spec/scss_lint/linter/unnecessary_parent_reference_spec.rb +18 -18
- data/spec/scss_lint/linter/url_format_spec.rb +4 -4
- data/spec/scss_lint/linter/url_quotes_spec.rb +14 -14
- data/spec/scss_lint/linter/variable_for_property_spec.rb +115 -0
- data/spec/scss_lint/linter/vendor_prefixes_spec.rb +66 -56
- data/spec/scss_lint/linter/zero_unit_spec.rb +22 -22
- data/spec/scss_lint/linter_spec.rb +72 -28
- data/spec/scss_lint/runner_spec.rb +0 -1
- data/spec/scss_lint/selector_visitor_spec.rb +23 -23
- data/spec/spec_helper.rb +2 -2
- metadata +27 -12
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SCSSLint::Engine do
|
4
|
-
let(:engine) { described_class.new(
|
4
|
+
let(:engine) { described_class.new(scss) }
|
5
5
|
|
6
6
|
context 'when a @media directive is present' do
|
7
|
-
let(:
|
7
|
+
let(:scss) { <<-SCSS }
|
8
8
|
@media only screen {
|
9
9
|
}
|
10
|
-
|
10
|
+
SCSS
|
11
11
|
|
12
12
|
it 'has a parse tree' do
|
13
13
|
engine.tree.should_not be_nil
|
@@ -15,7 +15,7 @@ describe SCSSLint::Engine do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
context 'when the file being linted has an invalid byte sequence' do
|
18
|
-
let(:
|
18
|
+
let(:scss) { "\xC0\u0001" }
|
19
19
|
|
20
20
|
it 'raises a SyntaxError' do
|
21
21
|
expect { engine }.to raise_error(SCSSLint::FileEncodingError)
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SCSSLint::FileFinder do
|
4
|
+
let(:config) { SCSSLint::Config.default }
|
5
|
+
|
6
|
+
subject { described_class.new(config) }
|
7
|
+
|
8
|
+
describe '#find' do
|
9
|
+
include_context 'isolated environment'
|
10
|
+
|
11
|
+
subject { super().find(patterns) }
|
12
|
+
|
13
|
+
context 'when no patterns are given' do
|
14
|
+
let(:patterns) { [] }
|
15
|
+
|
16
|
+
context 'and there are no SCSS files under the current directory' do
|
17
|
+
it { should == [] }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'and there are SCSS files under the current directory' do
|
21
|
+
before do
|
22
|
+
`touch blah.scss`
|
23
|
+
`mkdir -p more`
|
24
|
+
`touch more/more.scss`
|
25
|
+
end
|
26
|
+
|
27
|
+
it { should == ['blah.scss', 'more/more.scss'] }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'and a default set of files is specified in the config' do
|
31
|
+
let(:files) { ['file1.scss', 'file2.scss'] }
|
32
|
+
|
33
|
+
before do
|
34
|
+
config.stub(:scss_files).and_return(files)
|
35
|
+
end
|
36
|
+
|
37
|
+
it { should == files }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when files without valid extension are given' do
|
42
|
+
let(:patterns) { ['test.txt'] }
|
43
|
+
|
44
|
+
context 'and those files exist' do
|
45
|
+
before do
|
46
|
+
`touch test.txt`
|
47
|
+
end
|
48
|
+
|
49
|
+
it { should == ['test.txt'] }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'and those files do not exist' do
|
53
|
+
it { should == ['test.txt'] }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when directories are given' do
|
58
|
+
let(:patterns) { ['some-dir'] }
|
59
|
+
|
60
|
+
context 'and those directories exist' do
|
61
|
+
before do
|
62
|
+
`mkdir -p some-dir`
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'and they contain SCSS files' do
|
66
|
+
before do
|
67
|
+
`touch some-dir/test.scss`
|
68
|
+
end
|
69
|
+
|
70
|
+
it { should == ['some-dir/test.scss'] }
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'and they contain CSS files' do
|
74
|
+
before do
|
75
|
+
`touch some-dir/test.css`
|
76
|
+
end
|
77
|
+
|
78
|
+
it { should == ['some-dir/test.css'] }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'and they contain more directories with files with recognized extensions' do
|
82
|
+
before do
|
83
|
+
`mkdir -p some-dir/more-dir`
|
84
|
+
`touch some-dir/more-dir/test.scss`
|
85
|
+
end
|
86
|
+
|
87
|
+
it { should == ['some-dir/more-dir/test.scss'] }
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'and they contain files with some other extension' do
|
91
|
+
before do
|
92
|
+
`touch some-dir/test.txt`
|
93
|
+
end
|
94
|
+
|
95
|
+
it { should == [] }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'and those directories do not exist' do
|
100
|
+
it { should == ['some-dir'] }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when the same file is specified multiple times' do
|
105
|
+
let(:patterns) { ['test.scss'] * 3 }
|
106
|
+
|
107
|
+
it { should == ['test.scss'] }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -2,41 +2,41 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SCSSLint::Linter::BangFormat do
|
4
4
|
context 'when no bang is used' do
|
5
|
-
let(:
|
5
|
+
let(:scss) { <<-SCSS }
|
6
6
|
p {
|
7
7
|
color: #000;
|
8
8
|
}
|
9
|
-
|
9
|
+
SCSS
|
10
10
|
|
11
11
|
it { should_not report_lint }
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when !important is used correctly' do
|
15
|
-
let(:
|
15
|
+
let(:scss) { <<-SCSS }
|
16
16
|
p {
|
17
17
|
color: #000 !important;
|
18
18
|
}
|
19
|
-
|
19
|
+
SCSS
|
20
20
|
|
21
21
|
it { should_not report_lint }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'when !important has no space before' do
|
25
|
-
let(:
|
25
|
+
let(:scss) { <<-SCSS }
|
26
26
|
p {
|
27
27
|
color: #000!important;
|
28
28
|
}
|
29
|
-
|
29
|
+
SCSS
|
30
30
|
|
31
31
|
it { should report_lint line: 2 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'when !important has a space after' do
|
35
|
-
let(:
|
35
|
+
let(:scss) { <<-SCSS }
|
36
36
|
p {
|
37
37
|
color: #000 ! important;
|
38
38
|
}
|
39
|
-
|
39
|
+
SCSS
|
40
40
|
|
41
41
|
it { should report_lint line: 2 }
|
42
42
|
end
|
@@ -44,11 +44,11 @@ describe SCSSLint::Linter::BangFormat do
|
|
44
44
|
context 'when !important has a space after and config allows it' do
|
45
45
|
let(:linter_config) { { 'space_before_bang' => true, 'space_after_bang' => true } }
|
46
46
|
|
47
|
-
let(:
|
47
|
+
let(:scss) { <<-SCSS }
|
48
48
|
p {
|
49
49
|
color: #000 ! important;
|
50
50
|
}
|
51
|
-
|
51
|
+
SCSS
|
52
52
|
|
53
53
|
it { should_not report_lint }
|
54
54
|
end
|
@@ -56,11 +56,11 @@ describe SCSSLint::Linter::BangFormat do
|
|
56
56
|
context 'when !important has a space before but config does not allow it' do
|
57
57
|
let(:linter_config) { { 'space_before_bang' => false, 'space_after_bang' => true } }
|
58
58
|
|
59
|
-
let(:
|
59
|
+
let(:scss) { <<-SCSS }
|
60
60
|
p {
|
61
61
|
color: #000 ! important;
|
62
62
|
}
|
63
|
-
|
63
|
+
SCSS
|
64
64
|
|
65
65
|
it { should report_lint line: 2 }
|
66
66
|
end
|
@@ -68,17 +68,17 @@ describe SCSSLint::Linter::BangFormat do
|
|
68
68
|
context 'when !important has no spaces around and config allows it' do
|
69
69
|
let(:linter_config) { { 'space_before_bang' => false, 'space_after_bang' => false } }
|
70
70
|
|
71
|
-
let(:
|
71
|
+
let(:scss) { <<-SCSS }
|
72
72
|
p {
|
73
73
|
color: #000!important;
|
74
74
|
}
|
75
|
-
|
75
|
+
SCSS
|
76
76
|
|
77
77
|
it { should_not report_lint }
|
78
78
|
end
|
79
79
|
|
80
80
|
context 'when ! appears within a string' do
|
81
|
-
let(:
|
81
|
+
let(:scss) { <<-SCSS }
|
82
82
|
p:before { content: "!important"; }
|
83
83
|
p:before { content: "imp!ortant"; }
|
84
84
|
p:after { content: '!'; }
|
@@ -92,20 +92,30 @@ describe SCSSLint::Linter::BangFormat do
|
|
92
92
|
$foo: "bar!";
|
93
93
|
$foo: "!bar";
|
94
94
|
$foo: "b!ar";
|
95
|
-
|
95
|
+
SCSS
|
96
96
|
|
97
97
|
it { should_not report_lint }
|
98
98
|
end
|
99
99
|
|
100
100
|
context 'when !<word> is not followed by a semicolon' do
|
101
|
-
let(:
|
101
|
+
let(:scss) { <<-SCSS }
|
102
102
|
.class {
|
103
103
|
margin: 0 !important
|
104
104
|
}
|
105
|
-
|
105
|
+
SCSS
|
106
106
|
|
107
107
|
it 'does not loop forever' do
|
108
108
|
subject.should_not report_lint
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
context 'when property contains a list literal with an empty list' do
|
113
|
+
let(:scss) { <<-SCSS }
|
114
|
+
p {
|
115
|
+
content: 0 ();
|
116
|
+
}
|
117
|
+
SCSS
|
118
|
+
|
119
|
+
it { should_not report_lint }
|
120
|
+
end
|
111
121
|
end
|
@@ -2,83 +2,117 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SCSSLint::Linter::BorderZero do
|
4
4
|
context 'when a rule is empty' do
|
5
|
-
let(:
|
5
|
+
let(:scss) { <<-SCSS }
|
6
6
|
p {
|
7
7
|
}
|
8
|
-
|
8
|
+
SCSS
|
9
9
|
|
10
10
|
it { should_not report_lint }
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'when a property' do
|
14
14
|
context 'contains a normal border' do
|
15
|
-
let(:
|
15
|
+
let(:scss) { <<-SCSS }
|
16
16
|
p {
|
17
17
|
border: 1px solid #000;
|
18
18
|
}
|
19
|
-
|
19
|
+
SCSS
|
20
20
|
|
21
21
|
it { should_not report_lint }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'has a border of 0' do
|
25
|
-
let(:
|
25
|
+
let(:scss) { <<-SCSS }
|
26
26
|
p {
|
27
27
|
border: 0;
|
28
28
|
}
|
29
|
-
|
29
|
+
SCSS
|
30
30
|
|
31
31
|
it { should_not report_lint }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'has a border of none' do
|
35
|
-
let(:
|
35
|
+
let(:scss) { <<-SCSS }
|
36
36
|
p {
|
37
37
|
border: none;
|
38
38
|
}
|
39
|
-
|
39
|
+
SCSS
|
40
40
|
|
41
41
|
it { should report_lint line: 2 }
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'has a border-top of none' do
|
45
|
-
let(:
|
45
|
+
let(:scss) { <<-SCSS }
|
46
46
|
p {
|
47
47
|
border-top: none;
|
48
48
|
}
|
49
|
-
|
49
|
+
SCSS
|
50
50
|
|
51
51
|
it { should report_lint line: 2 }
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'has a border-right of none' do
|
55
|
-
let(:
|
55
|
+
let(:scss) { <<-SCSS }
|
56
56
|
p {
|
57
57
|
border-right: none;
|
58
58
|
}
|
59
|
-
|
59
|
+
SCSS
|
60
60
|
|
61
61
|
it { should report_lint line: 2 }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'has a border-bottom of none' do
|
65
|
-
let(:
|
65
|
+
let(:scss) { <<-SCSS }
|
66
66
|
p {
|
67
67
|
border-bottom: none;
|
68
68
|
}
|
69
|
-
|
69
|
+
SCSS
|
70
70
|
|
71
71
|
it { should report_lint line: 2 }
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'has a border-left of none' do
|
75
|
-
let(:
|
75
|
+
let(:scss) { <<-SCSS }
|
76
76
|
p {
|
77
77
|
border-left: none;
|
78
78
|
}
|
79
|
-
|
79
|
+
SCSS
|
80
80
|
|
81
81
|
it { should report_lint line: 2 }
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
context 'when a convention of `none` is preferred' do
|
86
|
+
let(:linter_config) { { 'convention' => 'none' } }
|
87
|
+
|
88
|
+
context 'and the border is `none`' do
|
89
|
+
let(:scss) { <<-SCSS }
|
90
|
+
p {
|
91
|
+
border: none;
|
92
|
+
}
|
93
|
+
SCSS
|
94
|
+
|
95
|
+
it { should_not report_lint }
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'and the border is `0`' do
|
99
|
+
let(:scss) { <<-SCSS }
|
100
|
+
p {
|
101
|
+
border: 0;
|
102
|
+
}
|
103
|
+
SCSS
|
104
|
+
|
105
|
+
it { should report_lint }
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'and the border is a non-zero value' do
|
109
|
+
let(:scss) { <<-SCSS }
|
110
|
+
p {
|
111
|
+
border: 5px;
|
112
|
+
}
|
113
|
+
SCSS
|
114
|
+
|
115
|
+
it { should_not report_lint }
|
116
|
+
end
|
117
|
+
end
|
84
118
|
end
|
@@ -2,81 +2,81 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SCSSLint::Linter::ColorKeyword do
|
4
4
|
context 'when a color is specified as a hex' do
|
5
|
-
let(:
|
5
|
+
let(:scss) { <<-SCSS }
|
6
6
|
p {
|
7
7
|
color: #fff;
|
8
8
|
}
|
9
|
-
|
9
|
+
SCSS
|
10
10
|
|
11
11
|
it { should_not report_lint }
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when a color is specified as a keyword' do
|
15
|
-
let(:
|
15
|
+
let(:scss) { <<-SCSS }
|
16
16
|
p {
|
17
17
|
color: white;
|
18
18
|
}
|
19
|
-
|
19
|
+
SCSS
|
20
20
|
|
21
21
|
it { should report_lint line: 2 }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'when a color keyword exists in a shorthand property' do
|
25
|
-
let(:
|
25
|
+
let(:scss) { <<-SCSS }
|
26
26
|
p {
|
27
27
|
border: 1px solid black;
|
28
28
|
}
|
29
|
-
|
29
|
+
SCSS
|
30
30
|
|
31
31
|
it { should report_lint line: 2 }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'when a property contains a color keyword as a string' do
|
35
|
-
let(:
|
35
|
+
let(:scss) { <<-SCSS }
|
36
36
|
p {
|
37
37
|
content: 'white';
|
38
38
|
}
|
39
|
-
|
39
|
+
SCSS
|
40
40
|
|
41
41
|
it { should_not report_lint }
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'when a function call contains a color keyword' do
|
45
|
-
let(:
|
45
|
+
let(:scss) { <<-SCSS }
|
46
46
|
p {
|
47
47
|
color: function(red);
|
48
48
|
}
|
49
|
-
|
49
|
+
SCSS
|
50
50
|
|
51
51
|
it { should report_lint line: 2 }
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'when a mixin include contains a color keyword' do
|
55
|
-
let(:
|
55
|
+
let(:scss) { <<-SCSS }
|
56
56
|
p {
|
57
57
|
@include some-mixin(red);
|
58
58
|
}
|
59
|
-
|
59
|
+
SCSS
|
60
60
|
|
61
61
|
it { should report_lint line: 2 }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when the "transparent" color keyword is used' do
|
65
|
-
let(:
|
65
|
+
let(:scss) { <<-SCSS }
|
66
66
|
p {
|
67
67
|
@include mixin(transparent);
|
68
68
|
}
|
69
|
-
|
69
|
+
SCSS
|
70
70
|
|
71
71
|
it { should_not report_lint }
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'when color keyword appears in a string identifier' do
|
75
|
-
let(:
|
75
|
+
let(:scss) { <<-SCSS }
|
76
76
|
p {
|
77
77
|
content: content-with-blue-in-name;
|
78
78
|
}
|
79
|
-
|
79
|
+
SCSS
|
80
80
|
|
81
81
|
it { should_not report_lint }
|
82
82
|
end
|