1 # frozen_string_literal: true
8 class Runner
< Pronto
::Runner
9 CONFIG_FILE
= '.pronto_hlint.yml'.freeze
10 CONFIG_KEYS
= %w
[hlint_executable files_to_lint cmd_line_opts
].freeze
12 attr_writer
:hlint_executable, :cmd_line_opts
15 @hlint_executable || 'hlint'
19 @files_to_lint || /(\.hs)$/
26 def files_to_lint
=(regexp
)
27 @files_to_lint = regexp
.is_a
?(Regexp
) && regexp
|| Regexp
.new(regexp
)
33 config_file
= File
.join(repo_path
, CONFIG_FILE
)
34 File
.exist
?(config_file
) && YAML
.load_file(config_file
) || {}
39 config_options
.each
do |key
, val
|
40 next unless CONFIG_KEYS
.include?(key
.to_s
)
46 return [] if !
@patches || @patches.count
.zero
?
51 .select
{ |patch
| patch
.additions
> 0 }
52 .select
{ |patch
| hs_file
?(patch
.new_file_full_path
) }
53 .map
{ |patch
| inspect(patch
) }
60 @repo_path ||= @patches.first
.repo
.path
64 offences
= run_hlint(patch
)
69 .select
{ |line
| (offence
['startLine']..offence
['endLine']).include?(line
.new_lineno
) }
70 .map
{ |line
| new_message(offence
, line
) }
74 def new_message(offence
, line
)
75 path
= line
.patch
.delta
.new_file
[:path]
76 level
= hlint_severity_to_pronto_level(offence
['severity']) || :warning
79 #{offence['severity']} offence detected by Hlint. Hint is: `#{offence['hint']}`.
81 Consider changing the code from
91 Message
.new(path
, line
, level
, text
, nil, self.class)
94 def hlint_severity_to_pronto_level(severity
)
106 files_to_lint
=~ path
.to_s
110 Dir
.chdir(repo_path
) do
111 JSON
.parse
`#{hlint_command_line(patch.new_file_full_path.to_s)}`
115 def hlint_command_line(path
)
116 "#{hlint_executable} #{cmd_line_opts} #{Shellwords.escape(path)} --json"