Class: SCSSLint::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/scss_lint/rake_task.rb

Overview

Provide task for invoking scss-lint via Rake.

Examples:

require 'scss_lint/rake_task'
SCSSLint::RakeTask.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &task_block) ⇒ RakeTask

Returns a new instance of RakeTask


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scss_lint/rake_task.rb', line 14

def initialize(*args, &task_block)
  @name = args.shift || :scss_lint

  desc 'Run scss-lint' unless ::Rake.application.last_comment

  task(name, *args) do |_, task_args|
    if task_block
      task_block.call(*[self, task_args].slice(0, task_block.arity))
    end
    run_task
  end
end

Instance Attribute Details

#nameObject

The name of the task (default 'scss-lint')


12
13
14
# File 'lib/scss_lint/rake_task.rb', line 12

def name
  @name
end

Instance Method Details

#run_taskObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/scss_lint/rake_task.rb', line 27

def run_task
  # Lazy load so task doesn't impact load time of Rakefile
  require 'scss_lint'

  CLI.new([]).tap do |cli|
    cli.parse_arguments
    cli.run
  end
rescue SystemExit => ex
  if ex.status == CLI::EXIT_CODES[:data]
    abort('scss-lint found lints')
  elsif ex.status != 0
    abort('scss-lint failed with an error')
  end
end