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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +19 -1
  3. data/data/properties.txt +4 -0
  4. data/lib/scss_lint.rb +1 -0
  5. data/lib/scss_lint/cli.rb +4 -42
  6. data/lib/scss_lint/config.rb +1 -45
  7. data/lib/scss_lint/control_comment_processor.rb +47 -15
  8. data/lib/scss_lint/file_finder.rb +57 -0
  9. data/lib/scss_lint/linter/bang_format.rb +1 -1
  10. data/lib/scss_lint/linter/border_zero.rb +25 -9
  11. data/lib/scss_lint/linter/color_keyword.rb +3 -13
  12. data/lib/scss_lint/linter/color_variable.rb +36 -0
  13. data/lib/scss_lint/linter/declaration_order.rb +2 -2
  14. data/lib/scss_lint/linter/important_rule.rb +12 -0
  15. data/lib/scss_lint/linter/indentation.rb +7 -1
  16. data/lib/scss_lint/linter/property_count.rb +44 -0
  17. data/lib/scss_lint/linter/property_sort_order.rb +73 -19
  18. data/lib/scss_lint/linter/string_quotes.rb +9 -0
  19. data/lib/scss_lint/linter/variable_for_property.rb +20 -0
  20. data/lib/scss_lint/linter/vendor_prefixes.rb +3 -3
  21. data/lib/scss_lint/runner.rb +5 -7
  22. data/lib/scss_lint/utils.rb +34 -0
  23. data/lib/scss_lint/version.rb +1 -1
  24. data/spec/scss_lint/cli_spec.rb +1 -1
  25. data/spec/scss_lint/config_spec.rb +4 -203
  26. data/spec/scss_lint/engine_spec.rb +4 -4
  27. data/spec/scss_lint/file_finder_spec.rb +110 -0
  28. data/spec/scss_lint/linter/bang_format_spec.rb +28 -18
  29. data/spec/scss_lint/linter/border_zero_spec.rb +50 -16
  30. data/spec/scss_lint/linter/color_keyword_spec.rb +16 -16
  31. data/spec/scss_lint/linter/color_variable_spec.rb +102 -0
  32. data/spec/scss_lint/linter/comment_spec.rb +9 -9
  33. data/spec/scss_lint/linter/compass/property_with_mixin_spec.rb +10 -10
  34. data/spec/scss_lint/linter/debug_statement_spec.rb +4 -4
  35. data/spec/scss_lint/linter/declaration_order_spec.rb +80 -80
  36. data/spec/scss_lint/linter/duplicate_property_spec.rb +30 -30
  37. data/spec/scss_lint/linter/else_placement_spec.rb +16 -16
  38. data/spec/scss_lint/linter/empty_line_between_blocks_spec.rb +38 -38
  39. data/spec/scss_lint/linter/empty_rule_spec.rb +4 -4
  40. data/spec/scss_lint/linter/final_newline_spec.rb +6 -6
  41. data/spec/scss_lint/linter/hex_length_spec.rb +16 -16
  42. data/spec/scss_lint/linter/hex_notation_spec.rb +16 -16
  43. data/spec/scss_lint/linter/hex_validation_spec.rb +6 -6
  44. data/spec/scss_lint/linter/id_selector_spec.rb +10 -10
  45. data/spec/scss_lint/linter/import_path_spec.rb +45 -45
  46. data/spec/scss_lint/linter/important_rule_spec.rb +43 -0
  47. data/spec/scss_lint/linter/indentation_spec.rb +103 -43
  48. data/spec/scss_lint/linter/leading_zero_spec.rb +45 -45
  49. data/spec/scss_lint/linter/mergeable_selector_spec.rb +32 -32
  50. data/spec/scss_lint/linter/name_format_spec.rb +75 -41
  51. data/spec/scss_lint/linter/nesting_depth_spec.rb +14 -14
  52. data/spec/scss_lint/linter/placeholder_in_extend_spec.rb +12 -12
  53. data/spec/scss_lint/linter/property_count_spec.rb +104 -0
  54. data/spec/scss_lint/linter/property_sort_order_spec.rb +138 -48
  55. data/spec/scss_lint/linter/property_spelling_spec.rb +14 -14
  56. data/spec/scss_lint/linter/qualifying_element_spec.rb +26 -26
  57. data/spec/scss_lint/linter/selector_depth_spec.rb +26 -26
  58. data/spec/scss_lint/linter/selector_format_spec.rb +114 -114
  59. data/spec/scss_lint/linter/shorthand_spec.rb +32 -32
  60. data/spec/scss_lint/linter/single_line_per_property_spec.rb +10 -10
  61. data/spec/scss_lint/linter/single_line_per_selector_spec.rb +24 -24
  62. data/spec/scss_lint/linter/space_after_comma_spec.rb +60 -60
  63. data/spec/scss_lint/linter/space_after_property_colon_spec.rb +44 -44
  64. data/spec/scss_lint/linter/space_after_property_name_spec.rb +6 -6
  65. data/spec/scss_lint/linter/space_before_brace_spec.rb +119 -119
  66. data/spec/scss_lint/linter/space_between_parens_spec.rb +48 -48
  67. data/spec/scss_lint/linter/string_quotes_spec.rb +74 -62
  68. data/spec/scss_lint/linter/trailing_semicolon_spec.rb +53 -54
  69. data/spec/scss_lint/linter/trailing_zero_spec.rb +34 -34
  70. data/spec/scss_lint/linter/unnecessary_mantissa_spec.rb +10 -10
  71. data/spec/scss_lint/linter/unnecessary_parent_reference_spec.rb +18 -18
  72. data/spec/scss_lint/linter/url_format_spec.rb +4 -4
  73. data/spec/scss_lint/linter/url_quotes_spec.rb +14 -14
  74. data/spec/scss_lint/linter/variable_for_property_spec.rb +115 -0
  75. data/spec/scss_lint/linter/vendor_prefixes_spec.rb +66 -56
  76. data/spec/scss_lint/linter/zero_unit_spec.rb +22 -22
  77. data/spec/scss_lint/linter_spec.rb +72 -28
  78. data/spec/scss_lint/runner_spec.rb +0 -1
  79. data/spec/scss_lint/selector_visitor_spec.rb +23 -23
  80. data/spec/spec_helper.rb +2 -2
  81. metadata +27 -12
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe SCSSLint::Linter::MergeableSelector do
4
4
  context 'when single root' do
