Class: Pronto::ESLintNpm

Inherits:
Runner
  • Object
show all
Defined in:
lib/pronto/eslint_npm.rb

Constant Summary collapse

CONFIG_FILE =
'.pronto_eslint_npm.yml'.freeze
CONFIG_KEYS =
%w[eslint_executable files_to_lint cmd_line_opts].freeze
SEVERITY_LEVELS =
[nil, :warning, :error].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmd_line_optsObject



22
23
24
# File 'lib/pronto/eslint_npm.rb', line 22

def cmd_line_opts
  @cmd_line_opts || ''
end

#eslint_executableObject



14
15
16
# File 'lib/pronto/eslint_npm.rb', line 14

def eslint_executable
  @eslint_executable || 'eslint'
end

Instance Method Details

#config_optionsObject



30
31
32
33
34
35
36
# File 'lib/pronto/eslint_npm.rb', line 30

def config_options
  @config_options ||=
    begin
      config_file = File.join(repo_path, CONFIG_FILE)
      File.exist?(config_file) && YAML.load_file(config_file) || {}
    end
end

#files_to_lintObject



18
19
20
# File 'lib/pronto/eslint_npm.rb', line 18

def files_to_lint
  @files_to_lint || /(\.js|\.es6)$/
end

#files_to_lint=(regexp) ⇒ Object



26
27
28
# File 'lib/pronto/eslint_npm.rb', line 26

def files_to_lint=(regexp)
  @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp)
end

#read_configObject



38
39
40
41
42
43
# File 'lib/pronto/eslint_npm.rb', line 38

def read_config
  config_options.each do |key, val|
    next unless CONFIG_KEYS.include?(key.to_s)
    send("#{key}=", val)
  end
end

#runObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pronto/eslint_npm.rb', line 45

def run
  return [] if !@patches || @patches.count.zero?

  read_config

  @patches
    .select { |patch| patch.additions > 0 }
    .select { |patch| js_file?(patch.new_file_full_path) }
    .map { |patch| inspect(patch) }
    .flatten.compact
end