Class: Eslintrb::EslintTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/eslintrb/eslinttask.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :eslint) {|_self| ... } ⇒ EslintTask

Defines a new task, using the name name.

Yields:

  • (_self)

Yield Parameters:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eslintrb/eslinttask.rb', line 37

def initialize(name=:eslint)
  @name = name
  @pattern = nil
  @js_files = nil
  @exclude_pattern = nil
  @exclude_js_files = nil
  @options = nil
  @globals = nil
  @fail_on_error = true

  yield self if block_given?
  @pattern = './**/*.js' if pattern.nil? && js_files.nil?
  define
end

Instance Attribute Details

#exclude_js_filesObject

Returns the value of attribute exclude_js_files.



34
35
36
# File 'lib/eslintrb/eslinttask.rb', line 34

def exclude_js_files
  @exclude_js_files
end

#exclude_patternObject

Returns the value of attribute exclude_pattern.



32
33
34
# File 'lib/eslintrb/eslinttask.rb', line 32

def exclude_pattern
  @exclude_pattern
end

#fail_on_errorObject

Whether or not to fail Rake when an error occurs (typically when ESLint check fail). Defaults to true.



24
25
26
# File 'lib/eslintrb/eslinttask.rb', line 24

def fail_on_error
  @fail_on_error
end

#globalsObject

Returns the value of attribute globals.



20
21
22
# File 'lib/eslintrb/eslinttask.rb', line 20

def globals
  @globals
end

#js_filesObject

Explicitly define the list of JavaScript files to be linted. js_files is expected to be an array of file names (a FileList is acceptable). If both pattern and js_files are used, then the list of JavaScritp files is the union of the two.



30
31
32
# File 'lib/eslintrb/eslinttask.rb', line 30

def js_files
  @js_files
end

#nameObject

Name of ESLint task. (default is :eslint)



12
13
14
# File 'lib/eslintrb/eslinttask.rb', line 12

def name
  @name
end

#optionsObject

options



18
19
20
# File 'lib/eslintrb/eslinttask.rb', line 18

def options
  @options
end

#patternObject

Glob pattern to match JavaScript files. (default is ‘./*/.js’)



15
16
17
# File 'lib/eslintrb/eslinttask.rb', line 15

def pattern
  @pattern
end

Instance Method Details

#defineObject

:nodoc:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/eslintrb/eslinttask.rb', line 52

def define # :nodoc:

  actual_name = Hash === name ? name.keys.first : name
  unless ::Rake.application.last_description
    desc "Run ESLint"
  end
  task name do
    unless js_file_list.empty?
      result = Eslintrb::report(js_file_list, @options, @globals, STDERR)
      if result.size > 0
        abort("ESLint check failed") if fail_on_error
      end
    end
  end

  self
end

#evaluate(o) ⇒ Object

:nodoc:



70
71
72
73
74
75
# File 'lib/eslintrb/eslinttask.rb', line 70

def evaluate(o) # :nodoc:
  case o
    when Proc then o.call
    else o
  end
end

#js_file_listObject

:nodoc:



77
78
79
80
81
82
83
84
# File 'lib/eslintrb/eslinttask.rb', line 77

def js_file_list # :nodoc:
    result = []
    result += js_files.to_a if js_files
    result += FileList[ pattern ].to_a if pattern
    result -= exclude_js_files.to_a if exclude_js_files
    result -= FileList[ exclude_pattern ].to_a if exclude_pattern
    FileList[result]
end