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
@@ -27,6 +27,7 @@ module SCSSLint
27
27
  def run_task
28
28
  # Lazy load so task doesn't impact load time of Rakefile
29
29
  require 'scss_lint'
30
+ require 'scss_lint/cli'
30
31
 
31
32
  CLI.new([]).tap do |cli|
32
33
  cli.parse_arguments
@@ -48,7 +48,8 @@ module SCSSLint
48
48
  end
49
49
  end
50
50
  rescue Sass::SyntaxError => ex
51
- @lints << Lint.new(nil, ex.sass_filename, Location.new(ex.sass_line), ex.to_s, :error)
51
+ @lints << Lint.new(nil, ex.sass_filename, Location.new(ex.sass_line),
52
+ "Syntax Error: #{ex}", :error)
52
53
  rescue FileEncodingError => ex
53
54
  @lints << Lint.new(nil, file, Location.new, ex.to_s, :error)
54
55
  end
@@ -6,6 +6,8 @@ module Sass::Script
6
6
  # Define the `node_name` and `visit_method` class methods for each Sass Script
7
7
  # parse tree node type so that our custom visitor can seamless traverse the
8
8
  # tree.
9
+ # Define the `invalid_child_method_name` and `invalid_parent_method_name`
10
+ # class methods to make errors understandable.
9
11
  #
10
12
  # This would be easier if we could just define an `inherited` callback, but
11
13
  # that won't work since the Sass library will have already been loaded before
@@ -29,6 +31,14 @@ module Sass::Script
29
31
  def self.visit_method
30
32
  :visit_script_#{node_name}
31
33
  end
34
+
35
+ def self.invalid_child_method_name
36
+ :"invalid_#{node_name}_child?"
37
+ end
38
+
39
+ def self.invalid_parent_method_name
40
+ :"invalid_#{node_name}_parent?"
41
+ end
32
42
  end
33
43
  DECL
34
44
  end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SCSSLint
3
- VERSION = '0.29.0'
3
+ VERSION = '0.30.0'
4
4
  end
@@ -93,7 +93,39 @@ describe SCSSLint::CLI do
93
93
 
94
94
  it 'includes all linters except the excluded one' do
95
95
  safe_parse
96
- subject.config.enabled_linters.should == [SCSSLint::Linter::FakeTestLinter2]
96
+ subject.config.enabled_linters.should == \
97
+ [SCSSLint::Linter::FakeTestLinter2]
98
+ end
99
+ end
100
+
101
+ context 'when the require flag is set' do
102
+ let(:flags) { %w[--require uri] }
103
+
104
+ it 'requires the specified file and constants are accessible' do
105
+ safe_parse
106
+ expect { subject.instance_eval %{ URI } }.to_not raise_error
107
+ end
108
+ end
109
+
110
+ context 'when neither format nor out flag is set' do
111
+ let(:flags) { %w[] }
112
+
113
+ it 'sets the default reporter to output to stdout' do
114
+ safe_parse
115
+ subject.options[:reporters].should \
116
+ include([SCSSLint::Reporter::DefaultReporter, :stdout])
117
+ end
118
+ end
119
+
120
+ context 'when the out flag is set' do
121
+ context 'and the path is valid' do
122
+ let(:flags) { %w[--out foo.txt] }
123
+
124
+ it 'sets the default :output to the given path' do
125
+ safe_parse
126
+ subject.options[:reporters].should \
127
+ include([SCSSLint::Reporter::DefaultReporter, 'foo.txt'])
128
+ end
97
129
  end
98
130
  end
99
131
 
@@ -103,7 +135,18 @@ describe SCSSLint::CLI do
103
135
 
104
136
  it 'sets the :reporter option to the correct reporter' do
105
137
  safe_parse
106
- subject.options[:reporter].should == SCSSLint::Reporter::XMLReporter
138
+ subject.options[:reporters].should \
139
+ include([SCSSLint::Reporter::XMLReporter, :stdout])
140
+ end
141
+ end
142
+
143
+ context 'and an out path is specified' do
144
+ let(:flags) { %w[--format XML --out foo.txt] }
145
+
146
+ it 'sets the specified reporter :output to the given path' do
147
+ safe_parse
148
+ subject.options[:reporters].should \
149
+ include([SCSSLint::Reporter::XMLReporter, 'foo.txt'])
107
150
  end
108
151
  end
