scss_lint 0.39.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +15 -0
  3. data/lib/scss_lint.rb +1 -0
  4. data/lib/scss_lint/cli.rb +10 -3
  5. data/lib/scss_lint/config.rb +54 -2
  6. data/lib/scss_lint/control_comment_processor.rb +15 -6
  7. data/lib/scss_lint/exceptions.rb +3 -0
  8. data/lib/scss_lint/linter/color_variable.rb +7 -0
  9. data/lib/scss_lint/linter/else_placement.rb +1 -0
  10. data/lib/scss_lint/linter/extend_directive.rb +11 -0
  11. data/lib/scss_lint/linter/final_newline.rb +1 -0
  12. data/lib/scss_lint/linter/name_format.rb +1 -12
  13. data/lib/scss_lint/linter/nesting_depth.rb +22 -1
  14. data/lib/scss_lint/linter/property_sort_order.rb +8 -0
  15. data/lib/scss_lint/linter/property_units.rb +21 -3
  16. data/lib/scss_lint/linter/space_after_variable_name.rb +18 -0
  17. data/lib/scss_lint/linter/space_between_parens.rb +1 -0
  18. data/lib/scss_lint/linter/trailing_whitespace.rb +15 -0
  19. data/lib/scss_lint/plugins.rb +33 -0
  20. data/lib/scss_lint/plugins/linter_dir.rb +24 -0
  21. data/lib/scss_lint/plugins/linter_gem.rb +51 -0
  22. data/lib/scss_lint/version.rb +1 -1
  23. data/spec/scss_lint/config_spec.rb +64 -0
  24. data/spec/scss_lint/fixtures/plugins/linter_plugin.rb +7 -0
  25. data/spec/scss_lint/linter/color_variable_spec.rb +12 -0
  26. data/spec/scss_lint/linter/else_placement_spec.rb +34 -0
  27. data/spec/scss_lint/linter/extend_directive_spec.rb +73 -0
  28. data/spec/scss_lint/linter/nesting_depth_spec.rb +72 -0
  29. data/spec/scss_lint/linter/property_sort_order_spec.rb +32 -0
  30. data/spec/scss_lint/linter/property_units_spec.rb +40 -0
  31. data/spec/scss_lint/linter/space_after_variable_name_spec.rb +13 -0
  32. data/spec/scss_lint/linter/trailing_whitespace_spec.rb +33 -0
  33. data/spec/scss_lint/linter_spec.rb +15 -2
  34. data/spec/scss_lint/plugins/linter_dir_spec.rb +21 -0
  35. data/spec/scss_lint/plugins/linter_gem_spec.rb +60 -0
  36. data/spec/scss_lint/plugins_spec.rb +53 -0
  37. data/spec/spec_helper.rb +10 -0
  38. metadata +26 -5
@@ -50,6 +50,36 @@ describe SCSSLint::Linter::PropertyUnits do
50
50
 
51
51
  it { should report_lint line: 2 }
52
52
  end
53
+
54
+ context 'and some of the units are allowed but others are not allowed' do
55
+ let(:scss) { <<-SCSS }
56
+ p {
57
+ margin: 1rem 1rem 16px 1rem;
58
+ }
59
+ SCSS
60
+
61
+ it { should report_lint line: 2 }
62
+ end
63
+
64
+ context 'and it contains a quoted string with unit-like characterstics' do
65
+ let(:scss) { <<-SCSS }
66
+ p {
67
+ font: italic 1rem "A 1a";
68
+ }
69
+ SCSS
70
+
71
+ it { should_not report_lint }
72
+
73
+ context 'and it contains other unallowed units' do
74
+ let(:scss) { <<-SCSS }
75
+ p {
76
+ font: italic 1px "A 1a";
77
+ }
78
+ SCSS
79
+
80
+ it { should report_lint }
81
+ end
82
+ end
53
83
  end
54
84
  end
55
85
 
@@ -226,4 +256,14 @@ describe SCSSLint::Linter::PropertyUnits do
226
256
 
227
257
  it { should_not report_lint }
228
258
  end