5
- let(:css) { <<-CSS }
5
+ let(:scss) { <<-SCSS }
6
6
  p {
7
7
  }
8
- CSS
8
+ SCSS
9
9
 
10
10
  it { should_not report_lint }
11
11
  end
12
12
 
13
13
  context 'when different roots' do
14
- let(:css) { <<-CSS }
14
+ let(:scss) { <<-SCSS }
15
15
  p {
16
16
  background: #000;
17
17
  margin: 5px;
@@ -20,13 +20,13 @@ describe SCSSLint::Linter::MergeableSelector do
20
20
  background: #000;
21
21
  margin: 5px;
22
22
  }
23
- CSS
23
+ SCSS
24
24
 
25
25
  it { should_not report_lint }
26
26
  end
27
27
 
28
28
  context 'when different roots with matching inner rules' do
29
- let(:css) { <<-CSS }
29
+ let(:scss) { <<-SCSS }
30
30
  p {
31
31
  background: #000;
32
32
  margin: 5px;
@@ -41,13 +41,13 @@ describe SCSSLint::Linter::MergeableSelector do
41
41
  color: red;
42
42
  }
43
43
  }
44
- CSS
44
+ SCSS
45
45
 
46
46
  it { should_not report_lint }
47
47
  end
48
48
 
49
49
  context 'when multi-selector roots and parital rule match' do
50
- let(:css) { <<-CSS }
50
+ let(:scss) { <<-SCSS }
51
51
  p, a {
52
52
  background: #000;
53
53
  margin: 5px;
@@ -62,13 +62,13 @@ describe SCSSLint::Linter::MergeableSelector do
62
62
  color: red;
63
63
  }
64
64
  }
65
- CSS
65
+ SCSS
66
66
 
67
67
  it { should_not report_lint }
68
68
  end
69
69
 
70
70
  context 'when nested and unnested selectors match' do
