scss-lint 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78eefba7814228e097ecd728f37ec53bd3a9c98b
4
- data.tar.gz: 21356e0c75ed328ac007f0ae9841d0e30a434fbd
3
+ metadata.gz: e1109af5e1f6cd4016185ea4d079a4188774f2d3
4
+ data.tar.gz: 41389f3cfc6b63b002101e8608b4b2f5eda48ec6
5
5
  SHA512:
6
- metadata.gz: 919f35cdcaa899ca549c87e549f653c89d0da5241bf45127d85ab89f9a76186df21432af47fc080827c7c9436aa915171aa70320faf859189d7ca051197d0c84
7
- data.tar.gz: c29ec8826b699855207837b10ae2679707b599a5a1db8c06c5579f6631e989e385bf545453498f9ef37408602e11201ee6d3e9658f3998fa8b5557bf10b6c57d
6
+ metadata.gz: 9120548dc3302ae1c7922e4b46166d6fa9238f4bf755824abad0176dec920d4722c0b4b67042258c7f73ed99903785a4f8bde6e6471809093c74cf0a7f0fbfbb
7
+ data.tar.gz: 046761b2017cbb1f333e446cae0fda6fb52a5fd8055764e91797b3eccb9eddcf862a18597c7a24ebe5dcd2e6f76d40397b6144298bbcd78d5a4574c88fe774d3
@@ -105,7 +105,7 @@ linters:
105
105
 
106
106
  SelectorFormat:
107
107
  enabled: true
108
- convention: hyphenated_lowercase # or 'BEM', or 'snake_case', or 'camel_case', or a regex pattern
108
+ convention: hyphenated_lowercase # or 'BEM', or 'hyphenated_BEM', or 'snake_case', or 'camel_case', or a regex pattern
109
109
 
110
110
  Shorthand:
111
111
  enabled: true
@@ -11,7 +11,7 @@ require 'scss_lint/control_comment_processor'
11
11
  require 'scss_lint/version'
12
12
  require 'scss_lint/utils'
13
13
 
14
- # Preload Sass so we can monkey patch it
14
+ # Load Sass classes and then monkey patch them
15
15
  require 'sass'
16
16
  require File.expand_path('scss_lint/sass/script', File.dirname(__FILE__))
17
17
  require File.expand_path('scss_lint/sass/tree', File.dirname(__FILE__))
@@ -66,6 +66,9 @@ module SCSSLint
66
66
  def check_commas_after_args(args, arg_type)
67
67
  # For each arg except the last, check the character following the comma
68
68
  args[0..-2].each do |arg|
69
+ # Sometimes the line we're looking at doesn't even contain a comma!
70
+ next unless engine.lines[arg.line - 1].include?(',')
71
+
69
72
  offset = find_comma_offset(arg)
70
73
 
71
74
  # Check for space or newline after comma (we allow arguments to be split
@@ -2,40 +2,105 @@ require 'rake'
2
2
  require 'rake/tasklib'
3
3
 
4
4
  module SCSSLint
5
- # Provide task for invoking scss-lint via Rake.
5
+ # Rake task for scss-lint CLI.
6
6
  #
7
7
  # @example
8
+ # # Add the following to your Rakefile...
8
9
  # require 'scss_lint/rake_task'
9
10
  # SCSSLint::RakeTask.new
11
+ #
12
+ # # ...and then execute from the command line:
13
+ # rake scss_lint
14
+ #
15
+ # You can also specify the list of files as explicit task arguments:
16
+ #
17
+ # @example
18
+ # # Add the following to your Rakefile...
19
+ # require 'scss_lint/rake_task'
20
+ # SCSSLint::RakeTask.new
21
+ #
22
+ # # ...and then execute from the command line (single quotes prevent shell
23
+ # # glob expansion and allow us to have a space after commas):
24
+ # rake 'scss_lint[app/assets/**/*.scss, other_files/**/*.scss]'
10
25
  class RakeTask < Rake::TaskLib
11
- # The name of the task (default 'scss-lint')
26
+ # Name of the task.
27
+ # @return [String]
12
28
  attr_accessor :name
13
29
 
14
- def initialize(*args, &task_block)
15
- @name = args.shift || :scss_lint
30
+ # Configuration file to use.
31
+ # @return [String]
32
+ attr_accessor :config
16
33
 
17
- desc 'Run scss-lint' unless ::Rake.application.last_comment
34
+ # List of files to lint (can contain shell globs).
35
+ #
36
+ # Note that this will be ignored if you explicitly pass a list of files as
37
+ # task arguments via the command line or in the task definition.
38
+ # @return [Array<String>]
39
+ attr_accessor :files
18
40
 
