Class: JSLintV8::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/jslint-v8/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jslint-v8/rake_task.rb', line 30

def initialize
  # a default name
  @name = "lint"
  
  # a default description
  @description = "Runs the JSLint Test Suite"

  # by default a glob pattern that will include javascript files found in rails
  @include_pattern = "app/javascripts/**/*.js"

  # by default a glob pattern which will match no files
  @exclude_pattern = ""

  # by default use standard output for writing information
  @output_stream = STDOUT

  # by default provide no overridden lint options
  @lint_options = {}

  # if a block was given allow the block to call elements on this object
  yield self if block_given?

  # create the rake task
  new_task = task(name) do
    formatter = JSLintV8::Formatter.new(output_stream)

    lint_result = runner.run do |file, errors|
      formatter.tick(errors)
    end

    # put a separator line in between the ticks and any summary
    output_stream.print "\n"

    # print a summary of failed files
    formatter.summary(files_to_run, lint_result)

    # raise an exception if there are errors
    raise "jslint suite failed" unless lint_result.empty?
  end
  
  # assign the description to the rake task
  new_task.comment = description
end

Instance Attribute Details

#descriptionObject

description for the task



10
11
12
# File 'lib/jslint-v8/rake_task.rb', line 10

def description
  @description
end

#exclude_patternObject

exclusion glob pattern for files



16
17
18
# File 'lib/jslint-v8/rake_task.rb', line 16

def exclude_pattern
  @exclude_pattern
end

#include_patternObject

inclusion glob pattern for files



13
14
15
# File 'lib/jslint-v8/rake_task.rb', line 13

def include_pattern
  @include_pattern
end

#lint_optionsObject

custom lint options for the task



22
23
24
# File 'lib/jslint-v8/rake_task.rb', line 22

def lint_options
  @lint_options
end

#nameObject

name of the rake task



7
8
9
# File 'lib/jslint-v8/rake_task.rb', line 7

def name
  @name
end

#output_streamObject

output stream for this task



19
20
21
# File 'lib/jslint-v8/rake_task.rb', line 19

def output_stream
  @output_stream
end

Instance Method Details

#files_to_runObject

Returns a list of all files to run, sorted



77
78
79
80
81
82
# File 'lib/jslint-v8/rake_task.rb', line 77

def files_to_run
  included_files = Dir.glob(include_pattern)
  excluded_files = Dir.glob(exclude_pattern)

  (included_files - excluded_files).sort
end