71
- let(:css) { <<-CSS }
71
+ let(:scss) { <<-SCSS }
72
72
  a.current {
73
73
  background: #000;
74
74
  margin: 5px;
@@ -85,7 +85,7 @@ describe SCSSLint::Linter::MergeableSelector do
85
85
  }
86
86
  }
87
87
  }
88
- CSS
88
+ SCSS
89
89
 
90
90
  context 'when force_nesting is enabled' do
91
91
  let(:linter_config) { { 'force_nesting' => true } }
@@ -99,7 +99,7 @@ describe SCSSLint::Linter::MergeableSelector do
99
99
  end
100
100
 
101
101
  context 'when same class roots' do
102
- let(:css) { <<-CSS }
102
+ let(:scss) { <<-SCSS }
103
103
  .warn {
104
104
  font-weight: bold;
105
105
  }
@@ -110,13 +110,13 @@ describe SCSSLint::Linter::MergeableSelector do
110
110
  color: #ccc;
111
111
  }
112
112
  }
113
- CSS
113
+ SCSS
114
114
 
115
115
  it { should report_lint }
116
116
  end
117
117
 
118
118
  context 'when same compond selector roots' do
119
- let(:css) { <<-CSS }
119
+ let(:scss) { <<-SCSS }
120
120
  .warn .alert {
121
121
  font-weight: bold;
122
122
  }
@@ -127,13 +127,13 @@ describe SCSSLint::Linter::MergeableSelector do
127
127
  color: #ccc;
128
128
  }
129
129
  }
130
- CSS
130
+ SCSS
131
131
 
132
132
  it { should report_lint }
133
133
  end
134
134
 
135
135
  context 'when same class roots separated by another class' do
136
- let(:css) { <<-CSS }
136
+ let(:scss) { <<-SCSS }
137
137
  .warn {
138
138
  font-weight: bold;
139
139
  }
@@ -147,13 +147,13 @@ describe SCSSLint::Linter::MergeableSelector do
147
147
  color: #ccc;
148
148
  }
149
149
  }
150
- CSS
150
+ SCSS
151
151
 
152
152
  it { should report_lint }
153
153
  end
154
154
 
155
155
  context 'when rule in a mixin @include matches a root root' do
156
- let(:css) { <<-CSS }
156
+ let(:scss) { <<-SCSS }
157
157
  p {
158
158
  font-weight: bold;
159
159
  }
@@ -162,13 +162,13 @@ describe SCSSLint::Linter::MergeableSelector do
162
162
  font-weight: normal;
163
163
  }
164
164
  }
165
- CSS
165
+ SCSS
166
166
 
167
167
  it { should_not report_lint }
168
168
  end
169
169
 
170
170
  context 'when rule in a mixin definition matches a root rule' do
171
- let(:css) { <<-CSS }
171
+ let(:scss) { <<-SCSS }
172
172
  p {
173
173
  font-weight: bold;
174
174
  }
@@ -177,13 +177,13 @@ describe SCSSLint::Linter::MergeableSelector do
177
177
  font-weight: normal;
178
178
  }
179
179
  }
180
- CSS
180
+ SCSS
181
181
 
182
182
  it { should_not report_lint }
183
183
  end
184
184
 
185
185
  context 'when rule in a media directive matches a root rule' do
186
- let(:css) { <<-CSS }
186
+ let(:scss) { <<-SCSS }
187
187
  p {
188
188
  font-weight: bold;
189
189
  }
@@ -192,13 +192,13 @@ describe SCSSLint::Linter::MergeableSelector do
192
192
  font-weight: normal;
193
193
  }
194
194
  }
195
- CSS
195
+ SCSS
196
196
 
197
197
  it { should_not report_lint }
198
198
  end
199
199
 
200
200
  context 'when rule in a keyframes directive matches a root rule' do
201
- let(:css) { <<-CSS }
201
+ let(:scss) { <<-SCSS }
202
202
  @keyframes slideouttoleft {
203
203
  from {
204
204
  transform: translateX(0);
@@ -218,13 +218,13 @@ describe SCSSLint::Linter::MergeableSelector do
218
218
  transform: translateX(100%);
219
219
  }
220
220
  }
