scss-lint 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +31 -1
  3. data/data/prefixed-identifiers/base.txt +107 -0
  4. data/data/prefixed-identifiers/bourbon.txt +71 -0
  5. data/lib/scss_lint/cli.rb +34 -7
  6. data/lib/scss_lint/config.rb +12 -1
  7. data/lib/scss_lint/engine.rb +3 -1
  8. data/lib/scss_lint/linter/bang_format.rb +40 -0
  9. data/lib/scss_lint/linter/declaration_order.rb +35 -14
  10. data/lib/scss_lint/linter/import_path.rb +62 -0
  11. data/lib/scss_lint/linter/name_format.rb +1 -1
  12. data/lib/scss_lint/linter/nesting_depth.rb +24 -0
  13. data/lib/scss_lint/linter/property_sort_order.rb +4 -11
  14. data/lib/scss_lint/linter/property_spelling.rb +25 -8
  15. data/lib/scss_lint/linter/qualifying_element.rb +42 -0
  16. data/lib/scss_lint/linter/selector_format.rb +23 -11
  17. data/lib/scss_lint/linter/space_after_property_colon.rb +4 -4
  18. data/lib/scss_lint/linter/space_after_property_name.rb +16 -1
  19. data/lib/scss_lint/linter/space_before_brace.rb +36 -9
  20. data/lib/scss_lint/linter/trailing_semicolon.rb +6 -2
  21. data/lib/scss_lint/linter/vendor_prefixes.rb +64 -0
  22. data/lib/scss_lint/rake_task.rb +1 -0
  23. data/lib/scss_lint/runner.rb +2 -1
  24. data/lib/scss_lint/sass/script.rb +10 -0
  25. data/lib/scss_lint/version.rb +1 -1
  26. data/spec/scss_lint/cli_spec.rb +45 -2
  27. data/spec/scss_lint/linter/bang_format_spec.rb +79 -0
  28. data/spec/scss_lint/linter/declaration_order_spec.rb +466 -0
  29. data/spec/scss_lint/linter/import_path_spec.rb +300 -0
  30. data/spec/scss_lint/linter/nesting_depth_spec.rb +114 -0
  31. data/spec/scss_lint/linter/property_spelling_spec.rb +27 -0
  32. data/spec/scss_lint/linter/qualifying_element_spec.rb +125 -0
  33. data/spec/scss_lint/linter/selector_format_spec.rb +329 -0
  34. data/spec/scss_lint/linter/space_after_property_colon_spec.rb +14 -0
  35. data/spec/scss_lint/linter/space_after_property_name_spec.rb +14 -0
  36. data/spec/scss_lint/linter/space_before_brace_spec.rb +401 -17
  37. data/spec/scss_lint/linter/trailing_semicolon_spec.rb +47 -0
  38. data/spec/scss_lint/linter/vendor_prefixes_spec.rb +350 -0
  39. metadata +19 -2