109
152
 
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::BangFormat do
4
+ context 'when no bang is used' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ color: #000;
8
+ }
9
+ CSS
10
+
11
+ it { should_not report_lint }
12
+ end
13
+
14
+ context 'when !important is used correctly' do
15
+ let(:css) { <<-CSS }
16
+ p {
17
+ color: #000 !important;
18
+ }
19
+ CSS
20
+
21
+ it { should_not report_lint }
22
+ end
23
+
24
+ context 'when !important has no space before' do
25
+ let(:css) { <<-CSS }
26
+ p {
27
+ color: #000!important;
28
+ }
29
+ CSS
30
+
31
+ it { should report_lint line: 2 }
32
+ end
33
+
34
+ context 'when !important has a space after' do
35
+ let(:css) { <<-CSS }
36
+ p {
37
+ color: #000 ! important;
38
+ }
39
+ CSS
40
+
41
+ it { should report_lint line: 2 }
42
+ end
43
+
44
+ context 'when !important has a space after and config allows it' do
45
+ let(:linter_config) { { 'space_before_bang' => true, 'space_after_bang' => true } }
46
+
47
+ let(:css) { <<-CSS }
48
+ p {
49
+ color: #000 ! important;
50
+ }
51
+ CSS
52
+
53
+ it { should_not report_lint }
54
+ end
55
+
56
+ context 'when !important has a space before but config does not allow it' do
57
+ let(:linter_config) { { 'space_before_bang' => false, 'space_after_bang' => true } }
58
+
59
+ let(:css) { <<-CSS }
60
+ p {
61
+ color: #000 ! important;
62
+ }
63
+ CSS
64
+
65
+ it { should report_lint line: 2 }
66
+ end
67
+
68
+ context 'when !important has no spaces around and config allows it' do
69
+ let(:linter_config) { { 'space_before_bang' => false, 'space_after_bang' => false } }
70
+
71
+ let(:css) { <<-CSS }
72
+ p {
73
+ color: #000!important;
74
+ }
75
+ CSS
76
+
77
+ it { should_not report_lint }
78
+ end
79
+ end
@@ -91,4 +91,470 @@ describe SCSSLint::Linter::DeclarationOrder do
91
91
 
92
92
  it { should report_lint }
93
93
  end
