scss_lint 0.38.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/scss-lint +6 -0
- data/config/default.yml +205 -0
- data/data/prefixed-identifiers/base.txt +107 -0
- data/data/prefixed-identifiers/bourbon.txt +71 -0
- data/data/properties.txt +477 -0
- data/data/property-sort-orders/concentric.txt +134 -0
- data/data/property-sort-orders/recess.txt +149 -0
- data/data/property-sort-orders/smacss.txt +137 -0
- data/lib/scss_lint.rb +31 -0
- data/lib/scss_lint/cli.rb +215 -0
- data/lib/scss_lint/config.rb +251 -0
- data/lib/scss_lint/constants.rb +8 -0
- data/lib/scss_lint/control_comment_processor.rb +126 -0
- data/lib/scss_lint/engine.rb +56 -0
- data/lib/scss_lint/exceptions.rb +21 -0
- data/lib/scss_lint/file_finder.rb +68 -0
- data/lib/scss_lint/lint.rb +24 -0
- data/lib/scss_lint/linter.rb +161 -0
- data/lib/scss_lint/linter/bang_format.rb +52 -0
- data/lib/scss_lint/linter/border_zero.rb +39 -0
- data/lib/scss_lint/linter/color_keyword.rb +32 -0
- data/lib/scss_lint/linter/color_variable.rb +60 -0
- data/lib/scss_lint/linter/comment.rb +21 -0
- data/lib/scss_lint/linter/compass.rb +7 -0
- data/lib/scss_lint/linter/compass/property_with_mixin.rb +47 -0
- data/lib/scss_lint/linter/debug_statement.rb +10 -0
- data/lib/scss_lint/linter/declaration_order.rb +71 -0
- data/lib/scss_lint/linter/duplicate_property.rb +58 -0
- data/lib/scss_lint/linter/else_placement.rb +48 -0
- data/lib/scss_lint/linter/empty_line_between_blocks.rb +85 -0
- data/lib/scss_lint/linter/empty_rule.rb +11 -0
- data/lib/scss_lint/linter/final_newline.rb +20 -0
- data/lib/scss_lint/linter/hex_length.rb +56 -0
- data/lib/scss_lint/linter/hex_notation.rb +38 -0
- data/lib/scss_lint/linter/hex_validation.rb +23 -0
- data/lib/scss_lint/linter/id_selector.rb +10 -0
- data/lib/scss_lint/linter/import_path.rb +62 -0
- data/lib/scss_lint/linter/important_rule.rb +12 -0
- data/lib/scss_lint/linter/indentation.rb +197 -0
- data/lib/scss_lint/linter/leading_zero.rb +49 -0
- data/lib/scss_lint/linter/mergeable_selector.rb +60 -0
- data/lib/scss_lint/linter/name_format.rb +117 -0
- data/lib/scss_lint/linter/nesting_depth.rb +24 -0
- data/lib/scss_lint/linter/placeholder_in_extend.rb +22 -0
- data/lib/scss_lint/linter/property_count.rb +44 -0
- data/lib/scss_lint/linter/property_sort_order.rb +198 -0
- data/lib/scss_lint/linter/property_spelling.rb +49 -0
- data/lib/scss_lint/linter/property_units.rb +59 -0
- data/lib/scss_lint/linter/qualifying_element.rb +42 -0
- data/lib/scss_lint/linter/selector_depth.rb +64 -0
- data/lib/scss_lint/linter/selector_format.rb +102 -0
- data/lib/scss_lint/linter/shorthand.rb +139 -0
- data/lib/scss_lint/linter/single_line_per_property.rb +59 -0
- data/lib/scss_lint/linter/single_line_per_selector.rb +35 -0
- data/lib/scss_lint/linter/space_after_comma.rb +110 -0
- data/lib/scss_lint/linter/space_after_property_colon.rb +92 -0
- data/lib/scss_lint/linter/space_after_property_name.rb +27 -0
- data/lib/scss_lint/linter/space_before_brace.rb +72 -0
- data/lib/scss_lint/linter/space_between_parens.rb +35 -0
- data/lib/scss_lint/linter/string_quotes.rb +94 -0
- data/lib/scss_lint/linter/trailing_semicolon.rb +67 -0
- data/lib/scss_lint/linter/trailing_zero.rb +41 -0
- data/lib/scss_lint/linter/unnecessary_mantissa.rb +42 -0
- data/lib/scss_lint/linter/unnecessary_parent_reference.rb +49 -0
- data/lib/scss_lint/linter/url_format.rb +56 -0
- data/lib/scss_lint/linter/url_quotes.rb +27 -0
- data/lib/scss_lint/linter/variable_for_property.rb +30 -0
- data/lib/scss_lint/linter/vendor_prefix.rb +64 -0
- data/lib/scss_lint/linter/zero_unit.rb +39 -0
- data/lib/scss_lint/linter_registry.rb +26 -0
- data/lib/scss_lint/location.rb +38 -0
- data/lib/scss_lint/options.rb +109 -0
- data/lib/scss_lint/rake_task.rb +106 -0
- data/lib/scss_lint/reporter.rb +18 -0
- data/lib/scss_lint/reporter/config_reporter.rb +26 -0
- data/lib/scss_lint/reporter/default_reporter.rb +27 -0
- data/lib/scss_lint/reporter/files_reporter.rb +8 -0
- data/lib/scss_lint/reporter/json_reporter.rb +30 -0
- data/lib/scss_lint/reporter/xml_reporter.rb +33 -0
- data/lib/scss_lint/runner.rb +51 -0
- data/lib/scss_lint/sass/script.rb +78 -0
- data/lib/scss_lint/sass/tree.rb +168 -0
- data/lib/scss_lint/selector_visitor.rb +34 -0
- data/lib/scss_lint/utils.rb +112 -0
- data/lib/scss_lint/version.rb +4 -0
- data/spec/scss_lint/cli_spec.rb +177 -0
- data/spec/scss_lint/config_spec.rb +253 -0
- data/spec/scss_lint/engine_spec.rb +24 -0
- data/spec/scss_lint/file_finder_spec.rb +134 -0
- data/spec/scss_lint/linter/bang_format_spec.rb +121 -0
- data/spec/scss_lint/linter/border_zero_spec.rb +118 -0
- data/spec/scss_lint/linter/color_keyword_spec.rb +83 -0
- data/spec/scss_lint/linter/color_variable_spec.rb +155 -0
- data/spec/scss_lint/linter/comment_spec.rb +79 -0
- data/spec/scss_lint/linter/compass/property_with_mixin_spec.rb +55 -0
- data/spec/scss_lint/linter/debug_statement_spec.rb +21 -0
- data/spec/scss_lint/linter/declaration_order_spec.rb +575 -0
- data/spec/scss_lint/linter/duplicate_property_spec.rb +189 -0
- data/spec/scss_lint/linter/else_placement_spec.rb +106 -0
- data/spec/scss_lint/linter/empty_line_between_blocks_spec.rb +276 -0
- data/spec/scss_lint/linter/empty_rule_spec.rb +27 -0
- data/spec/scss_lint/linter/final_newline_spec.rb +49 -0
- data/spec/scss_lint/linter/hex_length_spec.rb +104 -0
- data/spec/scss_lint/linter/hex_notation_spec.rb +104 -0
- data/spec/scss_lint/linter/hex_validation_spec.rb +40 -0
- data/spec/scss_lint/linter/id_selector_spec.rb +62 -0
- data/spec/scss_lint/linter/import_path_spec.rb +300 -0
- data/spec/scss_lint/linter/important_rule_spec.rb +43 -0
- data/spec/scss_lint/linter/indentation_spec.rb +347 -0
- data/spec/scss_lint/linter/leading_zero_spec.rb +233 -0
- data/spec/scss_lint/linter/mergeable_selector_spec.rb +283 -0
- data/spec/scss_lint/linter/name_format_spec.rb +282 -0
- data/spec/scss_lint/linter/nesting_depth_spec.rb +114 -0
- data/spec/scss_lint/linter/placeholder_in_extend_spec.rb +63 -0
- data/spec/scss_lint/linter/property_count_spec.rb +104 -0
- data/spec/scss_lint/linter/property_sort_order_spec.rb +482 -0
- data/spec/scss_lint/linter/property_spelling_spec.rb +84 -0
- data/spec/scss_lint/linter/property_units_spec.rb +229 -0
- data/spec/scss_lint/linter/qualifying_element_spec.rb +125 -0
- data/spec/scss_lint/linter/selector_depth_spec.rb +159 -0
- data/spec/scss_lint/linter/selector_format_spec.rb +632 -0
- data/spec/scss_lint/linter/shorthand_spec.rb +198 -0
- data/spec/scss_lint/linter/single_line_per_property_spec.rb +73 -0
- data/spec/scss_lint/linter/single_line_per_selector_spec.rb +130 -0
- data/spec/scss_lint/linter/space_after_comma_spec.rb +332 -0
- data/spec/scss_lint/linter/space_after_property_colon_spec.rb +373 -0
- data/spec/scss_lint/linter/space_after_property_name_spec.rb +37 -0
- data/spec/scss_lint/linter/space_before_brace_spec.rb +829 -0
- data/spec/scss_lint/linter/space_between_parens_spec.rb +263 -0
- data/spec/scss_lint/linter/string_quotes_spec.rb +335 -0
- data/spec/scss_lint/linter/trailing_semicolon_spec.rb +304 -0
- data/spec/scss_lint/linter/trailing_zero_spec.rb +176 -0
- data/spec/scss_lint/linter/unnecessary_mantissa_spec.rb +67 -0
- data/spec/scss_lint/linter/unnecessary_parent_reference_spec.rb +98 -0
- data/spec/scss_lint/linter/url_format_spec.rb +55 -0
- data/spec/scss_lint/linter/url_quotes_spec.rb +73 -0
- data/spec/scss_lint/linter/variable_for_property_spec.rb +145 -0
- data/spec/scss_lint/linter/vendor_prefix_spec.rb +371 -0
- data/spec/scss_lint/linter/zero_unit_spec.rb +113 -0
- data/spec/scss_lint/linter_registry_spec.rb +50 -0
- data/spec/scss_lint/linter_spec.rb +292 -0
- data/spec/scss_lint/location_spec.rb +42 -0
- data/spec/scss_lint/options_spec.rb +34 -0
- data/spec/scss_lint/rake_task_spec.rb +43 -0
- data/spec/scss_lint/reporter/config_reporter_spec.rb +42 -0
- data/spec/scss_lint/reporter/default_reporter_spec.rb +73 -0
- data/spec/scss_lint/reporter/files_reporter_spec.rb +38 -0
- data/spec/scss_lint/reporter/json_reporter_spec.rb +96 -0
- data/spec/scss_lint/reporter/xml_reporter_spec.rb +103 -0
- data/spec/scss_lint/reporter_spec.rb +11 -0
- data/spec/scss_lint/runner_spec.rb +123 -0
- data/spec/scss_lint/selector_visitor_spec.rb +264 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/isolated_environment.rb +25 -0
- data/spec/support/matchers/report_lint.rb +48 -0
- metadata +328 -0
@@ -0,0 +1,632 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SCSSLint::Linter::SelectorFormat do
|
4
|
+
context 'when class has alphanumeric chars and is separated by hyphens' do
|
5
|
+
let(:scss) { <<-SCSS }
|
6
|
+
.foo-bar-77 {
|
7
|
+
}
|
8
|
+
SCSS
|
9
|
+
|
10
|
+
it { should_not report_lint }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when id has alphanumeric chars and is separated by hyphens' do
|
14
|
+
let(:scss) { <<-SCSS }
|
15
|
+
#foo-bar-77 {
|
16
|
+
}
|
17
|
+
SCSS
|
18
|
+
|
19
|
+
it { should_not report_lint }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when element has alphanumeric chars and is separated by hyphens' do
|
23
|
+
let(:scss) { <<-SCSS }
|
24
|
+
foo-bar-77 {
|
25
|
+
}
|
26
|
+
SCSS
|
27
|
+
|
28
|
+
it { should_not report_lint }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when placeholder has alphanumeric chars and is separated by hyphens' do
|
32
|
+
let(:scss) { <<-SCSS }
|
33
|
+
%foo-bar-77 {
|
34
|
+
}
|
35
|
+
SCSS
|
36
|
+
|
37
|
+
it { should_not report_lint }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when selector has alphanumeric chars and is separated by underscores' do
|
41
|
+
let(:scss) { <<-SCSS }
|
42
|
+
.foo_bar {
|
43
|
+
}
|
44
|
+
SCSS
|
45
|
+
|
46
|
+
it { should report_lint line: 1 }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when selector is camelCase' do
|
50
|
+
let(:scss) { <<-SCSS }
|
51
|
+
fooBar77 {
|
52
|
+
}
|
53
|
+
SCSS
|
54
|
+
|
55
|
+
it { should report_lint line: 1 }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when placeholder has alphanumeric chars and is separated by underscores' do
|
59
|
+
let(:scss) { <<-SCSS }
|
60
|
+
%foo_bar {
|
61
|
+
}
|
62
|
+
SCSS
|
63
|
+
|
64
|
+
it { should report_lint line: 1 }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when attribute has alphanumeric chars and is separated by underscores' do
|
68
|
+
let(:scss) { <<-SCSS }
|
69
|
+
[data_text] {
|
70
|
+
}
|
71
|
+
SCSS
|
72
|
+
|
73
|
+
it { should report_lint line: 1 }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when attribute selector has alphanumeric chars and is separated by underscores' do
|
77
|
+
let(:scss) { <<-SCSS }
|
78
|
+
[data-text=some_text] {
|
79
|
+
}
|
80
|
+
SCSS
|
81
|
+
|
82
|
+
it { should_not report_lint }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when convention is set to snake_case' do
|
86
|
+
let(:linter_config) { { 'convention' => 'snake_case' } }
|
87
|
+
|
88
|
+
context 'when selector has alphanumeric chars and is separated by underscores' do
|
89
|
+
let(:scss) { <<-SCSS }
|
90
|
+
.foo_bar_77 {
|
91
|
+
}
|
92
|
+
SCSS
|
93
|
+
|
94
|
+
it { should_not report_lint }
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when selector has alphanumeric chars and is separated by hyphens' do
|
98
|
+
let(:scss) { <<-SCSS }
|
99
|
+
.foo-bar-77 {
|
100
|
+
}
|
101
|
+
SCSS
|
102
|
+
|
103
|
+
it { should report_lint line: 1 }
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when selector is in camelCase' do
|
107
|
+
let(:scss) { <<-SCSS }
|
108
|
+
.fooBar77 {
|
109
|
+
}
|
110
|
+
SCSS
|
111
|
+
|
112
|
+
it { should report_lint line: 1 }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when convention is set to camel_case' do
|
117
|
+
let(:linter_config) { { 'convention' => 'camel_case' } }
|
118
|
+
|
119
|
+
context 'when selector is camelCase' do
|
120
|
+
let(:scss) { <<-SCSS }
|
121
|
+
.fooBar77 {
|
122
|
+
}
|
123
|
+
SCSS
|
124
|
+
|
125
|
+
it { should_not report_lint }
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when selector capitalizes first word' do
|
129
|
+
let(:scss) { <<-SCSS }
|
130
|
+
.FooBar77 {
|
131
|
+
}
|
132
|
+
SCSS
|
133
|
+
|
134
|
+
it { should report_lint line: 1 }
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when selector has alphanumeric chars and is separated by underscores' do
|
138
|
+
let(:scss) { <<-SCSS }
|
139
|
+
.foo_bar_77 {
|
140
|
+
}
|
141
|
+
SCSS
|
142
|
+
|
143
|
+
it { should report_lint line: 1 }
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when selector has alphanumeric chars and is separated by hyphens' do
|
147
|
+
let(:scss) { <<-SCSS }
|
148
|
+
.foo-bar-77 {
|
149
|
+
}
|
150
|
+
SCSS
|
151
|
+
|
152
|
+
it { should report_lint line: 1 }
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when convention is set to use a regex' do
|
157
|
+
let(:linter_config) { { 'convention' => /^[0-9]*$/ } }
|
158
|
+
|
159
|
+
context 'when selector uses regex properly' do
|
160
|
+
let(:scss) { <<-SCSS }
|
161
|
+
.1337 {
|
162
|
+
}
|
163
|
+
SCSS
|
164
|
+
|
165
|
+
it { should_not report_lint }
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when selector does not use regex properly' do
|
169
|
+
let(:scss) { <<-SCSS }
|
170
|
+
.leet {
|
171
|
+
}
|
172
|
+
SCSS
|
173
|
+
|
174
|
+
it { should report_lint line: 1 }
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'when ignored names are set' do
|
179
|
+
let(:linter_config) { { 'ignored_names' => ['fooBar'] } }
|
180
|
+
|
181
|
+
context 'it ignores exact string matches' do
|
182
|
+
let(:scss) { <<-SCSS }
|
183
|
+
fooBar {
|
184
|
+
}
|
185
|
+
SCSS
|
186
|
+
|
187
|
+
it { should_not report_lint }
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when ignored types is set to class' do
|
192
|
+
let(:linter_config) { { 'ignored_types' => ['class'] } }
|
193
|
+
|
194
|
+
context 'it ignores all invalid classes' do
|
195
|
+
let(:scss) { <<-SCSS }
|
196
|
+
.fooBar {
|
197
|
+
}
|
198
|
+
SCSS
|
199
|
+
|
200
|
+
it { should_not report_lint }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'when ignored types is set to id, element, placeholder' do
|
205
|
+
let(:linter_config) do
|
206
|
+
{ 'ignored_types' => %w[id attribute element placeholder] }
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'it ignores all invalid ids' do
|
210
|
+
let(:scss) { <<-SCSS }
|
211
|
+
#fooBar {
|
212
|
+
}
|
213
|
+
SCSS
|
214
|
+
|
215
|
+
it { should_not report_lint }
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'it ignores all invalid elements' do
|
219
|
+
let(:scss) { <<-SCSS }
|
220
|
+
fooBar {
|
221
|
+
}
|
222
|
+
SCSS
|
223
|
+
|
224
|
+
it { should_not report_lint }
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'it ignores all invalid placeholders' do
|
228
|
+
let(:scss) { <<-SCSS }
|
229
|
+
%fooBar {
|
230
|
+
}
|
231
|
+
SCSS
|
232
|
+
|
233
|
+
it { should_not report_lint }
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'it ignores all invalid attributes' do
|
237
|
+
let(:scss) { <<-SCSS }
|
238
|
+
[fooBar=fooBar] {
|
239
|
+
}
|
240
|
+
SCSS
|
241
|
+
|
242
|
+
it { should_not report_lint }
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when using a unique `id_convention`' do
|
247
|
+
let(:linter_config) { { 'id_convention' => 'snake_case' } }
|
248
|
+
|
249
|
+
context 'and actual id is correct' do
|
250
|
+
let(:scss) { <<-SCSS }
|
251
|
+
.hyphenated-lowercase {}
|
252
|
+
#snake_case {}
|
253
|
+
SCSS
|
254
|
+
|
255
|
+
it { should_not report_lint }
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'and actual id is incorrect' do
|
259
|
+
let(:scss) { <<-SCSS }
|
260
|
+
.hyphenated-lowercase {}
|
261
|
+
#hyphenated-lowercase {}
|
262
|
+
SCSS
|
263
|
+
|
264
|
+
it { should report_lint line: 2 }
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'and something else uses the `id_convention`' do
|
268
|
+
let(:scss) { <<-SCSS }
|
269
|
+
.snake_case {}
|
270
|
+
#hyphenated-lowercase {}
|
271
|
+
SCSS
|
272
|
+
|
273
|
+
it { should report_lint line: 1 }
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'when using a unique `class_convention`' do
|
278
|
+
let(:linter_config) { { 'class_convention' => 'camel_case' } }
|
279
|
+
|
280
|
+
context 'and actual class is correct' do
|
281
|
+
let(:scss) { <<-SCSS }
|
282
|
+
.camelCase {}
|
283
|
+
#hyphenated-lowercase {}
|
284
|
+
SCSS
|
285
|
+
|
286
|
+
it { should_not report_lint }
|
287
|
+
end
|
288
|
+
|
289
|
+
context 'and actual class is incorrect' do
|
290
|
+
let(:scss) { <<-SCSS }
|
291
|
+
.hyphenated-lowercase {}
|
292
|
+
#hyphenated-lowercase {}
|
293
|
+
SCSS
|
294
|
+
|
295
|
+
it { should report_lint line: 1 }
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'and something else uses the `class_convention`' do
|
299
|
+
let(:scss) { <<-SCSS }
|
300
|
+
.hyphenated-lowercase {}
|
301
|
+
#camelCase {}
|
302
|
+
SCSS
|
303
|
+
|
304
|
+
it { should report_lint line: 2 }
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'when using a unique `placeholder_convention`' do
|
309
|
+
let(:linter_config) { { 'placeholder_convention' => 'snake_case' } }
|
310
|
+
|
311
|
+
context 'and actual placeholder is correct' do
|
312
|
+
let(:scss) { <<-SCSS }
|
313
|
+
.hyphenated-lowercase {}
|
314
|
+
%snake_case {}
|
315
|
+
SCSS
|
316
|
+
|
317
|
+
it { should_not report_lint }
|
318
|
+
end
|
319
|
+
|
320
|
+
context 'and actual placeholder is incorrect' do
|
321
|
+
let(:scss) { <<-SCSS }
|
322
|
+
.hyphenated-lowercase {}
|
323
|
+
%hyphenated-lowercase {}
|
324
|
+
SCSS
|
325
|
+
|
326
|
+
it { should report_lint line: 2 }
|
327
|
+
end
|
328
|
+
|
329
|
+
context 'and something else uses the `placeholder_convention`' do
|
330
|
+
let(:scss) { <<-SCSS }
|
331
|
+
.snake_case {}
|
332
|
+
%snake_case {}
|
333
|
+
SCSS
|
334
|
+
|
335
|
+
it { should report_lint line: 1 }
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context 'when using a unique `element_convention`' do
|
340
|
+
let(:linter_config) do
|
341
|
+
{
|
342
|
+
'convention' => 'camel_case',
|
343
|
+
'element_convention' => 'hyphenated-lowercase'
|
344
|
+
}
|
345
|
+
end
|
346
|
+
|
347
|
+
context 'and actual element is correct' do
|
348
|
+
let(:scss) { <<-SCSS }
|
349
|
+
hyphenated-lowercase {}
|
350
|
+
#camelCase {}
|
351
|
+
SCSS
|
352
|
+
|
353
|
+
it { should_not report_lint }
|
354
|
+
end
|
355
|
+
|
356
|
+
context 'and actual element is incorrect' do
|
357
|
+
let(:scss) { <<-SCSS }
|
358
|
+
camelCase {}
|
359
|
+
#camelCase {}
|
360
|
+
SCSS
|
361
|
+
|
362
|
+
it { should report_lint line: 1 }
|
363
|
+
end
|
364
|
+
|
365
|
+
context 'and something else uses the `element_convention`' do
|
366
|
+
let(:scss) { <<-SCSS }
|
367
|
+
hyphenated-lowercase {}
|
368
|
+
#hyphenated-lowercase {}
|
369
|
+
SCSS
|
370
|
+
|
371
|
+
it { should report_lint line: 2 }
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
context 'when using a unique `attribute_convention`' do
|
376
|
+
let(:linter_config) do
|
377
|
+
{
|
378
|
+
'convention' => 'camel_case',
|
379
|
+
'attribute_convention' => 'hyphenated-lowercase'
|
380
|
+
}
|
381
|
+
end
|
382
|
+
|
383
|
+
context 'and actual attribute is correct' do
|
384
|
+
let(:scss) { <<-SCSS }
|
385
|
+
[hyphenated-lowercase] {}
|
386
|
+
#camelCase {}
|
387
|
+
SCSS
|
388
|
+
|
389
|
+
it { should_not report_lint }
|
390
|
+
end
|
391
|
+
|
392
|
+
context 'and actual attribute is incorrect' do
|
393
|
+
let(:scss) { <<-SCSS }
|
394
|
+
[camelCase] {}
|
395
|
+
#camelCase {}
|
396
|
+
SCSS
|
397
|
+
|
398
|
+
it { should report_lint line: 1 }
|
399
|
+
end
|
400
|
+
|
401
|
+
context 'and something else uses the `attribute_convention`' do
|
402
|
+
let(:scss) { <<-SCSS }
|
403
|
+
[hyphenated-lowercase] {}
|
404
|
+
#hyphenated-lowercase {}
|
405
|
+
SCSS
|
406
|
+
|
407
|
+
it { should report_lint line: 2 }
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
context 'when using a blend of unique conventions' do
|
412
|
+
let(:linter_config) do
|
413
|
+
{
|
414
|
+
'convention' => 'camel_case',
|
415
|
+
'element_convention' => 'hyphenated-lowercase',
|
416
|
+
'attribute_convention' => 'snake_case',
|
417
|
+
'class_convention' => /[a-z]+\-\-[a-z]+/
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
421
|
+
context 'and everything is correct' do
|
422
|
+
let(:scss) { <<-SCSS }
|
423
|
+
#camelCase {}
|
424
|
+
hyphenated-lowercase {}
|
425
|
+
[snake_case] {}
|
426
|
+
.foo--bar {}
|
427
|
+
SCSS
|
428
|
+
|
429
|
+
it { should_not report_lint }
|
430
|
+
end
|
431
|
+
|
432
|
+
context 'some things are not correct' do
|
433
|
+
let(:scss) { <<-SCSS }
|
434
|
+
#camelCase {}
|
435
|
+
camelCase {}
|
436
|
+
[snake_case] {}
|
437
|
+
.fooBar {}
|
438
|
+
SCSS
|
439
|
+
|
440
|
+
it { should report_lint line: 2 }
|
441
|
+
it { should report_lint line: 4 }
|
442
|
+
end
|
443
|
+
|
444
|
+
context 'other things are not correct' do
|
445
|
+
let(:scss) { <<-SCSS }
|
446
|
+
#snake_case {}
|
447
|
+
hyphenated-lowercase {}
|
448
|
+
[camelCase] {}
|
449
|
+
.foo--bar {}
|
450
|
+
SCSS
|
451
|
+
|
452
|
+
it { should report_lint line: 1 }
|
453
|
+
it { should report_lint line: 3 }
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
context 'when the strict_BEM convention is specified' do
|
458
|
+
let(:linter_config) { { 'convention' => 'strict_BEM' } }
|
459
|
+
|
460
|
+
context 'when a name contains no underscores or hyphens' do
|
461
|
+
let(:scss) { '.block {}' }
|
462
|
+
|
463
|
+
it { should_not report_lint }
|
464
|
+
end
|
465
|
+
|
466
|
+
context 'when a name contains single hyphen' do
|
467
|
+
let(:scss) { '.b-block {}' }
|
468
|
+
|
469
|
+
it { should_not report_lint }
|
470
|
+
end
|
471
|
+
|
472
|
+
context 'when a name contains multiple hyphens' do
|
473
|
+
let(:scss) { '.b-block-name {}' }
|
474
|
+
|
475
|
+
it { should_not report_lint }
|
476
|
+
end
|
477
|
+
|
478
|
+
context 'when a name contains multiple hyphens in a row' do
|
479
|
+
let(:scss) { '.b-block--modifier {}' }
|
480
|
+
|
481
|
+
it { should report_lint }
|
482
|
+
end
|
483
|
+
|
484
|
+
context 'when a name contains a single underscore' do
|
485
|
+
let(:scss) { '.block_modifier {}' }
|
486
|
+
|
487
|
+
it { should report_lint }
|
488
|
+
end
|
489
|
+
|
490
|
+
context 'when a block has name-value modifier' do
|
491
|
+
let(:scss) { '.block_modifier_value {}' }
|
492
|
+
|
493
|
+
it { should_not report_lint }
|
494
|
+
end
|
495
|
+
|
496
|
+
context 'when a block has name-value modifier with lots of hyphens' do
|
497
|
+
let(:scss) { '.b-block-name_modifier-name-here_value-name-here {}' }
|
498
|
+
|
499
|
+
it { should_not report_lint }
|
500
|
+
end
|
501
|
+
|
502
|
+
context 'when a name has double underscores' do
|
503
|
+
let(:scss) { '.b-block__element {}' }
|
504
|
+
|
505
|
+
it { should_not report_lint }
|
506
|
+
end
|
507
|
+
|
508
|
+
context 'when element goes after block with modifier' do
|
509
|
+
let(:scss) { '.block_modifier_value__element {}' }
|
510
|
+
|
511
|
+
it { should report_lint }
|
512
|
+
end
|
513
|
+
|
514
|
+
context 'when element has modifier' do
|
515
|
+
let(:scss) { '.block__element_modifier_value {}' }
|
516
|
+
|
517
|
+
it { should_not report_lint }
|
518
|
+
end
|
519
|
+
|
520
|
+
context 'when element has not paired modifier' do
|
521
|
+
let(:scss) { '.block__element_modifier {}' }
|
522
|
+
|
523
|
+
it { should report_lint }
|
524
|
+
end
|
525
|
+
|
526
|
+
context 'when element has hypenated modifier' do
|
527
|
+
let(:scss) { '.block__element--modifier {}' }
|
528
|
+
|
529
|
+
it { should report_lint }
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'when element has hypenated paired modifier' do
|
533
|
+
let(:scss) { '.block__element--modifier_value {}' }
|
534
|
+
|
535
|
+
it { should report_lint }
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
context 'when the hyphenated_BEM convention is specified' do
|
540
|
+
let(:linter_config) { { 'convention' => 'hyphenated_BEM' } }
|
541
|
+
|
542
|
+
context 'when a name contains no underscores or hyphens' do
|
543
|
+
let(:scss) { '.block {}' }
|
544
|
+
|
545
|
+
it { should_not report_lint }
|
546
|
+
end
|
547
|
+
|
548
|
+
context 'when a name contains single hyphen' do
|
549
|
+
let(:scss) { '.b-block {}' }
|
550
|
+
|
551
|
+
it { should_not report_lint }
|
552
|
+
end
|
553
|
+
|
554
|
+
context 'when a name contains multiple hyphens' do
|
555
|
+
let(:scss) { '.b-block-name {}' }
|
556
|
+
|
557
|
+
it { should_not report_lint }
|
558
|
+
end
|
559
|
+
|
560
|
+
context 'when a name contains multiple hyphens in a row' do
|
561
|
+
let(:scss) { '.b-block--modifier {}' }
|
562
|
+
|
563
|
+
it { should_not report_lint }
|
564
|
+
end
|
565
|
+
|
566
|
+
context 'when a name contains a single underscore' do
|
567
|
+
let(:scss) { '.block_modifier {}' }
|
568
|
+
|
569
|
+
it { should report_lint }
|
570
|
+
end
|
571
|
+
|
572
|
+
context 'when a block has name-value modifier' do
|
573
|
+
let(:scss) { '.block--modifier-value {}' }
|
574
|
+
|
575
|
+
it { should_not report_lint }
|
576
|
+
end
|
577
|
+
|
578
|
+
context 'when a block has name-value modifier with lots of hyphens' do
|
579
|
+
let(:scss) { '.b-block-name--modifier-name-here-value-name-here {}' }
|
580
|
+
|
581
|
+
it { should_not report_lint }
|
582
|
+
end
|
583
|
+
|
584
|
+
context 'when a name has double underscores' do
|
585
|
+
let(:scss) { '.b-block__element {}' }
|
586
|
+
|
587
|
+
it { should_not report_lint }
|
588
|
+
end
|
589
|
+
|
590
|
+
context 'when element goes after block with modifier' do
|
591
|
+
let(:scss) { '.block--modifier-value__element {}' }
|
592
|
+
|
593
|
+
it { should_not report_lint }
|
594
|
+
end
|
595
|
+
|
596
|
+
context 'when element has modifier' do
|
597
|
+
let(:scss) { '.block__element--modifier-value {}' }
|
598
|
+
|
599
|
+
it { should_not report_lint }
|
600
|
+
end
|
601
|
+
|
602
|
+
context 'when element has hypenated modifier' do
|
603
|
+
let(:scss) { '.block__element--modifier {}' }
|
604
|
+
|
605
|
+
it { should_not report_lint }
|
606
|
+
end
|
607
|
+
|
608
|
+
context 'when element has hypenated paired modifier' do
|
609
|
+
let(:scss) { '.block__element--modifier-value {}' }
|
610
|
+
|
611
|
+
it { should_not report_lint }
|
612
|
+
end
|
613
|
+
|
614
|
+
context 'when a block contains an underscore' do
|
615
|
+
let(:scss) { '.a_block__element--modifier {}' }
|
616
|
+
|
617
|
+
it { should report_lint }
|
618
|
+
end
|
619
|
+
|
620
|
+
context 'when an element contains an underscore' do
|
621
|
+
let(:scss) { '.block__an_element--modifier {}' }
|
622
|
+
|
623
|
+
it { should report_lint }
|
624
|
+
end
|
625
|
+
|
626
|
+
context 'when a modifier contains an underscore' do
|
627
|
+
let(:scss) { '.block__element--a_modifier {}' }
|
628
|
+
|
629
|
+
it { should report_lint }
|
630
|
+
end
|
631
|
+
end
|
632
|
+
end
|