@@ -0,0 +1,300 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::ImportPath do
4
+ context 'when the path includes no directories' do
5
+ context 'and the filename has no leading underscore or filename extension' do
6
+ let(:css) { '@import "filename";' }
7
+
8
+ it { should_not report_lint }
9
+ end
10
+
11
+ context 'and the filename has a leading underscore' do
12
+ let(:css) { '@import "_filename";' }
13
+
14
+ it { should report_lint line: 1 }
15
+ end
16
+
17
+ context 'and the filename has a filename extension' do
18
+ let(:css) { '@import "filename.scss";' }
19
+
20
+ it { should report_lint line: 1 }
21
+ end
22
+
23
+ context 'and the filename has a leading underscore and a filename extension' do
24
+ let(:css) { '@import "_filename.scss";' }
25
+
26
+ it { should report_lint line: 1 }
27
+ end
28
+
29
+ context 'and multiple files are @imported' do
30
+ context 'and neither have leading underscores or filename extensions' do
31
+ let(:css) { '@import "foo", "bar";' }
32
+
33
+ it { should_not report_lint }
34
+ end
35
+
36
+ context 'and the second has a leading underscore' do
37
+ let(:css) { '@import "foo", "_bar";' }
38
+
39
+ it { should report_lint line: 1 }
40
+ end
41
+
42
+ context 'and the first has a filename extension' do
43
+ let(:css) { '@import "foo.scss", "bar";' }
44
+
45
+ it { should report_lint line: 1 }
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when the path includes directories' do
51
+ context 'and the filename has no leading underscore or filename extension' do
52
+ let(:css) { '@import "path/to/filename";' }
53
+
54
+ it { should_not report_lint }
55
+ end
56
+
57
+ context 'and the filename has a leading underscore' do
58
+ let(:css) { '@import "../to/_filename";' }
59
+
60
+ it { should report_lint line: 1 }
61
+ end
62
+
63
+ context 'and the filename has a filename extension' do
64
+ let(:css) { '@import "/path/to/filename.scss";' }
65
+
66
+ it { should report_lint line: 1 }
67
+ end
68
+
69
+ context 'and the filename has a leading underscore and a filename extension' do
70
+ let(:css) { '@import "path/to/_filename.scss";' }
71
+
72
+ it { should report_lint line: 1 }
73
+ end
74
+
75
+ context 'and multiple files are @imported' do
76
+ context 'and neither have leading underscores or filename extensions' do
77
+ let(:css) { '@import "path/to/foo", "../../bar";' }
78
+
79
+ it { should_not report_lint }
80
+ end
81
+
82
+ context 'and the second has a leading underscore' do
83
+ let(:css) { '@import "path/to/foo", "../../_bar";' }
84
+
85
+ it { should report_lint line: 1 }
86
+ end
87
+
88
+ context 'and the first has a filename extension' do
89
+ let(:css) { '@import "path/to/foo.scss", "../../bar";' }
90
+
91
+ it { should report_lint line: 1 }
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'when option `leading_underscore` is true' do
97
+ let(:linter_config) { { 'leading_underscore' => true } }
98
+
99
+ context 'and the filename has no leading underscore or filename extension' do
100
+ let(:css) { '@import "path/to/filename";' }
101
+
102
+ it { should report_lint line: 1 }
103
+ end
104
+
105
+ context 'and the filename has a leading underscore' do
106
+ let(:css) { '@import "../to/_filename";' }
107
+
108
+ it { should_not report_lint }
109
+ end
110
+
111
+ context 'and the filename has a filename extension' do
112
+ let(:css) { '@import "/path/to/filename.scss";' }
113
+
114
+ it { should report_lint line: 1 }
115
+ end
116
+
117
+ context 'and the filename has a leading underscore and a filename extension' do
118
+ let(:css) { '@import "path/to/_filename.scss";' }
119
+
120
+ it { should report_lint line: 1 }
121
+ end
122
+
123
+ context 'and multiple files are @imported' do
124
+ context 'and neither have leading underscores or filename extensions' do
125
+ let(:css) { '@import "path/to/foo", "../../bar";' }
126
+
127
+ it { should report_lint line: 1 }
128
+ end
129
+
130
+ context 'and both have a leading underscore' do
131
+ let(:css) { '@import "path/to/_foo", "../../_bar";' }
132
+
133
+ it { should_not report_lint }
134
+ end
135
+
136
+ context 'and only one has a leading underscore' do
137
+ let(:css) { '@import "path/to/foo.scss", "../../_bar";' }
138
+
139
+ it { should report_lint line: 1 }
140
+ end
141
+ end
142
+ end
143
+
144
+ context 'when option `filename_extension` is true' do
145
+ let(:linter_config) { { 'filename_extension' => true } }
146
+
147
+ context 'and the filename has no leading underscore or filename extension' do
148
+ let(:css) { '@import "path/to/filename";' }
149
+
150
+ it { should report_lint line: 1 }
151
+ end
152
+
153
+ context 'and the filename has a leading underscore' do
154
+ let(:css) { '@import "../to/_filename";' }
155
+
156
+ it { should report_lint line: 1 }
157
+ end
158
+
159
+ context 'and the filename has a filename extension' do
160
+ let(:css) { '@import "/path/to/filename.scss";' }
161
+
162
+ it { should_not report_lint }
163
+ end
164
+
165
+ context 'and the filename has a leading underscore and a filename extension' do
166
+ let(:css) { '@import "path/to/_filename.scss";' }
167
+
168
+ it { should report_lint line: 1 }
169
+ end
170
+
171
+ context 'and multiple files are @imported' do
172
+ context 'and neither have leading underscores or filename extensions' do
173
+ let(:css) { '@import "path/to/foo", "../../bar";' }
174
+
175
+ it { should report_lint line: 1 }
176
+ end
177
+
178
+ context 'and both have filename extensions' do
179
+ let(:css) { '@import "path/to/foo.scss", "../../bar.scss";' }
180
+
181
+ it { should_not report_lint }
182
+ end
183
+
184
+ context 'and only one has a filename extensions' do
185
+ let(:css) { '@import "path/to/foo.scss", "../../bar";' }
186
+
187
+ it { should report_lint line: 1 }
188
+ end
189
+ end
190
+ end
191
+
192
+ context 'when options `leading_underscore` and `filename_extension` are true' do
193
+ let(:linter_config) { { 'leading_underscore' => true, 'filename_extension' => true } }
194
+
195
+ context 'and the filename has no leading underscore or filename extension' do
196
+ let(:css) { '@import "path/to/filename";' }
197
+
198
+ it { should report_lint line: 1 }
199
+ end
200
+
201
+ context 'and the filename has a leading underscore' do
202
+ let(:css) { '@import "../to/_filename";' }
203
+
204
+ it { should report_lint line: 1 }
205
+ end
206
+
207
+ context 'and the filename has a filename extension' do
208
+ let(:css) { '@import "/path/to/filename.scss";' }
209
+
210
+ it { should report_lint line: 1 }
211
+ end
212
+
213
+ context 'and the filename has a leading underscore and a filename extension' do
214
+ let(:css) { '@import "path/to/_filename.scss";' }
215
+
216
+ it { should_not report_lint }
217
+ end
218
+
219
+ context 'and multiple files are @imported' do
220
+ context 'and neither have leading underscores or filename extensions' do
221
+ let(:css) { '@import "path/to/foo", "../../bar";' }
222
+
223
+ it { should report_lint line: 1 }
224
+ end
225
+
226
+ context 'and both have filename extensions and leading underscores' do
227
+ let(:css) { '@import "path/to/_foo.scss", "../../_bar.scss";' }
228
+
229
+ it { should_not report_lint }
230
+ end
231
+
232
+ context 'and only one has both a filename extension and a leading underscore' do
233
+ let(:css) { '@import "path/to/_foo.scss", "../../bar.scss";' }
234
+
235
+ it { should report_lint line: 1 }
236
+ end
237
+ end
238
+ end
239
+
240
+ context 'when the @import directive compiles directly to a CSS @import rule' do
241
+ context 'and the @import is a CSS file' do
242
+ let(:css) { '@import "_foo.css";' }
243
+
244
+ it { should_not report_lint }
245
+ end
246
+
247
+ context 'and the @import contains a protocol' do
248
+ let(:css) { '@import "http://foo.com/_bar.css";' }
249
+
250
+ it { should_not report_lint }
251
+ end
252
+
253
+ context 'and the @import contains a media query' do
254
+ let(:css) { '@import "_foo.css" screen;' }
255
+
256
+ it { should_not report_lint }
257
+ end
258
+
259
+ context 'and the @import is a URL' do
260
+ let(:css) { '@import url(_foo.css);' }
261
+
262
+ it { should_not report_lint }
263
+ end
264
+
265
+ context 'and the @import contains interpolation' do
266
+ let(:css) { <<-CSS }
267
+ $family: unquote("Droid+Sans");
268
+ @import url("http://fonts.googleapis.com/css?family=\#{$family}");
269
+ CSS
270
+
271
+ it { should_not report_lint }
272
+ end
273
+ end
274
+
275
+ context 'when the partial has the same name as its directory' do
276
+ context 'and the filename has no leading underscore or filename extension' do
277
+ let(:css) { '@import "foo/foo";' }
278
+
279
+ it { should_not report_lint }
280
+ end
281
+
282
+ context 'and the filename has a leading underscore' do
283
+ let(:css) { '@import "_foo/_foo";' }
284
+
285
+ it { should report_lint line: 1 }
286
+ end
287
+
288
+ context 'and the filename has a filename extension' do
289
+ let(:css) { '@import "foo/foo.scss";' }
290
+
291
+ it { should report_lint line: 1 }
292
+ end
293
+
294
+ context 'and the filename has a leading underscore and a filename extension' do
295
+ let(:css) { '@import "_foo/_foo.scss";' }
296
+
297
+ it { should report_lint line: 1 }
298
+ end
299
+ end
300
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::NestingDepth do
4
+ context 'and selectors are nested up to depth 3' do
5
+ let(:css) { <<-CSS }
6
+ .one {
7
+ .two {
8
+ .three {
9
+ background: #f00;
10
+ }
11
+ }
12
+ }
13
+ CSS
14
+
15
+ it { should_not report_lint }
16
+ end
17
+
18
+ context 'and selectors are nested greater than depth 3' do
19
+ let(:css) { <<-CSS }
20
+ .one {
21
+ .two {
22
+ .three {
23
+ .four {
24
+ background: #f00;
25
+ }
26
+ .four-other {
27
+ background: #f00;
28
+ }
29
+ }
30
+ }
31
+ }
32
+ CSS
33
+
34
+ it { should report_lint line: 4 }
35
+ it { should report_lint line: 7 }
36
+ end
37
+
38
+ context 'when max_depth is set to 1' do
39
+ let(:linter_config) { { 'max_depth' => 1 } }
40
+
41
+ context 'when nesting has a depth of one' do
42
+ let(:css) { <<-CSS }
43
+ .one {
44
+ font-style: italic;
45
+ }
46
+ CSS
47
+
48
+ it { should_not report_lint }
49
+ end
50
+
51
+ context 'when nesting has a depth of two' do
52
+ let(:css) { <<-CSS }
53
+ .one {
54
+ .two {
55
+ font-style: italic;
56
+ }
57
+ }
58
+ .one {
59
+ font-style: italic;
60
+ }
61
+ CSS
62
+
63
+ it { should report_lint line: 2 }
64
+ end
65
+
66
+ context 'when nesting has a depth of three' do
67
+ let(:css) { <<-CSS }
68
+ .one {
69
+ .two {
70
+ .three {
71
+ background: #f00;
72
+ }
73
+ }
74
+ .two-other {
75
+ font-style: italic;
76
+ }
77
+ }
78
+ CSS
79
+
80
+ it { should report_lint line: 2 }
81
+ it { should report_lint line: 7 }
82
+ it { should_not report_lint line: 3 }
83
+ end
84
+
85
+ context 'when nesting properties' do
86
+ let(:css) { <<-CSS }
87
+ .one {
88
+ font: {
89
+ family: monospace;
90
+ style: italic;
91
+ }
92
+ }
93
+ CSS
94
+
95
+ it { should_not report_lint }
96
+ end
97
+
98
+ context 'when sequence contains a @keyframe' do
99
+ let(:css) { <<-CSS }
100
+ @keyframe my-keyframe {
101
+ 0% {
102
+ background: #000;
103
+ }
104
+
105
+ 50% {
106
+ background: #fff;
107
+ }
108
+ }
109
+ CSS
110
+
111
+ it { should_not report_lint }
112
+ end
113
+ end
114
+ end
@@ -54,4 +54,31 @@ describe SCSSLint::Linter::PropertySpelling do
54
54
  it { should_not report_lint }