19
- task(name, *args) do |_, task_args|
20
- if task_block
21
- task_block.call(*[self, task_args].slice(0, task_block.arity))
22
- end
23
- run_task
24
- end
41
+ # Create the task so it is accessible via +Rake::Task['scss_lint']+.
42
+ def initialize(name = :scss_lint)
43
+ @name = name
44
+ @files = ['.'] # Search for everything under current directory by default
45
+ @quiet = false
46
+
47
+ yield self if block_given?
48
+
49
+ define
25
50
  end
26
51
 
27
- def run_task
28
- # Lazy load so task doesn't impact load time of Rakefile
29
- require 'scss_lint'
30
- require 'scss_lint/cli'
31
-
32
- CLI.new.run([])
33
- rescue SystemExit => ex
34
- if ex.status == CLI::EXIT_CODES[:data]
35
- abort('scss-lint found lints')
36
- elsif ex.status != 0
37
- abort('scss-lint failed with an error')
52
+ private
53
+
54
+ def define
55
+ # Generate a default description if one hasn't been provided
56
+ desc default_description unless ::Rake.application.last_description
57
+
58
+ task(name, [:files]) do |_task, task_args|
59
+ # Lazy-load so task doesn't affect Rakefile load time
60
+ require 'scss_lint'
61
+ require 'scss_lint/cli'
62
+
63
+ run_cli(task_args)
38
64
  end
39
65
  end
66
+
67
+ def run_cli(task_args)
68
+ cli_args = ['--config', config] if config
69
+
70
+ result = SCSSLint::CLI.new.run(Array(cli_args) + files_to_lint(task_args))
71
+
72
+ message =
73
+ case result
74
+ when CLI::EXIT_CODES[:error], CLI::EXIT_CODES[:warning]
75
+ 'scss-lint found one or more lints'
76
+ when CLI::EXIT_CODES[:ok]
77
+ 'scss-lint found no lints'
78
+ else
79
+ 'scss-lint failed with an error'
80
+ end
81
+
82
+ puts message
83
+ exit result unless result == 0
84
+ end
85
+
86
+ def files_to_lint(task_args)
87
+ # Note: we're abusing Rake's argument handling a bit here. We call the
88
+ # first argument `files` but it's actually only the first file--we pull
89
+ # the rest out of the `extras` from the task arguments. This is so we
90
+ # can specify an arbitrary list of files separated by commas on the
91
+ # command line or in a custom task definition.
92
+ explicit_files = Array(task_args[:files]) + Array(task_args.extras)
93
+
94
+ explicit_files.any? ? explicit_files : files
95
+ end
96
+
97
+ # Friendly description that shows the full command that will be executed.
98
+ def default_description
99
+ description = 'Run `scss-lint'
100
+ description += " --config #{config}" if config
101
+ description += " #{files.join(' ')}" if files.any?
102
+ description += ' [files...]`'
103
+ description
104
+ end
40
105
  end
41
106
  end
@@ -15,7 +15,9 @@ module SCSSLint
15
15
  end
16
16
 
17
17
  def visit_members(sequence)
18
- sequence.members.each do |member|
18
+ sequence.members
19
+ .reject { |member| member.is_a?(String) } # Skip newlines in multi-line comma seqs
20
+ .each do |member|
19
21
  visit_selector(member)
20
22
  end
21
23
  end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SCSSLint
3
- VERSION = '0.32.0'
3
+ VERSION = '0.33.0'
4
4
  end
@@ -535,4 +535,98 @@ describe SCSSLint::Linter::SelectorFormat do
535
535
  it { should report_lint }
536
536
  end
