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).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eslint_executableObject



11
12
13
# File 'lib/pronto/eslint_npm.rb', line 11

def eslint_executable
  @eslint_executable || 'eslint'.freeze
end

Instance Method Details

#files_to_lintObject



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

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

#files_to_lint=(regexp) ⇒ Object



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

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

#read_configObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/pronto/eslint_npm.rb', line 23

def read_config
  config_file = File.join(repo_path, CONFIG_FILE)
  return unless File.exist?(config_file)
  config = YAML.load_file(config_file)

  CONFIG_KEYS.each do |config_key|
    next unless config[config_key]
    send("#{config_key}=", config[config_key])
  end
end

#runObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pronto/eslint_npm.rb', line 34

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