Class: FoodCritic::Rake::LintTask

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :foodcritic) {|_self| ... } ⇒ LintTask

Returns a new instance of LintTask.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
# File 'lib/foodcritic/rake_task.rb', line 9

def initialize(name = :foodcritic)
  @name = name
  @files = [Dir.pwd]
  @options = {}
  yield self if block_given?
  define
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



7
8
9
# File 'lib/foodcritic/rake_task.rb', line 7

def files
  @files
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/foodcritic/rake_task.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/foodcritic/rake_task.rb', line 7

def options
  @options
end

Instance Method Details

#defineObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/foodcritic/rake_task.rb', line 17

def define
  desc "Lint Chef cookbooks" unless ::Rake.application.last_description
  task(name) do
    puts "Starting Foodcritic linting..."
    result = FoodCritic::Linter.new.check(default_options.merge(options))
    printer = if options[:context]
                ContextOutput.new($stdout)
              else
                SummaryOutput.new($stdout)
              end
    printer.output(result) if result.warnings.any?
    abort if result.failed?
    puts "Completed!"
  end
end