259
+
260
+ context 'when property contains a string in quotes that looks like a value with weird units' do
261
+ let(:scss) { <<-SCSS }
262
+ p {
263
+ content: "This is 12a";
264
+ }
265
+ SCSS
266
+
267
+ it { should_not report_lint }
268
+ end
229
269
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::SpaceAfterVariableName do
4
+ let(:scss) { <<-SCSS }
5
+ $none: #fff;
6
+ $one : #fff;
7
+ $two : #fff;
8
+ SCSS
9
+
10
+ it { should_not report_lint line: 1 }
11
+ it { should report_lint line: 2 }
12
+ it { should report_lint line: 3 }
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Linter::TrailingWhitespace do
4
+ context 'when lines contain trailing spaces' do
5
+ let(:scss) { <<-SCSS }
6
+ p {
7
+ margin: 0;\s\s
8
+ }
9
+ SCSS
10
+
11
+ it { should report_lint line: 2 }
12
+ end
13
+
14
+ context 'when lines contain trailing tabs' do
15
+ let(:scss) { <<-SCSS }
16
+ p {
17
+ margin: 0;\t\t
18
+ }
19
+ SCSS
20
+
21
+ it { should report_lint line: 2 }
22
+ end
23
+
24
+ context 'when lines does not contain trailing whitespace' do
25
+ let(:scss) { <<-SCSS }
26
+ p {
27
+ margin: 0;
28
+ }
29
+ SCSS
30
+
31
+ it { should_not report_lint }
32
+ end
33
+ end
@@ -7,6 +7,11 @@ describe SCSSLint::Linter do
7
7
 
8
8
  module SCSSLint
9
9
  class Linter::Fake < SCSSLint::Linter
10
+ def visit_root(_node)
11
+ add_lint(engine.lines.count, 'final new line') unless engine.lines[-1][-1] == "\n"
12
+ yield
13
+ end
14
+
10
15
  def visit_prop(node)
11
16
  return unless node.value.to_sass.strip == 'fail1'
12
17
  add_lint(node, 'everything offends me')
@@ -47,7 +52,7 @@ describe SCSSLint::Linter do
47
52
  end
48
53
 
49
54
  context 'when a disable is present at the top level' do
50
- let(:scss) { <<-SCSS }
55
+ let(:scss) { <<-SCSS.strip }
51
56
  // scss-lint:disable Fake
