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,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::DuplicateProperty do
4
+ context 'when rule set is empty' do
5
+ let(:css) { <<-CSS }
6
+ p {
7
+ }
8
+ CSS
9
+
10
+ it { should_not report_lint }
11
+ end
12
+
13
+ context 'when rule set contains no duplicates' do
14
+ let(:css) { <<-CSS }
15
+ p {
16
+ margin: 0;
17
+ padding: 0;
18
+ }
19
+ CSS
20
+
21
+ it { should_not report_lint }
22
+ end
23
+
24
+ context 'when rule set contains duplicates' do
25
+ let(:css) { <<-CSS }
26
+ p {
27
+ margin: 0;
28
+ padding: 0;
29
+ margin: 1em;
30
+ }
31
+ CSS
32
+
33
+ it { should report_lint line: 4 }
34
+ end
35
+
36
+ context 'when rule set contains duplicates but only on vendor-prefixed property values' do
37
+ let(:css) { <<-CSS }
38
+ p {
39
+ background: -moz-linear-gradient(center top , #fff, #000);
40
+ background: -ms-linear-gradient(center top , #fff, #000);
41
+ background: -o-linear-gradient(center top , #fff, #000);
42
+ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#000));
43
+ background: linear-gradient(center top , #fff, #000);
44
+ margin: 1em;
45
+ }
46
+ CSS
47
+
48
+ it { should_not report_lint }
49
+ end
50
+
51
+ context 'when placeholder contains duplicates but only on vendor-prefixed values' do
52
+ let(:css) { <<-CSS }
53
+ %cursor-grabbing {
54
+ cursor: -moz-grabbing;
55
+ cursor: -webkit-grabbing;
56
+ cursor: grabbing;
57
+ }
58
+ CSS
59
+
60
+ it { should_not report_lint }
61
+ end
62
+
63
+ context 'when placeholder contains exact duplicates besides for vendor-prefixed values' do
64
+ let(:css) { <<-CSS }
65
+ %cursor-grabbing {
66
+ cursor: grabbing;
67
+ cursor: grabbing;
68
+ }
69
+ CSS
70
+
71
+ it { should report_lint line: 3 }
72
+ end
73
+
74
+ context 'when mixin contains duplicates but only on vendor-prefixed values' do
75
+ let(:css) { <<-CSS }
76
+ @mixin cursor-grabbing($num) {
77
+ cursor: -moz-grabbing;
78
+ cursor: -webkit-grabbing;
79
+ cursor: grabbing;
80
+ }
81
+ CSS
82
+
83
+ it { should_not report_lint }
84
+ end
85
+
86
+ context 'when mixin contains duplicates besides for vendor-prefixed values' do
87
+ let(:css) { <<-CSS }
88
+ @mixin cursor-grabbing($num) {
89
+ cursor: grabbing;
90
+ cursor: grabbing;
91
+ }
92
+ CSS
93
+
94
+ it { should report_lint line: 3 }
95
+ end
96
+
97
+ context 'when rule set contains exact duplicates besides for vendor-prefixed property values' do
98
+ let(:css) { <<-CSS }
99
+ p {
100
+ background: -moz-linear-gradient(center top , #fff, #000);
101
+ background: -ms-linear-gradient(center top , #fff, #000);
102
+ background: -o-linear-gradient(center top , #fff, #000);
103
+ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#000));
104
+ background: linear-gradient(center top , #fff, #000);
105
+ background: linear-gradient(center top , #fff, #000);
106
+ margin: 1em;
107
+ }
108
+ CSS
109
+
110
+ it { should report_lint line: 7 }
111
+ end
112
+
113
+ context 'when rule set contains non-exact duplicates besides for vendor-prefixed values' do
114
+ let(:css) { <<-CSS }
115
+ p {
116
+ background: -moz-linear-gradient(center top , #fff, #000);
117
+ background: -ms-linear-gradient(center top , #fff, #000);
118
+ background: -o-linear-gradient(center top , #fff, #000);
119
+ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#000));
120
+ background: linear-gradient(center top , #fff, #000);
121
+ background: linear-gradient-b(center top , #fff, #000);
122
+ margin: 1em;
123
+ }
124
+ CSS
125
+
126
+ it { should report_lint line: 7 }
127
+ end
128
+
129
+ context 'when rule set contains multiple duplicates' do
130
+ let(:css) { <<-CSS }
131
+ p {
132
+ margin: 0;
133
+ padding: 0;
134
+ margin: 1em;
135
+ margin: 2em;
136
+ }
137
+ CSS
138
+
139
+ it { should report_lint line: 4 }
140
+ it { should report_lint line: 5 }
141
+ end
142
+
143
+ context 'when rule set contains duplicate properties with interpolation' do
144
+ let(:css) { <<-CSS }
145
+ p {
146
+ $direction: 'right';
147
+ margin-\#{direction}: 0;
148
+ $direction: 'left';
149
+ margin-\#{direction}: 0;
150
+ }
151
+ CSS
152
+
153
+ it { should_not report_lint }
154
+ end
155
+
156
+ context 'when property contains a variable' do
157
+ let(:css) { <<-CSS }
158
+ p {
159
+ color: $some-color;
160
+ }
161
+ CSS
162
+
163
+ it { should_not report_lint }
164
+ end
165
+
166
+ context 'when property contains a duplicate variable' do
167
+ let(:css) { <<-CSS }
168
+ p {
169
+ color: $some-color;
170
+ color: $some-color;
171
+ }
172
+ CSS
173
+
174
+ it { should report_lint line: 3 }
175
+ end
176
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::ElsePlacement do
4
+ context 'when @if contains no accompanying @else' do
5
+ let(:css) { <<-CSS }
6
+ @if $condition {
7
+ $var: 1;
8
+ }
9
+ CSS
10
+
11
+ it { should_not report_lint }
12
+ end
13
+
14
+ context 'when @else is on different line' do
15
+ let(:css) { <<-CSS }
16
+ @if $condition {
17
+ $var: 1;
18
+ }
19
+ @else {
20
+ $var: 0;
21
+ }
22
+ CSS
23
+
24
+ it { should report_lint line: 4 }
25
+ end
26
+
27
+ context 'when @else is on the same line as previous curly' do
28
+ let(:css) { <<-CSS }
29
+ @if $condition {
30
+ $var: 1;
31
+ } @else {
32
+ $var: 0;
33
+ }
34
+ CSS
35
+
36
+ it { should_not report_lint }
37
+ end
38
+
39
+ context 'when `@else if` is on different line' do
40
+ let(:css) { <<-CSS }
41
+ @if $condition {
42
+ $var: 1;
43
+ }
44
+ @else if $other_condition {
45
+ $var: 2;
46
+ }
47
+ @else {
48
+ $var: 0;
49
+ }
50
+ CSS
51
+
52
+ it { should report_lint line: 4 }
53
+ it { should report_lint line: 7 }
54
+ end
55
+
56
+ context 'when `@else if` is on the same line as previous curly' do
57
+ let(:css) { <<-CSS }
58
+ @if $condition {
59
+ $var: 1;
60
+ } @else if $other_condition {
61
+ $var: 2;
62
+ } @else {
63
+ $var: 0;
64
+ }
65
+ CSS
66
+
67
+ it { should_not report_lint }
68
+ end
69
+
70
+ context 'when @else is on same line as @if' do
71
+ let(:css) { <<-CSS }
72
+ @if $condition { $var: 1; } @else { $var: 0; }
73
+ CSS
74
+
75
+ it { should_not report_lint }
76
+ end
77
+
78
+ context 'when placement of @else on a new line is preferred' do
79
+ let(:linter_config) { { 'style' => 'new_line' } }
80
+
81
+ context 'when @else is on a new line' do
82
+ let(:css) { <<-CSS }
83
+ @if $condition {
84
+ $var: 1;
85
+ }
86
+ @else {
87
+ $var: 0;
88
+ }
89
+ CSS
90
+
91
+ it { should_not report_lint }
92
+ end
93
+
94
+ context 'when @else is on the same line as previous curly brace' do
95
+ let(:css) { <<-CSS }
96
+ @if $condition {
97
+ $var: 1;
98
+ } @else {
99
+ $var: 0;
100
+ }
101
+ CSS
102
+
103
+ it { should report_lint line: 3 }
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,263 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::EmptyLineBetweenBlocks do
4
+ context 'when there are multiple rule sets' do
5
+ context 'with blank lines between them' do
6
+ let(:css) { <<-CSS }
7
+ a {
8
+ }
9
+
10
+ b {
11
+ }
12
+
13
+ p {
14
+ }
15
+ CSS
16
+
17
+ it { should_not report_lint }
18
+ end
19
+
20
+ context 'with no blank line between them' do
21
+ let(:css) { <<-CSS }
22
+ a {
23
+ }
24
+ b {
25
+ }
26
+ p {
27
+ }
28
+ CSS
29
+
30
+ it { should report_lint line: 2 }
31
+ it { should report_lint line: 4 }
32
+ it { should_not report_lint line: 6 }
33
+ end
34
+ end
35
+
36
+ context 'when a rule set contains nested rule sets' do
37
+ context 'and the nested rule sets have no blank line between them' do
38
+ let(:css) { <<-CSS }
39
+ p {
40
+ a {
41
+ }
42
+ b {
43
+ }
44
+ }
45
+ CSS
46
+
47
+ it { should report_lint line: 3 }
48
+ it { should_not report_lint line: 5 }
49
+ end
50
+
51
+ context 'and the nested rule sets have a blank line between them' do
52
+ let(:css) { <<-CSS }
53
+ p {
54
+ a {
55
+ }
56
+
57
+ b {
58
+ }
59
+ }
60
+ CSS
61
+
62
+ it { should_not report_lint }
63
+ end
64
+
65
+ context 'and the nested rule set has a property preceding it' do
66
+ let(:css) { <<-CSS }
67
+ p {
68
+ margin: 0;
69
+ a {
70
+ }
71
+ }
72
+ CSS
73
+
74
+ it { should report_lint line: 3 }
75
+ end
76
+
77
+ context 'and the nested rule set has a property and empty line preceding it' do
78
+ let(:css) { <<-CSS }
79
+ p {
80
+ margin: 0;
81
+
82
+ a {
83
+ }
84
+ }
85
+ CSS
86
+
87
+ it { should_not report_lint }
88
+ end
89
+ end
90
+
91
+ context 'when mixins are defined' do
92
+ context 'and there is no blank line between them' do
93
+ let(:css) { <<-CSS }
94
+ @mixin mixin1() {
95
+ }
96
+ @mixin mixin2() {
97
+ }
98
+ CSS
99
+
100
+ it { should report_lint line: 2 }
101
+ end
102
+
103
+ context 'and there is a blank line between them' do
104
+ let(:css) { <<-CSS }
105
+ @mixin mixin1() {
106
+ }
107
+
108
+ @mixin mixin2() {
109
+ }
110
+ CSS
111
+
112
+ it { should_not report_lint }
113
+ end
114
+ end
115
+
116
+ context 'when mixins are included without content' do
117
+ let(:css) { <<-CSS }
118
+ p {
119
+ @include mixin1();
120
+ property: blah;
121
+ @include mixin2(4);
122
+ }
123
+ CSS
124
+
125
+ it { should_not report_lint }
126
+ end
127
+
128
+ context 'when mixins are included with content' do
129
+ context 'and there is no blank line between them' do
130
+ let(:css) { <<-CSS }
131
+ @include mixin1() {
132
+ property: value;
133
+ }
134
+ @include mixin2() {
135
+ property: value;
136
+ }
137
+ CSS
138
+
139
+ it { should report_lint line: 3 }
140
+ end
141
+
142
+ context 'and there is a blank line between them' do
143
+ let(:css) { <<-CSS }
144
+ @include mixin1() {
145
+ property: value;
146
+ }
147
+
148
+ @include mixin2() {
149
+ property: value;
150
+ }
151
+ CSS
152
+
153
+ it { should_not report_lint }
154
+ end
155
+ end
156
+
157
+ context 'when functions are defined' do
158
+ context 'and there is no blank line between them' do
159
+ let(:css) { <<-CSS }
160
+ @function func1() {
161
+ }
162
+ @function func2() {
163
+ }
164
+ CSS
165
+
166
+ it { should report_lint line: 2 }
167
+ end
168
+
169
+ context 'and there is a blank line between them' do
170
+ let(:css) { <<-CSS }
171
+ @function func1() {
172
+ }
173
+
174
+ @function func2() {
175
+ }
176
+ CSS
177
+
178
+ it { should_not report_lint }
179
+ end
180
+ end
181
+
182
+ context 'when a rule set is followed by a comment' do
183
+ let(:css) { <<-CSS }
184
+ a {
185
+ }
186
+ // This is a comment
187
+ p {
188
+ }
189
+ CSS
190
+
191
+ it { should report_lint line: 2 }
192
+ end
193
+
194
+ context 'when a rule set is preceded by a comment' do
195
+ let(:css) { <<-CSS }
196
+ a {
197
+ }
198
+
199
+ // This is a comment
200
+ p {
201
+ }
202
+ CSS
203
+
204
+ it { should_not report_lint }
205
+ end
206
+
207
+ context 'when there are multiple placeholder rule sets' do
208
+ context 'with blank lines between them' do
209
+ let(:css) { <<-CSS }
210
+ %a {
211
+ }
212
+
213
+ %b {
214
+ }
215
+
216
+ %c {
217
+ }
218
+ CSS
219
+
220
+ it { should_not report_lint }
221
+ end
222
+
223
+ context 'with no blank line between them' do
224
+ let(:css) { <<-CSS }
225
+ %a {
226
+ }
227
+ %b {
228
+ }
229
+ %c {
230
+ }
231
+ CSS
232
+
233
+ it { should report_lint line: 2 }
234
+ it { should report_lint line: 4 }
235
+ it { should_not report_lint line: 6 }
236
+ end
237
+ end
238
+
239
+ context 'when blocks occupy a single line' do
240
+ let(:linter_config) { { 'ignore_single_line_blocks' => ignore_single_line_blocks } }
241
+
242
+ let(:css) { <<-CSS }
243
+ .icon-up { &:before { content: '^'; } }
244
+ .icon-right { &:before { content: '>'; } }
245
+ @include some-mixin { content: '<'; }
246
+ @include some-other-mixin { content: 'v'; }
247
+ CSS
248
+
249
+ context 'and the `ignore_single_line_blocks` option is true' do
250
+ let(:ignore_single_line_blocks) { true }
251
+
252
+ it { should_not report_lint }
253
+ end
254
+
255
+ context 'and the `ignore_single_line_blocks` option is false' do
256
+ let(:ignore_single_line_blocks) { false }
257
+
258
+ it { should report_lint line: 1 }
259
+ it { should report_lint line: 2 }
260
+ it { should report_lint line: 3 }
261
+ end
262
+ end
263
+ end