Class: Guard::Eslint

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/eslint.rb,
lib/guard/eslint/runner.rb

Defined Under Namespace

Classes: Runner

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Eslint

Initializes a Guard plugin. Don’t do any work here, especially as Guard plugins get initialized

even if they are not in an active group!

Parameters:

  • options (Hash) (defaults to: {})

    the custom Guard plugin options

Options Hash (options):

  • watchers (Array<Guard::Watcher>)

    the Guard plugin file watchers

  • group (Symbol)

    the group this Guard plugin belongs to

  • any_return (Boolean)

    allow any object to be returned from a watcher



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/guard/eslint.rb', line 16

def initialize(options = {})
  super

  @options = {
    all_on_start: false,
    keep_failed: false,
    notification: :failed,
    cli: nil,
    formatter: nil,
    command: 'eslint',
    default_paths: ['**/*.js', '**/*.es6'],
  }.merge(options)

  @failed_paths = []
end

Instance Method Details

#reloadObject

Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading

passenger/spork/bundler/...

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when reload has failed



49
50
51
# File 'lib/guard/eslint.rb', line 49

def reload
  runner.reload
end

#run_allObject

Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_all has failed



59
60
61
62
# File 'lib/guard/eslint.rb', line 59

def run_all
  Compat::UI.info 'Inspecting all Javascript files'
  inspect_with_eslint
end

#run_on_additions(paths) ⇒ Object

Called on file(s) additions that the Guard plugin watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_additions has failed



70
71
72
# File 'lib/guard/eslint.rb', line 70

def run_on_additions(paths)
  run_partially(paths)
end

#run_on_modifications(paths) ⇒ Object

Called on file(s) modifications that the Guard plugin watches.

Parameters:

  • paths (Array<String>)

    the changes files or paths

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when run_on_modifications has failed



80
81
82
# File 'lib/guard/eslint.rb', line 80

def run_on_modifications(paths)
  run_partially(paths)
end

#startObject

Called once when Guard starts. Please override initialize method to init stuff.

Returns:

  • (Object)

    the task result

Raises:

  • (:task_has_failed)

    when start has failed



37
38
39
40
# File 'lib/guard/eslint.rb', line 37

def start
  Compat::UI.info 'Guard::ESLint is running'
  run_all if options[:all_on_start]
end