537
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(:css) { '.block {}' }
544
+
545
+ it { should_not report_lint }
546
+ end
547
+
548
+ context 'when a name contains single hyphen' do
549
+ let(:css) { '.b-block {}' }
550
+
551
+ it { should_not report_lint }
552
+ end
553
+
554
+ context 'when a name contains multiple hyphens' do
555
+ let(:css) { '.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(:css) { '.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(:css) { '.block_modifier {}' }
568
+
569
+ it { should report_lint }
570
+ end
571
+
572
+ context 'when a block has name-value modifier' do
573
+ let(:css) { '.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(:css) { '.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(:css) { '.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(:css) { '.block--modifier-value__element {}' }
592
+
593
+ it { should_not report_lint }
594
+ end
595
+
596
+ context 'when element has modifier' do
597
+ let(:css) { '.block__element--modifier-value {}' }
598
+
599
+ it { should_not report_lint }
600
+ end
601
+
602
+ context 'when element has hypenated modifier' do
603
+ let(:css) { '.block__element--modifier {}' }
604
+
605
+ it { should_not report_lint }
606
+ end
607
+
608
+ context 'when element has hypenated paired modifier' do
609
+ let(:css) { '.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(:css) { '.a_block__element--modifier {}' }
616
+
617
+ it { should report_lint }
618
+ end
619
+
620
+ context 'when an element contains an underscore' do
621
+ let(:css) { '.block__an_element--modifier {}' }
622
+
623
+ it { should report_lint }
624
+ end
625
+
626
+ context 'when a modifier contains an underscore' do
627
+ let(:css) { '.block__element--a_modifier {}' }
628
+
629
+ it { should report_lint }
630
+ end
631
+ end
538
632
  end
@@ -312,4 +312,21 @@ describe SCSSLint::Linter::SpaceAfterComma do
312
312
  it { should_not report_lint }
313
313
  end
314
314
  end
315
+
316
+ context 'when declaring list variables' do
317
+ context 'and one argument does not have a trailing comma' do
318
+ let(:css) { <<-CSS }
319
+ $z-list: (
320
+ (
321
+ name1
322
+ ),
323
+ (
324
+ name2,
325
+ )
326
+ );
327
+ CSS
328
+
329
+ it { should_not report_lint }
330
+ end
331
+ end
315
332
  end
@@ -1,20 +1,43 @@
1
1
  require 'spec_helper'
2
2
  require 'scss_lint/rake_task'
3
+ require 'tempfile'
3
4
 
4
5
  describe SCSSLint::RakeTask do
6
+ before(:all) do
7
+ SCSSLint::RakeTask.new
8
+ end
9
+
5
10
  before do
6
- # Silence console output
7
- STDOUT.stub(:write)
11
+ STDOUT.stub(:write) # Silence console output
12
+ end
13
+
14
+ let(:file) do
15
+ Tempfile.new(%w[scss-file .scss]).tap do |f|
16
+ f.write(scss)
17
+ f.close
18
+ end
8
19
  end
9
20
 
10
- describe '#run' do
11
- subject do
12
- SCSSLint::RakeTask.new
13
- Rake::Task['scss_lint']
21
+ def run_task
22
+ Rake::Task[:scss_lint].tap do |t|
23
+ t.reenable # Allows us to execute task multiple times
24
+ t.invoke(file.path)
14
25
  end
26
+ end
27
+
28
+ context 'when SCSS document is valid with no lints' do
29
+ let(:scss) { '' }
30
+
31
+ it 'does not call Kernel.exit' do
32
+ expect { run_task }.not_to raise_error
33
+ end
34
+ end
35
+
36
+ context 'when SCSS document is invalid' do
37
+ let(:scss) { '.class {' }
15
38
 
16
- it 'returns a successful exit code' do
17
- expect(subject.invoke.first.call).to be_truthy
39
+ it 'calls Kernel.exit with the status code' do
40
+ expect { run_task }.to raise_error SystemExit
18
41
  end
19
42
  end
20
43
  end
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.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-07 00:00:00.000000000 Z
12
+ date: 2015-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -271,11 +271,9 @@ test_files:
271
271
  - spec/scss_lint/linter/property_spelling_spec.rb
272
272
  - spec/scss_lint/linter/qualifying_element_spec.rb
273
273
  - spec/scss_lint/linter/selector_depth_spec.rb
274
- - spec/scss_lint/linter/selector_format_spec.rb
275
274
  - spec/scss_lint/linter/shorthand_spec.rb
276
275
  - spec/scss_lint/linter/single_line_per_property_spec.rb
277
276
  - spec/scss_lint/linter/single_line_per_selector_spec.rb
278
- - spec/scss_lint/linter/space_after_comma_spec.rb
279
277
  - spec/scss_lint/linter/space_after_property_colon_spec.rb
280
278
  - spec/scss_lint/linter/space_after_property_name_spec.rb
281
279
  - spec/scss_lint/linter/space_between_parens_spec.rb
@@ -292,6 +290,8 @@ test_files:
292
290
  - spec/scss_lint/linter/empty_line_between_blocks_spec.rb
293
291
  - spec/scss_lint/linter/bang_format_spec.rb
294
292
  - spec/scss_lint/linter/space_before_brace_spec.rb
293
+ - spec/scss_lint/linter/selector_format_spec.rb
294
+ - spec/scss_lint/linter/space_after_comma_spec.rb
295
295
  - spec/scss_lint/linter_registry_spec.rb
296
296
  - spec/scss_lint/location_spec.rb
297
297
  - spec/scss_lint/reporter/config_reporter_spec.rb
@@ -301,10 +301,10 @@ test_files:
301
301
  - spec/scss_lint/reporter/xml_reporter_spec.rb
302
302
  - spec/scss_lint/reporter_spec.rb
303
303
  - spec/scss_lint/runner_spec.rb
304
- - spec/scss_lint/selector_visitor_spec.rb
305
304
  - spec/scss_lint/linter_spec.rb
306
- - spec/scss_lint/rake_task_spec.rb
307
305
  - spec/scss_lint/options_spec.rb
306
+ - spec/scss_lint/rake_task_spec.rb
307
+ - spec/scss_lint/selector_visitor_spec.rb
308
308
  - spec/support/isolated_environment.rb
309
309
  - spec/support/matchers/report_lint.rb
310
310
  - spec/spec_helper.rb