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,283 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::MergeableSelector do
4
+ context 'when single root' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ }
8
+ CSS
9
+
10
+ it { should_not report_lint }
11
+ end
12
+
13
+ context 'when different roots' do
14
+ let(:css) { <<-CSS }
15
+ p {
16
+ background: #000;
17
+ margin: 5px;
18
+ }
19
+ a {
20
+ background: #000;
21
+ margin: 5px;
22
+ }
23
+ CSS
24
+
25
+ it { should_not report_lint }
26
+ end
27
+
28
+ context 'when different roots with matching inner rules' do
29
+ let(:css) { <<-CSS }
30
+ p {
31
+ background: #000;
32
+ margin: 5px;
33
+ .foo {
34
+ color: red;
35
+ }
36
+ }
37
+ a {
38
+ background: #000;
39
+ margin: 5px;
40
+ .foo {
41
+ color: red;
42
+ }
43
+ }
44
+ CSS
45
+
46
+ it { should_not report_lint }
47
+ end
48
+
49
+ context 'when multi-selector roots and parital rule match' do
50
+ let(:css) { <<-CSS }
51
+ p, a {
52
+ background: #000;
53
+ margin: 5px;
54
+ .foo {
55
+ color: red;
56
+ }
57
+ }
58
+ a {
59
+ background: #000;
60
+ margin: 5px;
61
+ .foo {
62
+ color: red;
63
+ }
64
+ }
65
+ CSS
66
+
67
+ it { should_not report_lint }
68
+ end
69
+
70
+ context 'when nested and unnested selectors match' do
71
+ let(:css) { <<-CSS }
72
+ a.current {
73
+ background: #000;
74
+ margin: 5px;
75
+ .foo {
76
+ color: red;
77
+ }
78
+ }
79
+ a {
80
+ &.current {
81
+ background: #000;
82
+ margin: 5px;
83
+ .foo {
84
+ color: red;
85
+ }
86
+ }
87
+ }
88
+ CSS
89
+
90
+ context 'when force_nesting is enabled' do
91
+ let(:linter_config) { { 'force_nesting' => true } }
92
+ it { should report_lint }
93
+ end
94
+
95
+ context 'when force_nesting is disabled' do
96
+ let(:linter_config) { { 'force_nesting' => false } }
97
+ it { should_not report_lint }
98
+ end
99
+ end
100
+
101
+ context 'when same class roots' do
102
+ let(:css) { <<-CSS }
103
+ .warn {
104
+ font-weight: bold;
105
+ }
106
+ .warn {
107
+ color: #f00;
108
+ @extend .warn;
109
+ a {
110
+ color: #ccc;
111
+ }
112
+ }
113
+ CSS
114
+
115
+ it { should report_lint }
116
+ end
117
+
118
+ context 'when same compond selector roots' do
119
+ let(:css) { <<-CSS }
120
+ .warn .alert {
121
+ font-weight: bold;
122
+ }
123
+ .warn .alert {
124
+ color: #f00;
125
+ @extend .warn;
126
+ a {
127
+ color: #ccc;
128
+ }
129
+ }
130
+ CSS
131
+
132
+ it { should report_lint }
133
+ end
134
+
135
+ context 'when same class roots separated by another class' do
136
+ let(:css) { <<-CSS }
137
+ .warn {
138
+ font-weight: bold;
139
+ }
140
+ .foo {
141
+ color: red;
142
+ }
143
+ .warn {
144
+ color: #f00;
145
+ @extend .warn;
146
+ a {
147
+ color: #ccc;
148
+ }
149
+ }
150
+ CSS
151
+
152
+ it { should report_lint }
153
+ end
154
+
155
+ context 'when rule in a mixin @include matches a root root' do
156
+ let(:css) { <<-CSS }
157
+ p {
158
+ font-weight: bold;
159
+ }
160
+ @include enhance(small-tablet) {
161
+ p {
162
+ font-weight: normal;
163
+ }
164
+ }
165
+ CSS
166
+
167
+ it { should_not report_lint }
168
+ end
169
+
170
+ context 'when rule in a mixin definition matches a root rule' do
171
+ let(:css) { <<-CSS }
172
+ p {
173
+ font-weight: bold;
174
+ }
175
+ @mixin my-mixin {
176
+ p {
177
+ font-weight: normal;
178
+ }
179
+ }
180
+ CSS
181
+
182
+ it { should_not report_lint }
183
+ end
184
+
185
+ context 'when rule in a media directive matches a root rule' do
186
+ let(:css) { <<-CSS }
187
+ p {
188
+ font-weight: bold;
189
+ }
190
+ @media only screen and (min-device-pixel-ratio: 1.5) {
191
+ p {
192
+ font-weight: normal;
193
+ }
194
+ }
195
+ CSS
196
+
197
+ it { should_not report_lint }
198
+ end
199
+
200
+ context 'when rule in a keyframes directive matches a root rule' do
201
+ let(:css) { <<-CSS }
202
+ @keyframes slideouttoleft {
203
+ from {
204
+ transform: translateX(0);
205
+ }
206
+
207
+ to {
208
+ transform: translateX(-100%);
209
+ }
210
+ }
211
+
212
+ @keyframes slideouttoright {
213
+ from {
214
+ transform: translateX(0);
215
+ }
216
+
217
+ to {
218
+ transform: translateX(100%);
219
+ }
220
+ }
221
+ CSS
222
+
223
+ it { should_not report_lint }
224
+ end
225
+
226
+ context 'when there are duplicate rules nested in a rule set' do
227
+ let(:css) { <<-CSS }
228
+ .foo {
229
+ .bar {
230
+ font-weight: bold;
231
+ }
232
+ .baz {
233
+ font-weight: bold;
234
+ }
235
+ .bar {
236
+ color: #ff0;
237
+ }
238
+ }
239
+ CSS
240
+
241
+ it { should report_lint }
242
+ end
243
+
244
+ context 'when force_nesting is enabled' do
245
+ let(:linter_config) { { 'force_nesting' => true } }
246
+
247
+ context 'when one of the duplicate rules is in a comma sequence' do
248
+ let(:css) { <<-CSS }
249
+ .foo,
250
+ .bar {
251
+ color: #000;
252
+ }
253
+ .foo {
254
+ color: #f00;
255
+ }
256
+ CSS
257
+
258
+ it { should_not report_lint }
259
+ end
260
+
261
+ context 'when rules start with the same prefix but are not the same' do
262
+ let(:css) { <<-CSS }
263
+ .foo {
264
+ color: #000;
265
+ }
266
+ .foobar {
267
+ color: #f00;
268
+ }
269
+ CSS
270
+
271
+ it { should_not report_lint }
272
+ end
273
+
274
+ context 'when a rule contains interpolation' do
275
+ let(:css) { <<-CSS }
276
+ .\#{$class-name} {}
277
+ .foobar {}
278
+ CSS
279
+
280
+ it { should_not report_lint }
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,206 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::NameFormat do
4
+ context 'when no variable, functions, or mixin declarations exist' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ margin: 0;
8
+ }
9
+ CSS
10
+
11
+ it { should_not report_lint }
12
+ end
13
+
14
+ context 'when a variable name contains a hyphen' do
15
+ let(:css) { '$content-padding: 10px;' }
16
+
17
+ it { should_not report_lint }
18
+ end
19
+
20
+ context 'when a variable name contains an underscore' do
21
+ let(:css) { '$content_padding: 10px;' }
22
+
23
+ it { should report_lint line: 1 }
24
+ end
25
+
26
+ context 'when a variable name contains an uppercase character' do
27
+ let(:css) { '$contentPadding: 10px;' }
28
+
29
+ it { should report_lint line: 1 }
30
+ end
31
+
32
+ context 'when a function is declared with a capital letter' do
33
+ let(:css) { <<-CSS }
34
+ @function badFunction() {
35
+ }
36
+ CSS
37
+
38
+ it { should report_lint line: 1 }
39
+ end
40
+
41
+ context 'when a function is declared with an underscore' do
42
+ let(:css) { <<-CSS }
43
+ @function bad_function() {
44
+ }
45
+ CSS
46
+
47
+ it { should report_lint line: 1 }
48
+ end
49
+
50
+ context 'when a mixin is declared with a capital letter' do
51
+ let(:css) { <<-CSS }
52
+ @mixin badMixin() {
53
+ }
54
+ CSS
55
+
56
+ it { should report_lint line: 1 }
57
+ end
58
+
59
+ context 'when a mixin is declared with an underscore' do
60
+ let(:css) { <<-CSS }
61
+ @mixin bad_mixin() {
62
+ }
63
+ CSS
64
+
65
+ it { should report_lint line: 1 }
66
+ end
67
+
68
+ context 'when no invalid usages exist' do
69
+ let(:css) { <<-CSS }
70
+ p {
71
+ margin: 0;
72
+ }
73
+ CSS
74
+
75
+ it { should_not report_lint }
76
+ end
77
+
78
+ context 'when a referenced variable name has a capital letter' do
79
+ let(:css) { <<-CSS }
80
+ p {
81
+ margin: $badVar;
82
+ }
83
+ CSS
84
+
85
+ it { should report_lint line: 2 }
86
+ end
87
+
88
+ context 'when a referenced variable name has an underscore' do
89
+ let(:css) { <<-CSS }
90
+ p {
91
+ margin: $bad_var;
92
+ }
93
+ CSS
94
+
95
+ it { should report_lint line: 2 }
96
+ end
97
+
98
+ context 'when a referenced function name has a capital letter' do
99
+ let(:css) { <<-CSS }
100
+ p {
101
+ margin: badFunc();
102
+ }
103
+ CSS
104
+
105
+ it { should report_lint line: 2 }
106
+ end
107
+
108
+ context 'when a referenced function name has an underscore' do
109
+ let(:css) { <<-CSS }
110
+ p {
111
+ margin: bad_func();
112
+ }
113
+ CSS
114
+
115
+ it { should report_lint line: 2 }
116
+ end
117
+
118
+ context 'when an included mixin name has a capital letter' do
119
+ let(:css) { '@include badMixin();' }
120
+
121
+ it { should report_lint line: 1 }
122
+ end
123
+
124
+ context 'when an included mixin name has an underscore' do
125
+ let(:css) { '@include bad_mixin();' }
126
+
127
+ it { should report_lint line: 1 }
128
+ end
129
+
130
+ context 'when function is a transform function' do
131
+ %w[rotateX rotateY rotateZ
132
+ scaleX scaleY scaleZ
133
+ skewX skewY
134
+ translateX translateY translateZ].each do |function|
135
+ let(:css) { <<-CSS }
136
+ p {
137
+ transform: #{function}(2);
138
+ }
139
+ CSS
140
+
141
+ it { should_not report_lint }
142
+ end
143
+ end
144
+
145
+ context 'when mixin is a transform function' do
146
+ let(:css) { <<-CSS }
147
+ p {
148
+ @include translateX(2);
149
+ }
150
+ CSS
151
+
152
+ it { should_not report_lint }
153
+ end
154
+
155
+ context 'when a mixin contains keyword arguments with underscores' do
156
+ let(:css) { '@include mixin($some_var: 4);' }
157
+
158
+ it { should report_lint }
159
+ end
160
+
161
+ context 'when a mixin contains keyword arguments with hyphens' do
162
+ let(:css) { '@include mixin($some-var: 4);' }
163
+
164
+ it { should_not report_lint }
165
+ end
166
+
167
+ context 'when the BEM convention is specified' do
168
+ let(:linter_config) { { 'convention' => 'BEM' } }
169
+
170
+ context 'when a name contains no underscores or hyphens' do
171
+ let(:css) { '@extend %block;' }
172
+
173
+ it { should_not report_lint }
174
+ end
175
+
176
+ context 'when a name contains a single underscore' do
177
+ let(:css) { '@extend %block_thing;' }
178
+
179
+ it { should report_lint }
180
+ end
181
+
182
+ context 'when a name contains a single hyphen' do
183
+ let(:css) { '@extend %block-thing;' }
184
+
185
+ it { should_not report_lint }
186
+ end
187
+
188
+ context 'when a name contains a double hyphen' do
189
+ let(:css) { '@extend %block--thing;' }
190
+
191
+ it { should_not report_lint }
192
+ end
193
+
194
+ context 'when a name contains a double underscore' do
195
+ let(:css) { '@extend %block__thing;' }
196
+
197
+ it { should_not report_lint }
198
+ end
199
+
200
+ context 'when a name contains a double underscore and double hyphen' do
201
+ let(:css) { '@extend %block--thing__word;' }
202
+
203
+ it { should_not report_lint }
204
+ end
205
+ end
206
+ end