94
+
95
+ context 'when nested rule set' do
96
+ context 'contains @extend before a property' do
97
+ let(:css) { <<-CSS }
98
+ p {
99
+ a {
100
+ @extend foo;
101
+ color: #f00;
102
+ }
103
+ }
104
+ CSS
105
+
106
+ it { should_not report_lint }
107
+ end
108
+
109
+ context 'contains @extend after a property' do
110
+ let(:css) { <<-CSS }
111
+ p {
112
+ a {
113
+ color: #f00;
114
+ @extend foo;
115
+ }
116
+ }
117
+ CSS
118
+
119
+ it { should report_lint }
120
+ end
121
+
122
+ context 'contains @extend after nested rule set' do
123
+ let(:css) { <<-CSS }
124
+ p {
125
+ a {
126
+ span {
127
+ color: #000;
128
+ }
129
+ @extend foo;
130
+ }
131
+ }
132
+ CSS
133
+
134
+ it { should report_lint }
135
+ end
136
+ end
137
+
138
+ context 'when @include appears' do
139
+ context 'before a property and rule set' do
140
+ let(:css) { <<-CSS }
141
+ .error {
142
+ @include warn;
143
+ color: #f00;
144
+ a {
145
+ color: #ccc;
146
+ }
147
+ }
148
+ CSS
149
+
150
+ it { should_not report_lint }
151
+ end
152
+
153
+ context 'after a property and before a rule set' do
154
+ let(:css) { <<-CSS }
155
+ .error {
156
+ color: #f00;
157
+ @include warn;
158
+ a {
159
+ color: #ccc;
160
+ }
161
+ }
162
+ CSS
163
+
164
+ it { should report_lint }
165
+ end
166
+ end
167
+
168
+ context 'when @include that features @content appears' do
169
+ context 'before a property' do
170
+ let(:css) { <<-CSS }
171
+ .foo {
172
+ @include breakpoint("phone") {
173
+ color: #ccc;
174
+ }
175
+ color: #f00;
176
+ }
177
+ CSS
178
+
179
+ it { should report_lint }
180
+ end
181
+
182
+ context 'after a property' do
183
+ let(:css) { <<-CSS }
184
+ .foo {
185
+ color: #f00;
186
+ @include breakpoint("phone") {
187
+ color: #ccc;
188
+ }
189
+ }
190
+ CSS
191
+
192
+ it { should_not report_lint }
193
+ end
194
+
195
+ context 'before an @extend' do
196
+ let(:css) { <<-CSS }
197
+ .foo {
198
+ @include breakpoint("phone") {
199
+ color: #ccc;
200
+ }
201
+ @extend .bar;
202
+ }
203
+ CSS
204
+
205
+ it { should report_lint }
206
+ end
207
+
208
+ context 'before a rule set' do
209
+ let(:css) { <<-CSS }
210
+ .foo {
211
+ @include breakpoint("phone") {
212
+ color: #ccc;
213
+ }
214
+ a {
215
+ color: #fff;
216
+ }
217
+ }
218
+ CSS
219
+
220
+ it { should_not report_lint }
221
+ end
222
+
223
+ context 'after a rule set' do
224
+ let(:css) { <<-CSS }
225
+ .foo {
226
+ a {
227
+ color: #fff;
228
+ }
229
+ @include breakpoint("phone") {
230
+ color: #ccc;
231
+ }
232
+ }
233
+ CSS
234
+
235
+ it { should report_lint }
236
+ end
237
+
238
+ context 'with its own nested rule set' do
239
+ context 'before a property' do
240
+ let(:css) { <<-CSS }
241
+ @include breakpoint("phone") {
242
+ a {
243
+ color: #000;
244
+ }
245
+ color: #ccc;
246
+ }
247
+ CSS
248
+
249
+ it { should report_lint }
250
+ end
251
+
252
+ context 'after a property' do
253
+ let(:css) { <<-CSS }
254
+ @include breakpoint("phone") {
255
+ color: #ccc;
256
+ a {
257
+ color: #000;
258
+ }
259
+ }
260
+ CSS
261
+
262
+ it { should_not report_lint }
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'when the nesting is crazy deep' do
268
+ context 'and nothing is wrong' do
269
+ let(:css) { <<-CSS }
270
+ div {
271
+ ul {
272
+ @extend .thing;
273
+ li {
274
+ @include box-shadow(yes);
275
+ background: green;
276
+ a {
277
+ span {
278
+ @include border-radius(5px);
279
+ color: #000;
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ CSS
286
+
287
+ it { should_not report_lint }
288
+ end
289
+
290
+ context 'and something is wrong' do
291
+ let(:css) { <<-CSS }
292
+ div {
293
+ ul {
294
+ li {
295
+ a {
296
+ span {
297
+ color: #000;
298
+ @include border-radius(5px);
299
+ }
300
+ }
301
+ }
302
+ }
303
+ }
304
+ CSS
305
+
306
+ it { should report_lint }
307
+ end
308
+ end
309
+
310
+ context 'when inside a @media query and rule set' do
311
+ context 'contains @extend before a property' do
312
+ let(:css) { <<-CSS }
313
+ @media only screen and (max-width: 1px) {
314
+ a {
315
+ @extend foo;
316
+ color: #f00;
317
+ }
318
+ }
319
+ CSS
320
+
321
+ it { should_not report_lint }
322
+ end
323
+
324
+ context 'contains @extend after a property' do
325
+ let(:css) { <<-CSS }
326
+ @media only screen and (max-width: 1px) {
327
+ a {
328
+ color: #f00;
329
+ @extend foo;
330
+ }
331
+ }
332
+ CSS
333
+
334
+ it { should report_lint }
335
+ end
336
+
337
+ context 'contains @extend after nested rule set' do
338
+ let(:css) { <<-CSS }
339
+ @media only screen and (max-width: 1px) {
340
+ a {
341
+ span {
342
+ color: #000;
343
+ }
344
+ @extend foo;
345
+ }
346
+ }
347
+ CSS
348
+
349
+ it { should report_lint }
350
+ end
351
+ end
352
+
353
+ context 'when a pseudo-element appears before a property' do
354
+ let(:css) { <<-CSS }
355
+ a {
356
+ &:hover {
357
+ color: #000;
358
+ }
359
+ color: #fff;
360
+ }
361
+ CSS
362
+
363
+ it { should report_lint }
364
+ end
365
+
366
+ context 'when a pseudo-element appears after a property' do
367
+ let(:css) { <<-CSS }
368
+ a {
369
+ color: #fff;
370
+ &:focus {
371
+ color: #000;
372
+ }
373
+ }
374
+ CSS
375
+
376
+ it { should_not report_lint }
377
+ end
378
+
379
+ context 'when a chained selector appears after a property' do
380
+ let(:css) { <<-CSS }
381
+ a {
382
+ color: #fff;
383
+ &.is-active {
384
+ color: #000;
385
+ }
386
+ }
387
+ CSS
388
+
389
+ it { should_not report_lint }
390
+ end
391
+
392
+ context 'when a chained selector appears before a property' do
393
+ let(:css) { <<-CSS }
394
+ a {
395
+ &.is-active {
396
+ color: #000;
397
+ }
398
+ color: #fff;
399
+ }
400
+ CSS
401
+
402
+ it { should report_lint }
403
+ end
404
+
405
+ context 'when a selector with parent reference appears after a property' do
406
+ let(:css) { <<-CSS }
407
+ a {
408
+ color: #fff;
409
+ .is-active & {
410
+ color: #000;
411
+ }
412
+ }
413
+ CSS
414
+
415
+ it { should_not report_lint }
416
+ end
417
+
418
+ context 'when a selector with parent reference appears before a property' do
419
+ let(:css) { <<-CSS }
420
+ a {
421
+ .is-active & {
422
+ color: #000;
423
+ }
424
+ color: #fff;
425
+ }
426
+ CSS
427
+
428
+ it { should report_lint }
429
+ end
430
+
431
+ context 'when a pseudo-element appears after a property' do
432
+ let(:css) { <<-CSS }
433
+ a {
434
+ color: #fff;
435
+ &:before {
436
+ color: #000;
437
+ }
438
+ }
439
+ CSS
440
+
441
+ it { should_not report_lint }
442
+ end
443
+
444
+ context 'when a pseudo-element appears before a property' do
445
+ let(:css) { <<-CSS }
446
+ a {
447
+ &:before {
448
+ color: #000;
449
+ }
450
+ color: #fff;
451
+ }
452
+ CSS
453
+
454
+ it { should report_lint }
455
+ end
456
+
457
+ context 'when a direct descendent appears after a property' do
458
+ let(:css) { <<-CSS }
459
+ a {
460
+ color: #fff;
461
+ > .foo {
462
+ color: #000;
463
+ }
464
+ }
465
+ CSS
466
+
467
+ it { should_not report_lint }
468
+ end
469
+
470
+ context 'when a direct descendent appears before a property' do
471
+ let(:css) { <<-CSS }
472
+ a {
473
+ > .foo {
474
+ color: #000;
475
+ }
476
+ color: #fff;
477
+ }
478
+ CSS
479
+
480
+ it { should report_lint }
481
+ end
482
+
483
+ context 'when an adjacent sibling appears after a property' do
484
+ let(:css) { <<-CSS }
485
+ a {
486
+ color: #fff;
487
+ & + .foo {
488
+ color: #000;
489
+ }
490
+ }
491
+ CSS
492
+
493
+ it { should_not report_lint }
494
+ end
495
+
496
+ context 'when an adjacent sibling appears before a property' do
497
+ let(:css) { <<-CSS }
498
+ a {
499
+ & + .foo {
500
+ color: #000;
501
+ }
502
+ color: #fff;
503
+ }
504
+ CSS
505
+
506
+ it { should report_lint }
507
+ end
508
+
509
+ context 'when a general sibling appears after a property' do
510
+ let(:css) { <<-CSS }
511
+ a {
512
+ color: #fff;
513
+ & ~ .foo {
514
+ color: #000;
515
+ }
516
+ }
517
+ CSS
518
+
519
+ it { should_not report_lint }
520
+ end
521
+
522
+ context 'when a general sibling appears before a property' do
523
+ let(:css) { <<-CSS }
524
+ a {
525
+ & ~ .foo {
526
+ color: #000;
527
+ }
528
+ color: #fff;
529
+ }
530
+ CSS
531
+
532
+ it { should report_lint }
533
+ end
534
+
535
+ context 'when a descendent appears after a property' do
536
+ let(:css) { <<-CSS }
537
+ a {
538
+ color: #fff;
539
+ .foo {
540
+ color: #000;
541
+ }
542
+ }
543
+ CSS
544
+
545
+ it { should_not report_lint }
546
+ end
547
+
548
+ context 'when a descendent appears before a property' do
549
+ let(:css) { <<-CSS }
550
+ a {
551
+ .foo {
552
+ color: #000;
553
+ }
554
+ color: #fff;
555
+ }
556
+ CSS
557
+
558
+ it { should report_lint }
559
+ end
94
560
  end