221
- CSS
221
+ SCSS
222
222
 
223
223
  it { should_not report_lint }
224
224
  end
225
225
 
226
226
  context 'when there are duplicate rules nested in a rule set' do
227
- let(:css) { <<-CSS }
227
+ let(:scss) { <<-SCSS }
228
228
  .foo {
229
229
  .bar {
230
230
  font-weight: bold;
@@ -236,7 +236,7 @@ describe SCSSLint::Linter::MergeableSelector do
236
236
  color: #ff0;
237
237
  }
238
238
  }
239
- CSS
239
+ SCSS
240
240
 
241
241
  it { should report_lint }
242
242
  end
@@ -245,7 +245,7 @@ describe SCSSLint::Linter::MergeableSelector do
245
245
  let(:linter_config) { { 'force_nesting' => true } }
246
246
 
247
247
  context 'when one of the duplicate rules is in a comma sequence' do
248
- let(:css) { <<-CSS }
248
+ let(:scss) { <<-SCSS }
249
249
  .foo,
250
250
  .bar {
251
251
  color: #000;
@@ -253,29 +253,29 @@ describe SCSSLint::Linter::MergeableSelector do
253
253
  .foo {
254
254
  color: #f00;
255
255
  }
256
- CSS
256
+ SCSS
257
257
 
258
258
  it { should_not report_lint }
259
259
  end
260
260
 
261
261
  context 'when rules start with the same prefix but are not the same' do
262
- let(:css) { <<-CSS }
262
+ let(:scss) { <<-SCSS }
263
263
  .foo {
264
264
  color: #000;
265
265
  }
266
266
  .foobar {
267
267
  color: #f00;
268
268
  }
269
- CSS
269
+ SCSS
270
270
 
271
271
  it { should_not report_lint }
272
272
  end
273
273
 
274
274
  context 'when a rule contains interpolation' do
275
- let(:css) { <<-CSS }
275
+ let(:scss) { <<-SCSS }
276
276
  .\#{$class-name} {}
277
277
  .foobar {}
278
- CSS
278
+ SCSS
279
279
 
280
280
  it { should_not report_lint }
281
281
  end
@@ -3,127 +3,127 @@ require 'spec_helper'
3
3
  describe SCSSLint::Linter::NameFormat do
4
4
  shared_examples 'hyphenated_lowercase' do
5
5
  context 'when no variable, functions, or mixin declarations exist' do
6
- let(:css) { <<-CSS }
6
+ let(:scss) { <<-SCSS }
7
7
  p {
8
8
  margin: 0;
9
9
  }
10
- CSS
10
+ SCSS
11
11
 
12
12
  it { should_not report_lint }
13
13
  end
14
14
 
15
15
  context 'when a variable name contains a hyphen' do
16
- let(:css) { '$content-padding: 10px;' }
16
+ let(:scss) { '$content-padding: 10px;' }
17
17
 
18
18
  it { should_not report_lint }
19
19
  end
20
20
 
21
21
  context 'when a variable name contains an underscore' do
22
- let(:css) { '$content_padding: 10px;' }
22
+ let(:scss) { '$content_padding: 10px;' }
23
23
 
24
24
  it { should report_lint line: 1 }
25
25
  end
26
26
 
27
27
  context 'when a variable name contains an uppercase character' do
28
- let(:css) { '$contentPadding: 10px;' }
28
+ let(:scss) { '$contentPadding: 10px;' }
29
29
 
30
30
  it { should report_lint line: 1 }
31
31
  end
32
32
 
33
33
  context 'when a function is declared with a capital letter' do
34
- let(:css) { <<-CSS }
34
+ let(:scss) { <<-SCSS }
35
35
  @function badFunction() {
36
36
  }
37
- CSS
37
+ SCSS
38
38
 
39
39
  it { should report_lint line: 1 }
40
40
  end
41
41
 
42
42
  context 'when a function is declared with an underscore' do
43
- let(:css) { <<-CSS }
43
+ let(:scss) { <<-SCSS }
44
44
  @function bad_function() {
45
45
  }
46
- CSS
46
+ SCSS
47
47
 
48
48
  it { should report_lint line: 1 }
49
49
  end
50
50
 
51
51
  context 'when a mixin is declared with a capital letter' do
52
- let(:css) { <<-CSS }
52
+ let(:scss) { <<-SCSS }
53
53
  @mixin badMixin() {
54
54
  }
55
- CSS
55
+ SCSS
56
56
 
57
57
  it { should report_lint line: 1 }
58
58
  end
59
59
 
60
60
  context 'when a mixin is declared with an underscore' do
61
- let(:css) { <<-CSS }
61
+ let(:scss) { <<-SCSS }
62
62
  @mixin bad_mixin() {
63
63
  }
64
- CSS
64
+ SCSS
65
65
 
66
66
  it { should report_lint line: 1 }
67
67
  end
68
68
 
69
69
  context 'when no invalid usages exist' do
70
- let(:css) { <<-CSS }
70
+ let(:scss) { <<-SCSS }
71
71
  p {
72
72
  margin: 0;
73
73
  }
74
- CSS
74
+ SCSS
75
75
 
76
76
  it { should_not report_lint }
77
77
  end
78
78
 
79
79
  context 'when a referenced variable name has a capital letter' do
80
- let(:css) { <<-CSS }
80
+ let(:scss) { <<-SCSS }
81
81
  p {
82
82
  margin: $badVar;
83
83
  }
84
- CSS
84
+ SCSS
85
85
 
86
86
  it { should report_lint line: 2 }
87
87
  end
88
88
 
89
89
  context 'when a referenced variable name has an underscore' do
90
- let(:css) { <<-CSS }
90
+ let(:scss) { <<-SCSS }
91
91
  p {
92
92
  margin: $bad_var;
93
93
  }
94
- CSS
94
+ SCSS
95
95
 
96
96
  it { should report_lint line: 2 }
97
97
  end
98
98
 
99
99
  context 'when a referenced function name has a capital letter' do
100
- let(:css) { <<-CSS }
100
+ let(:scss) { <<-SCSS }
101
101
  p {
102
102
  margin: badFunc();
103
103
  }
104
- CSS
104
+ SCSS
105
105
 
106
106
  it { should report_lint line: 2 }
107
107
  end
108
108
 
109
109
  context 'when a referenced function name has an underscore' do
110
- let(:css) { <<-CSS }
110
+ let(:scss) { <<-SCSS }
111
111
  p {
112
112
  margin: bad_func();
113
113
  }
114
- CSS
114
+ SCSS
115
115
 
116
116
  it { should report_lint line: 2 }
117
117
  end
118
118
 
119
119
  context 'when an included mixin name has a capital letter' do
120
- let(:css) { '@include badMixin();' }
120
+ let(:scss) { '@include badMixin();' }
121
121
 
122
122
  it { should report_lint line: 1 }
123
123
  end
124
124
 
125
125
  context 'when an included mixin name has an underscore' do
126
- let(:css) { '@include bad_mixin();' }
126
+ let(:scss) { '@include bad_mixin();' }
127
127
 
128
128
  it { should report_lint line: 1 }
129
129
  end
@@ -133,34 +133,34 @@ describe SCSSLint::Linter::NameFormat do
133
133
  scaleX scaleY scaleZ
134
134
  skewX skewY
135
135
  translateX translateY translateZ].each do |function|