52
57
  p {
53
58
  border: fail1;
@@ -271,6 +276,10 @@ describe SCSSLint::Linter do
271
276
  .good-selector {
272
277
  border: fail1;
273
278
  }
279
+
280
+ p {
281
+ color: #FFF;
282
+ }
274
283
  SCSS
275
284
 
276
285
  it { should_not report_lint line: 1 }
@@ -279,6 +288,10 @@ describe SCSSLint::Linter do
279
288
 
280
289
  context 'when /* control comment appears in the middle of a comma sequence' do
281
290
  let(:scss) { <<-SCSS }
291
+ p {
292
+ color: #FFF;
293
+ }
294
+
282
295
  .badClass, /* scss-lint:disable Fake */
283
296
  .good-selector {
284
297
  border: fail1;
@@ -286,7 +299,7 @@ describe SCSSLint::Linter do
286
299
  SCSS
287
300
 
288
301
  it { should_not report_lint line: 1 }
289
- it { should report_lint line: 3 }
302
+ it { should report_lint line: 7 }
290
303
  end
291
304
  end
292
305
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe SCSSLint::Plugins::LinterDir do
4
+ let(:plugin_directory) { File.expand_path('../../fixtures/plugins', __FILE__) }
5
+ let(:subject) { described_class.new(plugin_directory) }
6
+
7
+ describe '#config' do
8
+ it 'returns empty configuration' do
9
+ subject.config.should == SCSSLint::Config.new({})
10
+ end
11
+ end
12
+
13
+ describe '#load' do
14
+ it 'requires each file in the plugin directory' do
15
+ subject.should_receive(:require)
16
+ .with(File.join(plugin_directory, 'linter_plugin.rb')).once
17
+
18
+ subject.load
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ module SCSSLint
4
+ describe Plugins::LinterGem do
5
+ let(:subject) { described_class.new('a_gem') }
6
+
7
+ describe '#load' do
8
+ let(:gem_dir) { '/gem_dir' }
9
+ let(:config_file) { File.join(gem_dir, '.scss-lint.yml') }
10
+ let(:config_file_exists) { false }
11
+
12
+ before do
13
+ File.stub(:exist?).with(config_file).and_return(config_file_exists)
14
+ end
15
+
16
+ context 'when the gem does not exist' do
17
+ it 'raises an exception' do
18
+ expect { subject.load }.to raise_error Exceptions::PluginGemLoadError
19
+ end
20
+ end
21
+
22
+ context 'when the gem exists' do
23
+ before do
24
+ subject.stub(:require).with('a_gem').and_return(true)
25
+ Gem::Specification.stub(:find_by_name)
26
+ .with('a_gem')
27
+ .and_return(double(gem_dir: gem_dir))
28
+ end
29
+
30
+ it 'requires the gem' do
31
+ subject.should_receive(:require).with('a_gem').once
32
+ subject.load
33
+ end
34
+
35
+ context 'when the gem does not include a configuration file' do
36
+ it 'loads an empty configuration' do
37
+ subject.load
38
+ subject.config.should == Config.new({})
39
+ end
40
+ end
41
+
42
+ context 'when a config file exists in the gem' do
43
+ let(:config_file_exists) { true }
44
+ let(:fake_config) { Config.new('linters' => { 'FakeLinter' => {} }) }
45
+
46
+ before do
47
+ Config.should_receive(:load)
48
+ .with(config_file, merge_with_default: false)
49
+ .and_return(fake_config)
50
+ end
51
+
52
+ it 'loads the configuration' do
53
+ subject.load
54
+ subject.config.should == fake_config
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module SCSSLint
4
+ describe Plugins do
5
+ let(:subject) { described_class.new(Config.new(config_options)) }
6
+
7
+ describe '#load' do
8
+ context 'when gem plugins are specified' do
9
+ let(:config_options) { { 'plugin_gems' => ['a_gem'] } }
10
+ let(:plugin) { double(load: nil) }
11
+
12
+ before do
13
+ Plugins::LinterGem.stub(:new).with('a_gem').and_return(plugin)
14
+ end
15
+
16
+ it 'loads the plugin' do
17
+ plugin.should_receive(:load)
18
+ subject.load
19
+ end
20
+ end
21
+
22
+ context 'when directory plugins are specified' do
23
+ let(:config_options) { { 'plugin_directories' => ['some_dir'] } }
24
+ let(:plugin) { double(load: nil) }
25
+
26
+ before do
27
+ Plugins::LinterDir.stub(:new).with('some_dir').and_return(plugin)
28
+ end
29
+
30
+ it 'loads the plugin' do
31
+ plugin.should_receive(:load)
32
+ subject.load
33
+ end
34
+ end
35
+
36
+ context 'when plugins options are empty lists' do
37
+ let(:config_options) { { 'plugin_directories' => [], 'plugin_gems' => [] } }
38
+
39
+ it 'returns empty array' do
40
+ subject.load.should == []
41
+ end
42
+ end
43
+
44
+ context 'when no plugins options are specified' do
45
+ let(:config_options) { {} }
46
+
47
+ it 'returns empty array' do
48
+ subject.load.should == []
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,13 @@
1
+ if ENV['TRAVIS']
2
+ # When running in Travis, report coverage stats to Coveralls.
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ else
6
+ # Otherwise render coverage information in coverage/index.html and display
7
+ # coverage percentage in the console.
8
+ require 'simplecov'
9
+ end
10
+
1
11
  require 'scss_lint'
2
12
 
3
13
  Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scss_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.39.0
4
+ version: 0.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brigade Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-23 00:00:00.000000000 Z
12
+ date: 2015-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '3.0'
48
+ version: 3.1.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '3.0'
55
+ version: 3.1.0
56
56
  description: Configurable tool for writing clean and consistent SCSS
57
57
  email:
58
58
  - eng@brigade.com
@@ -94,6 +94,7 @@ files:
94
94
  - lib/scss_lint/linter/else_placement.rb
95
95
  - lib/scss_lint/linter/empty_line_between_blocks.rb
96
96
  - lib/scss_lint/linter/empty_rule.rb
97
+ - lib/scss_lint/linter/extend_directive.rb
97
98
  - lib/scss_lint/linter/final_newline.rb
98
99
  - lib/scss_lint/linter/hex_length.rb
99
100
  - lib/scss_lint/linter/hex_notation.rb
@@ -120,10 +121,12 @@ files:
120
121
  - lib/scss_lint/linter/space_after_comma.rb
121
122
  - lib/scss_lint/linter/space_after_property_colon.rb
122
123
  - lib/scss_lint/linter/space_after_property_name.rb
124
+ - lib/scss_lint/linter/space_after_variable_name.rb
123
125
  - lib/scss_lint/linter/space_before_brace.rb
124
126
  - lib/scss_lint/linter/space_between_parens.rb
125
127
  - lib/scss_lint/linter/string_quotes.rb
126
128
  - lib/scss_lint/linter/trailing_semicolon.rb
129
+ - lib/scss_lint/linter/trailing_whitespace.rb
127
130
  - lib/scss_lint/linter/trailing_zero.rb
128
131
  - lib/scss_lint/linter/unnecessary_mantissa.rb
129
132
  - lib/scss_lint/linter/unnecessary_parent_reference.rb
@@ -135,6 +138,9 @@ files:
135
138
  - lib/scss_lint/linter_registry.rb
136
139
  - lib/scss_lint/location.rb
137
140
  - lib/scss_lint/options.rb
141
+ - lib/scss_lint/plugins.rb
142
+ - lib/scss_lint/plugins/linter_dir.rb
143
+ - lib/scss_lint/plugins/linter_gem.rb
138
144
  - lib/scss_lint/rake_task.rb
139
145
  - lib/scss_lint/reporter.rb
140
146
  - lib/scss_lint/reporter/config_reporter.rb
@@ -151,6 +157,7 @@ files:
151
157
  - spec/scss_lint/config_spec.rb
152
158
  - spec/scss_lint/engine_spec.rb
153
159
  - spec/scss_lint/file_finder_spec.rb
160
+ - spec/scss_lint/fixtures/plugins/linter_plugin.rb
154
161
  - spec/scss_lint/linter/bang_format_spec.rb
155
162
  - spec/scss_lint/linter/bem_depth_spec.rb
156
163
  - spec/scss_lint/linter/border_zero_spec.rb
@@ -164,6 +171,7 @@ files:
164
171
  - spec/scss_lint/linter/else_placement_spec.rb
165
172
  - spec/scss_lint/linter/empty_line_between_blocks_spec.rb
166
173
  - spec/scss_lint/linter/empty_rule_spec.rb
174
+ - spec/scss_lint/linter/extend_directive_spec.rb
167
175
  - spec/scss_lint/linter/final_newline_spec.rb
168
176
  - spec/scss_lint/linter/hex_length_spec.rb
169
177
  - spec/scss_lint/linter/hex_notation_spec.rb
@@ -190,10 +198,12 @@ files:
190
198
  - spec/scss_lint/linter/space_after_comma_spec.rb
191
199
  - spec/scss_lint/linter/space_after_property_colon_spec.rb
192
200
  - spec/scss_lint/linter/space_after_property_name_spec.rb
201
+ - spec/scss_lint/linter/space_after_variable_name_spec.rb
193
202
  - spec/scss_lint/linter/space_before_brace_spec.rb
194
203
  - spec/scss_lint/linter/space_between_parens_spec.rb
195
204
  - spec/scss_lint/linter/string_quotes_spec.rb
196
205
  - spec/scss_lint/linter/trailing_semicolon_spec.rb
206
+ - spec/scss_lint/linter/trailing_whitespace_spec.rb
197
207
  - spec/scss_lint/linter/trailing_zero_spec.rb
198
208
  - spec/scss_lint/linter/unnecessary_mantissa_spec.rb
199
209
  - spec/scss_lint/linter/unnecessary_parent_reference_spec.rb
@@ -206,6 +216,9 @@ files:
206
216
  - spec/scss_lint/linter_spec.rb
207
217
  - spec/scss_lint/location_spec.rb
208
218
  - spec/scss_lint/options_spec.rb
219
+ - spec/scss_lint/plugins/linter_dir_spec.rb
220
+ - spec/scss_lint/plugins/linter_gem_spec.rb
221
+ - spec/scss_lint/plugins_spec.rb
209
222
  - spec/scss_lint/rake_task_spec.rb
210
223
  - spec/scss_lint/reporter/config_reporter_spec.rb
211
224
  - spec/scss_lint/reporter/default_reporter_spec.rb
@@ -237,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
250
  version: '0'
238
251
  requirements: []
239
252
  rubyforge_project:
240
- rubygems_version: 2.4.5
253
+ rubygems_version: 2.4.8
241
254
  signing_key:
242
255
  specification_version: 4
243
256
  summary: SCSS lint tool
@@ -246,6 +259,7 @@ test_files:
246
259
  - spec/scss_lint/config_spec.rb
247
260
  - spec/scss_lint/engine_spec.rb
248
261
  - spec/scss_lint/file_finder_spec.rb
262
+ - spec/scss_lint/fixtures/plugins/linter_plugin.rb
249
263
  - spec/scss_lint/linter/bang_format_spec.rb
250
264
  - spec/scss_lint/linter/bem_depth_spec.rb
251
265
  - spec/scss_lint/linter/border_zero_spec.rb
@@ -259,6 +273,7 @@ test_files:
259
273
  - spec/scss_lint/linter/else_placement_spec.rb
260
274
  - spec/scss_lint/linter/empty_line_between_blocks_spec.rb
261
275
  - spec/scss_lint/linter/empty_rule_spec.rb
276
+ - spec/scss_lint/linter/extend_directive_spec.rb
262
277
  - spec/scss_lint/linter/final_newline_spec.rb
263
278
  - spec/scss_lint/linter/hex_length_spec.rb
264
279
  - spec/scss_lint/linter/hex_notation_spec.rb
@@ -285,10 +300,12 @@ test_files:
285
300
  - spec/scss_lint/linter/space_after_comma_spec.rb
286
301
  - spec/scss_lint/linter/space_after_property_colon_spec.rb
287
302
  - spec/scss_lint/linter/space_after_property_name_spec.rb
303
+ - spec/scss_lint/linter/space_after_variable_name_spec.rb
288
304
  - spec/scss_lint/linter/space_before_brace_spec.rb
289
305
  - spec/scss_lint/linter/space_between_parens_spec.rb
290
306
  - spec/scss_lint/linter/string_quotes_spec.rb
291
307
  - spec/scss_lint/linter/trailing_semicolon_spec.rb
308
+ - spec/scss_lint/linter/trailing_whitespace_spec.rb
292
309
  - spec/scss_lint/linter/trailing_zero_spec.rb
293
310
  - spec/scss_lint/linter/unnecessary_mantissa_spec.rb
294
311
  - spec/scss_lint/linter/unnecessary_parent_reference_spec.rb
@@ -301,6 +318,9 @@ test_files:
301
318
  - spec/scss_lint/linter_spec.rb
302
319
  - spec/scss_lint/location_spec.rb
303
320
  - spec/scss_lint/options_spec.rb
321
+ - spec/scss_lint/plugins/linter_dir_spec.rb
322
+ - spec/scss_lint/plugins/linter_gem_spec.rb
323
+ - spec/scss_lint/plugins_spec.rb
304
324
  - spec/scss_lint/rake_task_spec.rb
305
325
  - spec/scss_lint/reporter/config_reporter_spec.rb
306
326
  - spec/scss_lint/reporter/default_reporter_spec.rb
@@ -312,3 +332,4 @@ test_files:
312
332
  - spec/spec_helper.rb
313
333
  - spec/support/isolated_environment.rb
314
334
  - spec/support/matchers/report_lint.rb
335
+ has_rdoc: