scss-lint 0.25.1 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +10 -1
  3. data/data/property-sort-orders/concentric.txt +99 -0
  4. data/lib/scss_lint.rb +1 -0
  5. data/lib/scss_lint/cli.rb +9 -3
  6. data/lib/scss_lint/exceptions.rb +4 -0
  7. data/lib/scss_lint/linter.rb +10 -1
  8. data/lib/scss_lint/linter/capitalization_in_selector.rb +14 -6
  9. data/lib/scss_lint/linter/compass/property_with_mixin.rb +9 -2
  10. data/lib/scss_lint/linter/indentation.rb +28 -6
  11. data/lib/scss_lint/linter/property_sort_order.rb +61 -9
  12. data/lib/scss_lint/linter/single_line_per_property.rb +53 -0
  13. data/lib/scss_lint/linter/single_line_per_selector.rb +6 -1
  14. data/lib/scss_lint/linter/space_after_comma.rb +27 -19
  15. data/lib/scss_lint/linter/space_before_brace.rb +5 -4
  16. data/lib/scss_lint/linter/trailing_semicolon.rb +53 -0
  17. data/lib/scss_lint/linter/unnecessary_parent_reference.rb +36 -0
  18. data/lib/scss_lint/reporter/default_reporter.rb +7 -2
  19. data/lib/scss_lint/reporter/xml_reporter.rb +2 -1
  20. data/lib/scss_lint/runner.rb +7 -3
  21. data/lib/scss_lint/version.rb +1 -1
  22. data/spec/scss_lint/cli_spec.rb +314 -0
  23. data/spec/scss_lint/config_spec.rb +439 -0
  24. data/spec/scss_lint/engine_spec.rb +24 -0
  25. data/spec/scss_lint/linter/border_zero_spec.rb +84 -0
  26. data/spec/scss_lint/linter/capitalization_in_selector_spec.rb +71 -0
  27. data/spec/scss_lint/linter/color_keyword_spec.rb +83 -0
  28. data/spec/scss_lint/linter/comment_spec.rb +55 -0
  29. data/spec/scss_lint/linter/compass/property_with_mixin_spec.rb +55 -0
  30. data/spec/scss_lint/linter/debug_statement_spec.rb +21 -0
  31. data/spec/scss_lint/linter/declaration_order_spec.rb +94 -0
  32. data/spec/scss_lint/linter/duplicate_property_spec.rb +176 -0
  33. data/spec/scss_lint/linter/else_placement_spec.rb +106 -0
  34. data/spec/scss_lint/linter/empty_line_between_blocks_spec.rb +263 -0
  35. data/spec/scss_lint/linter/empty_rule_spec.rb +27 -0
  36. data/spec/scss_lint/linter/final_newline_spec.rb +49 -0
  37. data/spec/scss_lint/linter/hex_length_spec.rb +104 -0
  38. data/spec/scss_lint/linter/hex_notation_spec.rb +104 -0
  39. data/spec/scss_lint/linter/hex_validation_spec.rb +36 -0
  40. data/spec/scss_lint/linter/id_with_extraneous_selector_spec.rb +139 -0
  41. data/spec/scss_lint/linter/indentation_spec.rb +242 -0
  42. data/spec/scss_lint/linter/leading_zero_spec.rb +233 -0
  43. data/spec/scss_lint/linter/mergeable_selector_spec.rb +283 -0
  44. data/spec/scss_lint/linter/name_format_spec.rb +206 -0
  45. data/spec/scss_lint/linter/placeholder_in_extend_spec.rb +63 -0
  46. data/spec/scss_lint/linter/property_sort_order_spec.rb +246 -0
  47. data/spec/scss_lint/linter/property_spelling_spec.rb +57 -0
  48. data/spec/scss_lint/linter/selector_depth_spec.rb +159 -0
  49. data/spec/scss_lint/linter/shorthand_spec.rb +172 -0
  50. data/spec/scss_lint/linter/single_line_per_property_spec.rb +73 -0
  51. data/spec/scss_lint/linter/single_line_per_selector_spec.rb +121 -0
  52. data/spec/scss_lint/linter/space_after_comma_spec.rb +315 -0
  53. data/spec/scss_lint/linter/space_after_property_colon_spec.rb +238 -0
  54. data/spec/scss_lint/linter/space_after_property_name_spec.rb +23 -0
  55. data/spec/scss_lint/linter/space_before_brace_spec.rb +447 -0
  56. data/spec/scss_lint/linter/space_between_parens_spec.rb +263 -0
  57. data/spec/scss_lint/linter/string_quotes_spec.rb +303 -0
  58. data/spec/scss_lint/linter/trailing_semicolon_spec.rb +188 -0
  59. data/spec/scss_lint/linter/unnecessary_mantissa_spec.rb +67 -0
  60. data/spec/scss_lint/linter/unnecessary_parent_reference_spec.rb +67 -0
  61. data/spec/scss_lint/linter/url_format_spec.rb +55 -0
  62. data/spec/scss_lint/linter/url_quotes_spec.rb +63 -0
  63. data/spec/scss_lint/linter/zero_unit_spec.rb +113 -0
  64. data/spec/scss_lint/linter_registry_spec.rb +50 -0
  65. data/spec/scss_lint/location_spec.rb +42 -0
  66. data/spec/scss_lint/reporter/config_reporter_spec.rb +42 -0
  67. data/spec/scss_lint/reporter/default_reporter_spec.rb +73 -0
  68. data/spec/scss_lint/reporter/files_reporter_spec.rb +38 -0
  69. data/spec/scss_lint/reporter/xml_reporter_spec.rb +103 -0
  70. data/spec/scss_lint/reporter_spec.rb +11 -0
  71. data/spec/scss_lint/runner_spec.rb +132 -0
  72. data/spec/scss_lint/selector_visitor_spec.rb +264 -0
  73. data/spec/spec_helper.rb +34 -0
  74. data/spec/support/isolated_environment.rb +25 -0
  75. data/spec/support/matchers/report_lint.rb +48 -0
  76. metadata +126 -8
  77. data/lib/scss_lint/linter/trailing_semicolon_after_property_value.rb +0 -40
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::PlaceholderInExtend do
4
+ context 'when extending with a class' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ @extend .error;
8
+ }
9
+ CSS
10
+
11
+ it { should report_lint line: 2 }
12
+ end
13
+
14
+ context 'when extending with a type' do
15
+ let(:css) { <<-CSS }
16
+ p {
17
+ @extend span;
18
+ }
19
+ CSS
20
+
21
+ it { should report_lint line: 2 }
22
+ end
23
+
24
+ context 'when extending with an id' do
25
+ let(:css) { <<-CSS }
26
+ p {
27
+ @extend #some-identifer;
28
+ }
29
+ CSS
30
+
31
+ it { should report_lint line: 2 }
32
+ end
33
+
34
+ context 'when extending with a placeholder' do
35
+ let(:css) { <<-CSS }
36
+ p {
37
+ @extend %placeholder;
38
+ }
39
+ CSS
40
+
41
+ it { should_not report_lint }
42
+ end
43
+
44
+ context 'when extending with a selector whose prefix is not a placeholder' do
45
+ let(:css) { <<-CSS }
46
+ p {
47
+ @extend .blah-\#{$dynamically_generated_name};
48
+ }
49
+ CSS
50
+
51
+ it { should report_lint line: 2 }
52
+ end
53
+
54
+ context 'when extending with a selector whose prefix is dynamic' do
55
+ let(:css) { <<-CSS }
56
+ p {
57
+ @extend \#{$dynamically_generated_placeholder_name};
58
+ }
59
+ CSS
60
+
61
+ it { should_not report_lint }
62
+ end
63
+ end
@@ -0,0 +1,246 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::PropertySortOrder do
4
+ context 'when rule is empty' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ }
8
+ CSS
9
+
10
+ it { should_not report_lint }
11
+ end
12
+
13
+ context 'when rule contains properties in sorted order' do
14
+ let(:css) { <<-CSS }
15
+ p {
16
+ background: #000;
17
+ display: none;
18
+ margin: 5px;
19
+ padding: 10px;
20
+ }
21
+ CSS
22
+
23
+ it { should_not report_lint }
24
+ end
25
+
26
+ context 'when rule contains mixins followed by properties in sorted order' do
27
+ let(:css) { <<-CSS }
28
+ p {
29
+ @include border-radius(5px);
30
+ background: #000;
31
+ display: none;
32
+ margin: 5px;
33
+ padding: 10px;
34
+ }
35
+ CSS
36
+
37
+ it { should_not report_lint }
38
+ end
39
+
40
+ context 'when rule contains nested rules after sorted properties' do
41
+ let(:css) { <<-CSS }
42
+ p {
43
+ background: #000;
44
+ display: none;
45
+ margin: 5px;
46
+ padding: 10px;
47
+ a {
48
+ color: #555;
49
+ }
50
+ }
51
+ CSS
52
+
53
+ it { should_not report_lint }
54
+ end
55
+
56
+ context 'when rule contains properties in random order' do
57
+ let(:css) { <<-CSS }
58
+ p {
59
+ padding: 5px;
60
+ display: block;
61
+ margin: 10px;
62
+ }
63
+ CSS
64
+
65
+ it { should report_lint line: 2 }
66
+ end
67
+
68
+ context 'when there are multiple rules with out of order properties' do
69
+ let(:css) { <<-CSS }
70
+ p {
71
+ display: block;
72
+ background: #fff;
73
+ }
74
+ a {
75
+ margin: 5px;
76
+ color: #444;
77
+ }
78
+ CSS
79
+
80
+ it { should report_lint line: 2 }
81
+ it { should report_lint line: 6 }
82
+ end
83
+
84
+ context 'when there are nested rules with out of order properties' do
85
+ let(:css) { <<-CSS }
86
+ p {
87
+ display: block;
88
+ background: #fff;
89
+ a {
90
+ margin: 5px;
91
+ color: #444;
92
+ }
93
+ }
94
+ CSS
95
+
96
+ it { should report_lint line: 2 }
97
+ it { should report_lint line: 5 }
98
+ end
99
+
100
+ context 'when out-of-order property is the second last in the list of sorted properties' do
101
+ let(:css) { <<-CSS }
102
+ p {
103
+ border: 0;
104
+ border-radius: 3px;
105
+ float: left;
106
+ display: block;
107
+ }
108
+ CSS
109
+
110
+ it { should report_lint line: 4 }
111
+ end
112
+
113
+ context 'when vendor-prefixed properties are ordered after the non-prefixed property' do
114
+ let(:css) { <<-CSS }
115
+ p {
116
+ border-radius: 3px;
117
+ -moz-border-radius: 3px;
118
+ -o-border-radius: 3px;
119
+ -webkit-border-radius: 3px;
120
+ }
121
+ CSS
122
+
123
+ it { should report_lint line: 2 }
124
+ end
125
+
126
+ context 'when vendor-prefixed properties are ordered before the non-prefixed property' do
127
+ let(:css) { <<-CSS }
128
+ p {
129
+ -moz-border-radius: 3px;
130
+ -o-border-radius: 3px;
131
+ -webkit-border-radius: 3px;
132
+ border-radius: 3px;
133
+ }
134
+ CSS
135
+
136
+ it { should_not report_lint }
137
+ end
138
+
139
+ context 'when using -moz-osx vendor-prefixed property' do
140
+ let(:css) { <<-CSS }
141
+ p {
142
+ -moz-osx-font-smoothing: grayscale;
143
+ -webkit-font-smoothing: antialiased;
144
+ }
145
+ CSS
146
+
147
+ it { should_not report_lint }
148
+ end
149
+
150
+ context 'when vendor properties are ordered out-of-order before the non-prefixed property' do
151
+ let(:css) { <<-CSS }
152
+ p {
153
+ -moz-border-radius: 3px;
154
+ -webkit-border-radius: 3px;
155
+ -o-border-radius: 3px;
156
+ border-radius: 3px;
157
+ }
158
+ CSS
159
+
160
+ it { should report_lint line: 3 }
161
+ end
162
+
163
+ context 'when the order has been explicitly set' do
164
+ let(:linter_config) { { 'order' => %w[position display padding margin width] } }
165
+
166
+ context 'and the properties match the specified order' do
167
+ let(:css) { <<-CSS }
168
+ p {
169
+ display: block;
170
+ padding: 5px;
171
+ margin: 10px;
172
+ }
173
+ CSS
174
+
175
+ it { should_not report_lint }
176
+ end
177
+
178
+ context 'and the properties do not match the specified order' do
179
+ let(:css) { <<-CSS }
180
+ p {
181
+ padding: 5px;
182
+ display: block;
183
+ margin: 10px;
184
+ }
185
+ CSS
186
+
187
+ it { should report_lint line: 2 }
188
+ end
189
+
190
+ context 'and there are properties that are not specified in the explicit ordering' do
191
+ let(:css) { <<-CSS }
192
+ p {
193
+ display: block;
194
+ padding: 5px;
195
+ font-weight: bold; // Unspecified
196
+ margin: 10px;
197
+ border: 0; // Unspecified
198
+ background: red; // Unspecified
199
+ width: 100%;
200
+ }
201
+ CSS
202
+
203
+ context 'and the ignored_omitted option is enabled' do
204
+ let(:linter_config) { super().merge('ignored_unspecified' => true) }
205
+
206
+ it { should_not report_lint }
207
+ end
208
+
209
+ context 'and the ignored_omitted option is disabled' do
210
+ let(:linter_config) { super().merge('ignored_unspecified' => false) }
211
+
212
+ it { should report_lint }
213
+ end
214
+ end
215
+ end
216
+
217
+ context 'when sort order is set to a preset order' do
218
+ let(:linter_config) { { 'order' => 'concentric' } }
219
+
220
+ context 'and the properties match the order' do
221
+ let(:css) { <<-CSS }
222
+ p {
223
+ display: block;
224
+ position: absolute;
225
+ float: left;
226
+ clear: both;
227
+ }
228
+ CSS
229
+
230
+ it { should_not report_lint }
231
+ end
232
+
233
+ context 'and the properties do not match the order' do
234
+ let(:css) { <<-CSS }
235
+ p {
236
+ clear: both;
237
+ display: block;
238
+ float: left;
239
+ position: absolute;
240
+ }
241
+ CSS
242
+
243
+ it { should report_lint }
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::PropertySpelling do
4
+ context 'with a regular property' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ margin: 5px;
8
+ }
9
+ CSS
10
+
11
+ it { should_not report_lint }
12
+ end
13
+
14
+ context 'with a property containing interpolation' do
15
+ let(:css) { <<-CSS }
16
+ p {
17
+ \#{$property-name}: 5px;
18
+ }
19
+ CSS
20
+
21
+ it { should_not report_lint }
22
+ end
23
+
24
+ context 'with a non-existent property' do
25
+ let(:css) { <<-CSS }
26
+ p {
27
+ peanut-butter: jelly-time;
28
+ }
29
+ CSS
30
+
31
+ it { should report_lint }
32
+ end
33
+
34
+ context 'when extra properties are specified' do
35
+ let(:linter_config) { { 'extra_properties' => ['made-up-property'] } }
36
+
37
+ context 'with a non-existent property' do
38
+ let(:css) { <<-CSS }
39
+ p {
40
+ peanut-butter: jelly-time;
41
+ }
42
+ CSS
43
+
44
+ it { should report_lint }
45
+ end
46
+
47
+ context 'with a property listed as an extra property' do
48
+ let(:css) { <<-CSS }
49
+ p {
50
+ made-up-property: value;
51
+ }
52
+ CSS
53
+
54
+ it { should_not report_lint }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::SelectorDepth do
4
+ context 'when sequence has a depth of one' do
5
+ let(:css) { 'p {}' }
6
+
7
+ it { should_not report_lint }
8
+ end
9
+
10
+ context 'when sequence has a depth of three' do
11
+ let(:css) { 'body article p {}' }
12
+
13
+ it { should_not report_lint }
14
+
15
+ context 'and contains a nested selector' do
16
+ let(:css) { <<-CSS }
17
+ body article p {
18
+ i {
19
+ font-style: italic;
20
+ }
21
+ }
22
+ CSS
23
+
24
+ it { should report_lint line: 2 }
25
+ end
26
+
27
+ context 'and contains multiple nested selectors' do
28
+ let(:css) { <<-CSS }
29
+ body article p {
30
+ b {
31
+ font-weight: bold;
32
+ }
33
+ i {
34
+ font-style: italic;
35
+ }
36
+ }
37
+ CSS
38
+
39
+ it { should report_lint line: 2 }
40
+ it { should report_lint line: 5 }
41
+ end
42
+ end
43
+
44
+ context 'when sequence has a depth of four' do
45
+ let(:css) { 'body article p i {}' }
46
+
47
+ it { should report_lint line: 1 }
48
+ end
49
+
50
+ context 'when sequence is made up of adjacent sibling combinators' do
51
+ let(:css) { '.one + .two + .three + .four {}' }
52
+
53
+ it { should_not report_lint }
54
+ end
55
+
56
+ context 'when sequence is made up of general sibling combinators' do
57
+ let(:css) { '.one .two ~ .three ~ .four {}' }
58
+
59
+ it { should_not report_lint }
60
+ end
61
+
62
+ context 'when sequence contains interpolation' do
63
+ let(:css) { '.one #{$interpolated-string} .two .three {}' }
64
+
65
+ it { should_not report_lint }
66
+ end
67
+
68
+ context 'when comma sequence contains no sequences exceeding depth limit' do
69
+ let(:css) { <<-CSS }
70
+ p,
71
+ .one .two .three,
72
+ ul > li {
73
+ }
74
+ CSS
75
+
76
+ it { should_not report_lint }
77
+
78
+ context 'and a nested selector causes one of the sequences to exceed the limit' do
79
+ let(:css) { <<-CSS }
80
+ p,
81
+ .one .two .three,
82
+ ul > li {
83
+ .four {}
84
+ }
85
+ CSS
86
+
87
+ it { should report_lint line: 4 }
88
+ end
89
+ end
90
+
91
+ context 'when comma sequence contains a sequence exceeding the depth limit' do
92
+ let(:css) { <<-CSS }
93
+ p,
94
+ .one .two .three .four,
95
+ ul > li {
96
+ }
97
+ CSS
98
+
99
+ it { should report_lint line: 1 }
100
+ end
101
+
102
+ context 'when sequence contains a nested selector with a parent selector' do
103
+ context 'which does not exceed the depth limit' do
104
+ let(:css) { <<-CSS }
105
+ .one .two {
106
+ .three & {}
107
+ }
108
+ CSS
109
+
110
+ it { should_not report_lint }
111
+
112
+ context 'and the parent selector is chained' do
113
+ let(:css) { <<-CSS }
114
+ .one .two .three {
115
+ &.chained {}
116
+ }
117
+ CSS
118
+
119
+ it { should_not report_lint }
120
+ end
121
+ end
122
+
123
+ context 'which does exceed the depth limit' do
124
+ let(:css) { <<-CSS }
125
+ .one .two {
126
+ .three & & .four {}
127
+ }
128
+ CSS
129
+
130
+ it { should report_lint line: 2 }
131
+
132
+ context 'and the parent selector is chained' do
133
+ let(:css) { <<-CSS }
134
+ .one .two .three > .four {
135
+ &.chained {}
136
+ }
137
+ CSS
138
+
139
+ it { should report_lint line: 2 }
140
+ end
141
+ end
142
+ end
143
+
144
+ context 'when sequence contains a @keyframe' do
145
+ let(:css) { <<-CSS }
146
+ @keyframe my-keyframe {
147
+ 0% {
148
+ background: #000;
149
+ }
150
+
151
+ 50% {
152
+ background: #fff;
153
+ }
154
+ }
155
+ CSS
156
+
157
+ it { should_not report_lint }
158
+ end
159
+ end