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,242 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::Indentation do
4
+ context 'when a line at the root level is indented' do
5
+ let(:css) { <<-CSS }
6
+ $var: 5px;
7
+ $other: 10px;
8
+ CSS
9
+
10
+ it { should_not report_lint line: 1 }
11
+ it { should report_lint line: 2 }
12
+ end
13
+
14
+ context 'when a line in a rule set is properly indented' do
15
+ let(:css) { <<-CSS }
16
+ p {
17
+ margin: 0;
18
+ }
19
+ CSS
20
+
21
+ it { should_not report_lint }
22
+ end
23
+
24
+ context 'when lines in a rule set are not properly indented' do
25
+ let(:css) { <<-CSS }
26
+ p {
27
+ margin: 0;
28
+ padding: 1em;
29
+ opacity: 0.5;
30
+ }
31
+ CSS
32
+
33
+ it { should report_lint line: 2 }
34
+ it { should_not report_lint line: 3 }
35
+ it { should report_lint line: 4 }
36
+ end
37
+
38
+ context 'when selector of a nested rule set is not properly indented' do
39
+ let(:css) { <<-CSS }
40
+ p {
41
+ em {
42
+ font-style: italic;
43
+ }
44
+ }
45
+ CSS
46
+
47
+ it { should report_lint line: 2 }
48
+ it { should_not report_lint line: 3 }
49
+ it { should_not report_lint line: 4 }
50
+ end
51
+
52
+ context 'when multi-line selector of a nested rule set is not properly indented' do
53
+ let(:css) { <<-CSS }
54
+ p {
55
+ b,
56
+ em,
57
+ i {
58
+ font-style: italic;
59
+ }
60
+ }
61
+ CSS
62
+
63
+ it { should report_lint line: 2 }
64
+ it { should_not report_lint line: 3 }
65
+ it { should_not report_lint line: 4 }
66
+ it { should_not report_lint line: 5 }
67
+ end
68
+
69
+ context 'when a property is on the same line as its rule selector' do
70
+ let(:css) { 'h1 { margin: 5px; }' }
71
+ it { should_not report_lint }
72
+ end
73
+
74
+ context 'when an argument list spans multiple lines' do
75
+ let(:css) { <<-CSS }
76
+ @include mixin(one,
77
+ two,
78
+ three);
79
+ CSS
80
+
81
+ it { should_not report_lint }
82
+ end
83
+
84
+ context 'when an argument list of an improperly indented script spans multiple lines' do
85
+ let(:css) { <<-CSS }
86
+ p {
87
+ @include mixin(one,
88
+ two,
89
+ three);
90
+ }
91
+ CSS
92
+
93
+ it { should report_lint line: 2 }
94
+ it { should_not report_lint line: 3 }
95
+ it { should_not report_lint line: 4 }
96
+ end
97
+
98
+ context 'when an if statement is incorrectly indented' do
99
+ let(:css) { <<-CSS }
100
+ $condition: true;
101
+ @if $condition {
102
+ padding: 0;
103
+ }
104
+ CSS
105
+
106
+ it { should report_lint line: 2 }
107
+ end
108
+
109
+ context 'when an if statement is accompanied by a correctly indented else statement' do
110
+ let(:css) { <<-CSS }
111
+ @if $condition {
112
+ padding: 0;
113
+ } @else {
114
+ margin: 0;
115
+ }
116
+ CSS
117
+
118
+ it { should_not report_lint }
119
+ end
120
+
121
+ context 'when @at-root directive contains correctly indented children' do
122
+ let(:css) { <<-CSS }
123
+ .block {
124
+ @at-root {
125
+ .something {}
126
+ }
127
+ }
128
+ CSS
129
+
130
+ it { should_not report_lint }
131
+ end
132
+
133
+ context 'when @at-root directive with an inline selector contains correctly indented children' do
134
+ let(:css) { <<-CSS }
135
+ .block {
136
+ @at-root .something {
137
+ .something-else {}
138
+ }
139
+ }
140
+ CSS
141
+
142
+ it { should_not report_lint }
143
+ end
144
+
145
+ context 'when the indentation width has been explicitly set' do
146
+ let(:linter_config) { { 'width' => 3 } }
147
+
148
+ let(:css) { <<-CSS }
149
+ p {
150
+ margin: 0;
151
+ padding: 5px;
152
+ }
153
+ CSS
154
+
155
+ it { should report_lint line: 2 }
156
+ it { should_not report_lint line: 3 }
157
+ end
158
+
159
+ context 'when there are selectors across multiple lines' do
160
+ let(:css) { <<-CSS }
161
+ .class1,
162
+ .class2 {
163
+ margin: 0;
164
+ padding: 5px;
165
+ }
166
+ CSS
167
+
168
+ it { should_not report_lint }
169
+ end
170
+
171
+ context 'when there are selectors across multiple lines with a single line block' do
172
+ let(:css) { <<-CSS }
173
+ .class1,
174
+ .class2 { margin: 0; }
175
+ CSS
176
+
177
+ it { should_not report_lint }
178
+ end
179
+
180
+ context 'when a comment node precedes a node' do
181
+ let(:css) { <<-CSS }
182
+ // A comment
183
+ $var: 1;
184
+ CSS
185
+
186
+ it { should_not report_lint }
187
+ end
188
+
189
+ context 'when a line is indented with tabs' do
190
+ let(:css) { <<-CSS }
191
+ p {
192
+ \tmargin: 0;
193
+ }
194
+ CSS
195
+
196
+ it { should report_lint line: 2 }
197
+ end
198
+
199
+ context 'when a line contains a mix of tabs and spaces' do
200
+ let(:css) { <<-CSS }
201
+ p {
202
+ \tmargin: 0;
203
+ }
204
+ CSS
205
+
206
+ it { should report_lint line: 2 }
207
+ end
208
+
209
+ context 'when tabs are preferred' do
210
+ let(:linter_config) { { 'character' => 'tab', 'width' => 1 } }
211
+
212
+ context 'and the line is indented correctly' do
213
+ let(:css) { <<-CSS }
214
+ p {
215
+ \tmargin: 0;
216
+ }
217
+ CSS
218
+
219
+ it { should_not report_lint }
220
+ end
221
+
222
+ context 'and the line is incorrectly indented' do
223
+ let(:css) { <<-CSS }
224
+ p {
225
+ \t\tmargin: 0;
226
+ }
227
+ CSS
228
+
229
+ it { should report_lint line: 2 }
230
+ end
231
+
232
+ context 'and the line is indented with spaces' do
233
+ let(:css) { <<-CSS }
234
+ p {
235
+ margin: 0;
236
+ }
237
+ CSS
238
+
239
+ it { should report_lint line: 2 }
240
+ end
241
+ end
242
+ end
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::LeadingZero do
4
+ context 'when no values exist' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ }
8
+ CSS
9
+
10
+ it { should_not report_lint }
11
+ end
12
+
13
+ context 'when a zero exists' do
14
+ let(:css) { <<-CSS }
15
+ p {
16
+ margin: 0;
17
+ }
18
+ CSS
19
+
20
+ it { should_not report_lint }
21
+ end
22
+
23
+ context 'when an integer value exists' do
24
+ let(:css) { <<-CSS }
25
+ p {
26
+ line-height: 2;
27
+ }
28
+ CSS
29
+
30
+ it { should_not report_lint }
31
+ end
32
+
33
+ context 'when an integer value with units exists' do
34
+ let(:css) { <<-CSS }
35
+ p {
36
+ margin: 5px;
37
+ }
38
+ CSS
39
+
40
+ it { should_not report_lint }
41
+ end
42
+
43
+ context 'when a unitless fractional value with no leading zero exists' do
44
+ let(:css) { <<-CSS }
45
+ p {
46
+ line-height: .5;
47
+ }
48
+ CSS
49
+
50
+ it { should_not report_lint }
51
+ end
52
+
53
+ context 'when a negative unitless fractional value with no leading zero exists' do
54
+ let(:css) { <<-CSS }
55
+ p {
56
+ line-height: -.5;
57
+ }
58
+ CSS
59
+
60
+ it { should_not report_lint }
61
+ end
62
+
63
+ context 'when a fractional value with units and no leading zero exists' do
64
+ let(:css) { <<-CSS }
65
+ p {
66
+ margin: .5em;
67
+ }
68
+ CSS
69
+
70
+ it { should_not report_lint }
71
+ end
72
+
73
+ context 'when a negative fractional value with units and no leading zero exists' do
74
+ let(:css) { <<-CSS }
75
+ p {
76
+ margin: -.5em;
77
+ }
78
+ CSS
79
+
80
+ it { should_not report_lint }
81
+ end
82
+
83
+ context 'when a fractional value with a leading zero exists' do
84
+ let(:css) { <<-CSS }
85
+ p {
86
+ line-height: 0.5;
87
+ }
88
+ CSS
89
+
90
+ it { should report_lint line: 2 }
91
+ end
92
+
93
+ context 'when a fractional value with units and a leading zero exists' do
94
+ let(:css) { <<-CSS }
95
+ p {
96
+ margin: 0.5em;
97
+ }
98
+ CSS
99
+
100
+ it { should report_lint line: 2 }
101
+ end
102
+
103
+ context 'when a negative fractional value with units and a leading zero exists' do
104
+ let(:css) { <<-CSS }
105
+ p {
106
+ margin: -0.5em;
107
+ }
108
+ CSS
109
+
110
+ it { should report_lint line: 2 }
111
+ end
112
+
113
+ context 'when a fractional value with a mantissa ending in zero exists' do
114
+ let(:css) { <<-CSS }
115
+ p {
116
+ line-height: 10.5;
117
+ }
118
+ CSS
119
+
120
+ it { should_not report_lint }
121
+ end
122
+
123
+ context 'when multiple fractional values with leading zeros exist' do
124
+ let(:css) { <<-CSS }
125
+ p {
126
+ margin: 0.5em 0.5 0.1px 0.9pt;
127
+ }
128
+ CSS
129
+
130
+ it { should report_lint count: 4, line: 2 }
131
+ end
132
+
133
+ context 'when leading zeros appear in function arguments' do
134
+ let(:css) { <<-CSS }
135
+ p {
136
+ margin: some-function(0.5em, 0.4 0.3 .2);
137
+ }
138
+ CSS
139
+
140
+ it { should report_lint count: 3, line: 2 }
141
+ end
142
+
143
+ context 'when leading zeros appear in mixin arguments' do
144
+ let(:css) { <<-CSS }
145
+ p {
146
+ @include some-mixin(0.5em, 0.4 0.3 .2);
147
+ }
148
+ CSS
149
+
150
+ it { should report_lint count: 3, line: 2 }
151
+ end
152
+
153
+ context 'when leading zeros appear in variable declarations' do
154
+ let(:css) { '$some-var: 0.5em;' }
155
+
156
+ it { should report_lint line: 1 }
157
+ end
158
+
159
+ context 'when leading zeros appear in named arguments' do
160
+ let(:css) { <<-CSS }
161
+ p {
162
+ @include line-clamp($line-height: 0.9, $line-count: 2);
163
+ }
164
+ CSS
165
+
166
+ it { should report_lint line: 2 }
167
+ end
168
+
169
+ context 'when leading zeros appear in parameter defaults' do
170
+ let(:css) { <<-CSS }
171
+ @mixin my-mixin($bad-value: 0.5, $good-value: .9, $string-value: "0.9") {
172
+ margin: $some-value;
173
+ padding: $some-other-value;
174
+ }
175
+ CSS
176
+
177
+ it { should report_lint count: 1, line: 1 }
178
+ end
179
+
180
+ context 'when leading zeros are preferred' do
181
+ let(:linter_config) { { 'style' => 'include_zero' } }
182
+
183
+ context 'when a zero exists' do
184
+ let(:css) { <<-CSS }
185
+ p {
186
+ margin: 0;
187
+ }
188
+ CSS
189
+
190
+ it { should_not report_lint }
191
+ end
192
+
193
+ context 'when a non-zero integer value exists' do
194
+ let(:css) { <<-CSS }
195
+ p {
196
+ line-height: 2;
197
+ }
198
+ CSS
199
+
200
+ it { should_not report_lint }
201
+ end
202
+
203
+ context 'when a fractional value with no leading zero exists' do
204
+ let(:css) { <<-CSS }
205
+ p {
206
+ padding: .5em;
207
+ }
208
+ CSS
209
+
210
+ it { should report_lint line: 2 }
211
+ end
212
+
213
+ context 'when a fractional value with leading zero exists' do
214
+ let(:css) { <<-CSS }
215
+ p {
216
+ padding: 0.5em;
217
+ }
218
+ CSS
219
+
220
+ it { should_not report_lint }
221
+ end
222
+
223
+ context 'when a fractional value with a mantissa ending in zero exists' do
224
+ let(:css) { <<-CSS }
225
+ p {
226
+ padding: 10.5em;
227
+ }
228
+ CSS
229
+
230
+ it { should_not report_lint }
231
+ end
232
+ end
233
+ end