55
55
  end
56
56
  end
57
+
58
+ context 'with valid nested properties' do
59
+ let(:css) { <<-CSS }
60
+ p {
61
+ text: {
62
+ align: center;
63
+ transform: uppercase;
64
+ }
65
+ }
66
+ CSS
67
+
68
+ it { should_not report_lint }
69
+ end
70
+
71
+ context 'with invalid nested properties' do
72
+ let(:css) { <<-CSS }
73
+ p {
74
+ text: {
75
+ aligned: center;
76
+ transformed: uppercase;
77
+ }
78
+ }
79
+ CSS
80
+
81
+ it { should report_lint line: 3 }
82
+ it { should report_lint line: 4 }
83
+ end
57
84
  end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::QualifyingElement do
4
+ context 'when selector does not include an element' do
5
+ let(:css) { <<-CSS }
6
+ .foo {}
7
+ #bar {}
8
+ [foobar] {}
9
+ .foo .bar {}
10
+ #bar > .foo {}
11
+ [foobar] #bar .foo {}
12
+ CSS
13
+
14
+ it { should_not report_lint }
15
+ end
16
+
17
+ context 'when selector includes an element' do
18
+ context 'and element does not qualify' do
19
+ let(:css) { <<-CSS }
20
+ ul {}
21
+ CSS
22
+
23
+ it { should_not report_lint }
24
+ end
25
+
26
+ context 'and element qualifies class' do
27
+ let(:css) { <<-CSS }
28
+ ul.list {}
29
+ CSS
30
+
31
+ it { should report_lint line: 1 }
32
+ end
33
+
34
+ context 'and element qualifies attribute' do
35
+ let(:css) { <<-CSS }
36
+ a[href] {}
37
+ CSS
38
+
39
+ it { should report_lint line: 1 }
40
+ end
41
+
42
+ context 'and element qualifies id' do
43
+ let(:css) { <<-CSS }
44
+ ul#list {}
45
+ CSS
46
+
47
+ it { should report_lint line: 1 }
48
+ end
49
+
50
+ context 'and selector is in a group' do
51
+ context 'and element does not qualify' do
52
+ let(:css) { <<-CSS }
53
+ .list li,
54
+ .item > span {}
55
+ CSS
56
+
57
+ it { should_not report_lint }
58
+ end
59
+
60
+ context 'and element qualifies class' do
61
+ let(:css) { <<-CSS }
62
+ .item span,
63
+ ul > li.item {}
64
+ CSS
65
+
66
+ it { should report_lint line: 1 }
67
+ end
68
+
69
+ context 'and element qualifies attribute' do
70
+ let(:css) { <<-CSS }
71
+ .item + span,
72
+ li a[href] {}
73
+ CSS
74
+
75
+ it { should report_lint line: 1 }
76
+ end
77
+
78
+ context 'and element qualifies id' do
79
+ let(:css) { <<-CSS }
80
+ #foo,
81
+ li#item + li {}
82
+ CSS
83
+
84
+ it { should report_lint line: 1 }
85
+ end
86
+ end
87
+
88
+ context 'and selector involves a combinator' do
89
+ context 'and element does not qualify' do
90
+ let(:css) { <<-CSS }
91
+ .list li {}
92
+ .list > li {}
93
+ .item + li {}
94
+ .item ~ li {}
95
+ CSS
96
+
97
+ it { should_not report_lint }
98
+ end
99
+
100
+ context 'and element qualifies class' do
101
+ let(:css) { <<-CSS }
102
+ ul > li.item {}
103
+ CSS
104
+
105
+ it { should report_lint line: 1 }
106
+ end
107
+
108
+ context 'and element qualifies attribute' do
109
+ let(:css) { <<-CSS }
110
+ li a[href] {}
111
+ CSS
112
+
113
+ it { should report_lint line: 1 }
114
+ end
115
+
116
+ context 'and element qualifies id' do
117
+ let(:css) { <<-CSS }
118
+ li#item + li {}
119
+ CSS
120
+
121
+ it { should report_lint line: 1 }
122
+ end
123
+ end
124
+ end
125
+ end