136
- let(:css) { <<-CSS }
136
+ let(:scss) { <<-SCSS }
137
137
  p {
138
138
  transform: #{function}(2);
139
139
  }
140
- CSS
140
+ SCSS
141
141
 
142
142
  it { should_not report_lint }
143
143
  end
144
144
  end
145
145
 
146
146
  context 'when mixin is a transform function' do
147
- let(:css) { <<-CSS }
147
+ let(:scss) { <<-SCSS }
148
148
  p {
149
149
  @include translateX(2);
150
150
  }
151
- CSS
151
+ SCSS
152
152
 
153
153
  it { should_not report_lint }
154
154
  end
155
155
 
156
156
  context 'when a mixin contains keyword arguments with underscores' do
157
- let(:css) { '@include mixin($some_var: 4);' }
157
+ let(:scss) { '@include mixin($some_var: 4);' }
158
158
 
159
159
  it { should report_lint }
160
160
  end
161
161
 
162
162
  context 'when a mixin contains keyword arguments with hyphens' do
163
- let(:css) { '@include mixin($some-var: 4);' }
163
+ let(:scss) { '@include mixin($some-var: 4);' }
164
164
 
165
165
  it { should_not report_lint }
166
166
  end
@@ -170,10 +170,10 @@ describe SCSSLint::Linter::NameFormat do
170
170
  it_behaves_like 'hyphenated_lowercase'
