pronto-hlint 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/lib/pronto/hlint.rb +8 -0
- data/lib/pronto/hlint/runner.rb +120 -0
- data/lib/pronto/hlint/version.rb +7 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 441848a65b4876773f2995a8d59b9cb9768c1b51991ab0d90d706f80970b94b0
|
4
|
+
data.tar.gz: 86bd2cad174dd7aa95ab930711adacb060902a52c7130dd72830354445bd3744
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29b217d89d38d7e8397777523c90459161563cdc2ea5b864a8a1d378bdbbb4694000e8548389a2c938f553cef84e49aa759342cfb56484cf7a469ec9e93dd868
|
7
|
+
data.tar.gz: 3b49d909bae096fbef0da5d1a9237879e2e914ce50b7007cd7471b76e6a05832d04aed010ee909029a2bd66d3021290ddd8af8570cfbb40db62ecba512bbd877
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Fretlink
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Pronto runner for Hlint
|
2
|
+
|
3
|
+
[](https://travis-ci.org/fretlink/pronto-hlint)
|
4
|
+
[](http://badge.fury.io/rb/pronto-hlint)
|
5
|
+
|
6
|
+
Pronto runner for [Hlint](https://hackage.haskell.org/package/hlint), pluggable linting utility for Haskell. [What is Pronto?](https://github.com/mmozuras/pronto)
|
7
|
+
|
8
|
+
## Prerequisites
|
9
|
+
|
10
|
+
You'll need to install [hlint by yourself with cabal or stack][hlint-install]. If `hlint` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-hlint your custom executable path (see [below](#configuration-of-hlint)).
|
11
|
+
|
12
|
+
[hlint-install]: https://github.com/ndmitchell/hlint#installing-and-running-hlint
|
13
|
+
|
14
|
+
## Configuration of Hlint
|
15
|
+
|
16
|
+
Configuring Hlint via [.hlint.yaml][.hlint.yaml] will work just fine with pronto-hlint.
|
17
|
+
|
18
|
+
[.hlint.yaml]: https://github.com/ndmitchell/hlint#customizing-the-hints
|
19
|
+
|
20
|
+
## Configuration of Pronto-Hlint
|
21
|
+
|
22
|
+
pronto-hlint can be configured by placing a `.pronto_hlint.yml` inside the directory where pronto will run.
|
23
|
+
|
24
|
+
Following options are available:
|
25
|
+
|
26
|
+
| Option | Meaning | Default |
|
27
|
+
| ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |
|
28
|
+
| hlint_executable | Hlint executable to call. | `hlint` (calls `hlint` in `PATH`) |
|
29
|
+
| files_to_lint | What files to lint. Absolute path of offending file will be matched against this Regexp. | `(\.hs)$` |
|
30
|
+
| cmd_line_opts | Command line options to pass to hlint when running | `` |
|
31
|
+
|
32
|
+
Example configuration to call custom hlint executable and only lint files ending with `.my_custom_extension`:
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
# .pronto_hlint.yml
|
36
|
+
hlint_executable: '/my/custom/path/.bin/hlint'
|
37
|
+
files_to_lint: '\.my_custom_extension$'
|
38
|
+
cmd_line_opts: '-j $(nproc) --typecheck'
|
39
|
+
```
|
data/lib/pronto/hlint.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pronto'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
module Pronto
|
7
|
+
module Hlint
|
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
|
11
|
+
|
12
|
+
attr_writer :hlint_executable, :cmd_line_opts
|
13
|
+
|
14
|
+
def hlint_executable
|
15
|
+
@hlint_executable || 'hlint'
|
16
|
+
end
|
17
|
+
|
18
|
+
def files_to_lint
|
19
|
+
@files_to_lint || /(\.hs)$/
|
20
|
+
end
|
21
|
+
|
22
|
+
def cmd_line_opts
|
23
|
+
@cmd_line_opts || ''
|
24
|
+
end
|
25
|
+
|
26
|
+
def files_to_lint=(regexp)
|
27
|
+
@files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp)
|
28
|
+
end
|
29
|
+
|
30
|
+
def config_options
|
31
|
+
@config_options ||=
|
32
|
+
begin
|
33
|
+
config_file = File.join(repo_path, CONFIG_FILE)
|
34
|
+
File.exist?(config_file) && YAML.load_file(config_file) || {}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_config
|
39
|
+
config_options.each do |key, val|
|
40
|
+
next unless CONFIG_KEYS.include?(key.to_s)
|
41
|
+
send("#{key}=", val)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def run
|
46
|
+
return [] if !@patches || @patches.count.zero?
|
47
|
+
|
48
|
+
read_config
|
49
|
+
|
50
|
+
@patches
|
51
|
+
.select { |patch| patch.additions > 0 }
|
52
|
+
.select { |patch| hs_file?(patch.new_file_full_path) }
|
53
|
+
.map { |patch| inspect(patch) }
|
54
|
+
.flatten.compact
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def repo_path
|
60
|
+
@repo_path ||= @patches.first.repo.path
|
61
|
+
end
|
62
|
+
|
63
|
+
def inspect(patch)
|
64
|
+
offences = run_hlint(patch)
|
65
|
+
offences
|
66
|
+
.map do |offence|
|
67
|
+
patch
|
68
|
+
.added_lines
|
69
|
+
.select { |line| (offence['startLine']..offence['endLine']).include?(line.new_lineno) }
|
70
|
+
.map { |line| new_message(offence, line) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def new_message(offence, line)
|
75
|
+
path = line.patch.delta.new_file[:path]
|
76
|
+
level = hlint_severity_to_pronto_level(offence['severity']) || :warning
|
77
|
+
|
78
|
+
text = <<~EOF
|
79
|
+
#{offence['severity']} offence detected by Hlint. Hint is: `#{offence['hint']}`.
|
80
|
+
|
81
|
+
Consider changing the code from
|
82
|
+
```
|
83
|
+
#{offence['from']}
|
84
|
+
```
|
85
|
+
to
|
86
|
+
```
|
87
|
+
#{offence['to']}
|
88
|
+
```
|
89
|
+
EOF
|
90
|
+
|
91
|
+
Message.new(path, line, level, text, nil, self.class)
|
92
|
+
end
|
93
|
+
|
94
|
+
def hlint_severity_to_pronto_level(severity)
|
95
|
+
case severity
|
96
|
+
when "Error"
|
97
|
+
:error
|
98
|
+
when "Warning"
|
99
|
+
:warning
|
100
|
+
when "Suggestion"
|
101
|
+
:info
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def hs_file?(path)
|
106
|
+
files_to_lint =~ path.to_s
|
107
|
+
end
|
108
|
+
|
109
|
+
def run_hlint(patch)
|
110
|
+
Dir.chdir(repo_path) do
|
111
|
+
JSON.parse `#{hlint_command_line(patch.new_file_full_path.to_s)}`
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def hlint_command_line(path)
|
116
|
+
"#{hlint_executable} #{cmd_line_opts} #{Shellwords.escape(path)} --json"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-hlint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Bonaud
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '11.0'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '13'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '11.0'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '13'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.4'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.4'
|
75
|
+
description:
|
76
|
+
email: paul.bonaud@fretlink.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files:
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
files:
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- lib/pronto/hlint.rb
|
86
|
+
- lib/pronto/hlint/runner.rb
|
87
|
+
- lib/pronto/hlint/version.rb
|
88
|
+
homepage: https://github.com/fretlink/pronto-hlint
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 2.3.0
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements:
|
107
|
+
- hlint (in PATH)
|
108
|
+
rubygems_version: 3.0.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Pronto runner for Hlint, pluggable linting utility for Haskell
|
112
|
+
test_files: []
|