diff options
author | Markus Doits <markus.doits@stellenticket.de> | 2018-03-31 18:34:01 +0200 |
---|---|---|
committer | Markus Doits <markus.doits@stellenticket.de> | 2018-03-31 18:42:20 +0200 |
commit | c89a62b8e91dc1329aee92392eb32a51a25a8315 (patch) | |
tree | 199de267f89a7d17752a8540eeee0922c40700ce /lib | |
parent | ed98da4ce890259abc2d82006325be9f37e69908 (diff) | |
download | pronto-hlint-c89a62b8e91dc1329aee92392eb32a51a25a8315.tar.gz pronto-hlint-c89a62b8e91dc1329aee92392eb32a51a25a8315.tar.zst pronto-hlint-c89a62b8e91dc1329aee92392eb32a51a25a8315.zip |
refactor config handling and specs a little bit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pronto/eslint_npm.rb | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/pronto/eslint_npm.rb b/lib/pronto/eslint_npm.rb index e861ffe..63a215b 100644 --- a/lib/pronto/eslint_npm.rb +++ b/lib/pronto/eslint_npm.rb | |||
@@ -22,14 +22,18 @@ module Pronto | |||
22 | @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp) | 22 | @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp) |
23 | end | 23 | end |
24 | 24 | ||
25 | def read_config | 25 | def config_options |
26 | config_file = File.join(repo_path, CONFIG_FILE) | 26 | @config_options ||= |
27 | return unless File.exist?(config_file) | 27 | begin |
28 | config = YAML.load_file(config_file) | 28 | config_file = File.join(repo_path, CONFIG_FILE) |
29 | File.exist?(config_file) && YAML.load_file(config_file) || {} | ||
30 | end | ||
31 | end | ||
29 | 32 | ||
30 | CONFIG_KEYS.each do |config_key| | 33 | def read_config |
31 | next unless config[config_key] | 34 | config_options.each do |key, val| |
32 | send("#{config_key}=", config[config_key]) | 35 | next unless CONFIG_KEYS.include?(key.to_s) |
36 | send("#{key}=", val) | ||
33 | end | 37 | end |
34 | end | 38 | end |
35 | 39 | ||
@@ -48,7 +52,7 @@ module Pronto | |||
48 | private | 52 | private |
49 | 53 | ||
50 | def repo_path | 54 | def repo_path |
51 | @_repo_path ||= @patches.first.repo.path | 55 | @repo_path ||= @patches.first.repo.path |
52 | end | 56 | end |
53 | 57 | ||
54 | def inspect(patch) | 58 | def inspect(patch) |
@@ -75,13 +79,14 @@ module Pronto | |||
75 | 79 | ||
76 | def run_eslint(patch) | 80 | def run_eslint(patch) |
77 | Dir.chdir(repo_path) do | 81 | Dir.chdir(repo_path) do |
78 | escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s) | 82 | JSON.parse `#{eslint_command_line(patch.new_file_full_path.to_s)}` |
79 | JSON.parse( | ||
80 | `#{eslint_executable} #{escaped_file_path} -f json` | ||
81 | ) | ||
82 | end | 83 | end |
83 | end | 84 | end |
84 | 85 | ||
86 | def eslint_command_line(path) | ||
87 | "#{eslint_executable} #{Shellwords.escape(path)} -f json" | ||
88 | end | ||
89 | |||
85 | def clean_up_eslint_output(output) | 90 | def clean_up_eslint_output(output) |
86 | # 1. Filter out offences without a warning or error | 91 | # 1. Filter out offences without a warning or error |
87 | # 2. Get the messages for that file | 92 | # 2. Get the messages for that file |