Class: Danger::DangerEslint

Inherits:
Plugin
  • Object
show all
Defined in:
lib/eslint/plugin.rb

Overview

Lint javascript files using [eslint](eslint.org/). Results are send as inline commen.

Examples:

Run eslint with changed files only


eslint.filtering = true
eslint.lint

See Also:

  • leonhartX/danger-eslint

Constant Summary collapse

DEFAULT_BIN_PATH =
'./node_modules/.bin/eslint'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bin_pathObject



33
34
35
# File 'lib/eslint/plugin.rb', line 33

def bin_path
  @bin_path ||= DEFAULT_BIN_PATH
end

#config_fileString

An path to eslint’s config file

Returns:

  • (String)


20
21
22
# File 'lib/eslint/plugin.rb', line 20

def config_file
  @config_file
end

#filteringBoolean

Enable filtering Only show messages within changed files.

Returns:

  • (Boolean)


29
30
31
# File 'lib/eslint/plugin.rb', line 29

def filtering
  @filtering
end

#ignore_fileString

An path to eslint’s ignore file

Returns:

  • (String)


24
25
26
# File 'lib/eslint/plugin.rb', line 24

def ignore_file
  @ignore_file
end

#target_extensionsObject



41
42
43
# File 'lib/eslint/plugin.rb', line 41

def target_extensions
  @target_extensions ||= %W(.js)
end

Instance Method Details

#lintvoid

This method returns an undefined value.

Lints javascript files. Generates ‘errors` and `warnings` due to eslint’s config. Will try to send inline comment if supported(Github)



51
52
53
54
55
56
# File 'lib/eslint/plugin.rb', line 51

def lint
  lint_results
    .reject { |r| r.nil? || r['messages'].length.zero? }
    .reject { |r| r['messages'].first['message'].include? 'matching ignore pattern' }
    .map { |r| send_comment r }
end