171
171
 
172
172
  context 'when a name contains a leading underscore' do
173
- let(:css) { <<-CSS }
173
+ let(:scss) { <<-SCSS }
174
174
  @function _private-method() {
175
175
  }
176
- CSS
176
+ SCSS
177
177
 
178
178
  it { should_not report_lint }
179
179
  end
@@ -185,10 +185,10 @@ describe SCSSLint::Linter::NameFormat do
185
185
  it_behaves_like 'hyphenated_lowercase'
186
186
 
187
187
  context 'when a name contains a leading underscore' do
188
- let(:css) { <<-CSS }
188
+ let(:scss) { <<-SCSS }
189
189
  @function _private-method() {
190
190
  }
191
- CSS
191
+ SCSS
192
192
 
193
193
  it { should report_lint line: 1 }
194
194
  end
@@ -198,39 +198,73 @@ describe SCSSLint::Linter::NameFormat do
198
198
  let(:linter_config) { { 'convention' => 'BEM' } }
199
199
 
200
200
  context 'when a name contains no underscores or hyphens' do
201
- let(:css) { '@extend %block;' }
201
+ let(:scss) { '@extend %block;' }
202
202
 
203
203
  it { should_not report_lint }
204
204
  end
205
205
 
206
206
  context 'when a name contains a single underscore' do
207
- let(:css) { '@extend %block_thing;' }
207
+ let(:scss) { '@extend %block_thing;' }
208
208
 
209
209
  it { should report_lint }
210
210
  end
211
211
 
212
212
  context 'when a name contains a single hyphen' do
213
- let(:css) { '@extend %block-thing;' }
213
+ let(:scss) { '@extend %block-thing;' }
214
214
 
215
215
  it { should_not report_lint }
216
216
  end
217
217
 
218
218
  context 'when a name contains a double hyphen' do
219
- let(:css) { '@extend %block--thing;' }
219
+ let(:scss) { '@extend %block--thing;' }
220
220
 
221
221
  it { should_not report_lint }
222
222
  end
223
223
 
224
224
  context 'when a name contains a double underscore' do
225
- let(:css) { '@extend %block__thing;' }
225
+ let(:scss) { '@extend %block__thing;' }
226
226
 
227
227
  it { should_not report_lint }
228
228
  end
229
229
 
230
230
  context 'when a name contains a double underscore and double hyphen' do
231
- let(:css) { '@extend %block--thing__word;' }
231
+ let(:scss) { '@extend %block--thing__word;' }
232
232
 
233
233
  it { should_not report_lint }
234
234
  end
235
235
  end
236
+
237
+ context 'when a regexp convention is specified' do
238
+ let(:linter_config) { { 'convention' => '^[a-v_-]+$' } }
239
+
240
+ context 'when a name contains no underscores or hyphens' do
241
+ let(:scss) { '@extend %block;' }
242
+
243
+ it { should_not report_lint }
244
+ end
245
+
246
+ context 'when a name contains a single underscore' do
247
+ let(:scss) { '@extend %block_thing;' }
248
+
249
+ it { should_not report_lint }
250
+ end
251
+
252
+ context 'when a name contains a single hyphen' do
253
+ let(:scss) { '@extend %block-thing;' }
254
+
255
+ it { should_not report_lint }
256
+ end
257
+
258
+ context 'when a name contains a uppercase character' do
259
+ let(:scss) { '@extend Block-thing;' }
260
+
261
+ it { should report_lint }
262
+ end
263
+
264
+ context 'when a name contains an unallowed character' do
265
+ let(:scss) { '@extend zoo;' }
266
+
267
+ it { should report_lint }
268
+ end
269
+ end
236
270
  end