danger-hlint 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f714598e5fe9ebdbed959a92bacb4772deb26787
4
- data.tar.gz: 8806ceb2b76218caf2f1058ce46e0fe60dbfe5f2
3
+ metadata.gz: bd14c1da49d7c97a0f54878aa2ad2e3f9d7b7485
4
+ data.tar.gz: 0e03a82a957390f5cef8b47b2e31559d684cbb8d
5
5
  SHA512:
6
- metadata.gz: 5ee44c558bd05a2e3467f010efdd34e3e7579496dc59a31e790508569e7bc8112b54a7a43412e9867b2ae8af9d347478ee189e41f2396ff4a6985c2460a7beb3
7
- data.tar.gz: 9bf3bdd6d17cd7e507d31119603f8bfc3b2805bbb88d9bd6a026d29896d8e86075268d52383581020bc1ba2887f572cd3a071073c622d09e037f92945fb3d4bb
6
+ metadata.gz: 4ba752949ec302c3244e0417fc18739231e939cce135c4a77f0041208a9134a316382435634464bcd3c1d702ac9d1ccf6ad392cd5b006e3d0131097f2b045b09
7
+ data.tar.gz: 4cd241884902f3faa17c8c7764fdedcbbed6998f6d734f035995856a49723c3be76e58bdb4260c80525277e65ff19fe97961cba8dcaf88d943487eda6ab74809
@@ -1,3 +1,3 @@
1
1
  module Hlint
2
- VERSION = "0.0.2".freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -1,53 +1,53 @@
1
1
  require 'shellwords'
2
2
 
3
3
  module Danger
4
- # This is your plugin class. Any attributes or methods you expose here will
5
- # be available from within your Dangerfile.
4
+ # Lint Haskell files inside your project using [HLint](https://github.com/ndmitchell/hlint)
6
5
  #
7
- # To be published on the Danger plugins site, you will need to have
8
- # the public interface documented. Danger uses [YARD](http://yardoc.org/)
9
- # for generating documentation from your plugin source, and you can verify
10
- # by running `danger plugins lint` or `bundle exec rake spec`.
6
+ # @example Lint a list of files
11
7
  #
12
- # You should replace these comments with a public description of your library.
13
- #
14
- # @example Ensure people are well warned about merging on Mondays
15
- #
16
- # danger_hlint.warn_on_mondays
8
+ # danger_hlint.lint(["Lib.hs"], inline_mode: true:
17
9
  #
18
10
  # @see blender/danger-hlint
19
- # @tags monday, weekends, time, rattata
11
+ # @tags hlint, haskell
20
12
  #
21
13
  class DangerHlint < Plugin
22
-
23
- # The path to the hint/ignore file used by hlint
14
+ # The list of suggestions found by hlint in JSON format
24
15
  #
25
16
  # @return [String]
26
- attr_accessor :config_file
17
+ attr_accessor :suggestions
18
+
19
+ # The list of warnings found by hlint in JSON format
20
+ #
21
+ # @return [String]
22
+ attr_accessor :warnings
23
+
24
+ # The list of errors found by hlint in JSON format
25
+ #
26
+ # @return [String]
27
+ attr_accessor :errors
27
28
 
28
29
  # Runs hlint on a list of files
29
30
  #
30
31
  # @return [void]
31
- def lint(files, inline_mode=false, options={})
32
-
33
- final_options = options.merge({ json: true })
32
+ def lint(files, inline_mode = false, options = {})
33
+ final_options = options.merge(json: true)
34
34
 
35
35
  issues = files
36
- .map { |file| Shellwords.escape(file) }
37
- .map { |file| `hlint lint #{file} #{to_hlint_options(final_options)} 2>/dev/null`}
38
- .reject { |s| s == '' }
39
- .map { |lint_result| JSON.parse(lint_result).flatten }
40
- .flatten
36
+ .map { |file| Shellwords.escape(file) }
37
+ .map { |file| `hlint lint #{file} #{to_hlint_options(final_options)} 2>/dev/null` }
38
+ .reject { |s| s == '' }
39
+ .map { |lint_result| JSON.parse(lint_result).flatten }
40
+ .flatten
41
41
 
42
- suggestions = issues.select { |issue| issue['severity'] == 'Suggestion' }
43
- warnings = issues.select { |issue| issue['severity'] == 'Warning' }
44
- errors = issues.select { |issue| issue['severity'] == 'Error' }
42
+ self.suggestions = issues.select { |issue| issue['severity'] == 'Suggestion' }
43
+ self.warnings = issues.select { |issue| issue['severity'] == 'Warning' }
44
+ self.errors = issues.select { |issue| issue['severity'] == 'Error' }
45
45
 
46
46
  if inline_mode
47
47
  # Reprt with inline comment
48
- send_inline_comment(suggestions, "warn")
49
- send_inline_comment(warnings, "warn")
50
- send_inline_comment(errors, "fail")
48
+ send_inline_comment(suggestions, 'warn')
49
+ send_inline_comment(warnings, 'warn')
50
+ send_inline_comment(errors, 'fail')
51
51
 
52
52
  else
53
53
  # Report if any suggestions, warnings or errors
@@ -59,10 +59,9 @@ module Danger
59
59
  markdown message
60
60
  end
61
61
  end
62
-
63
62
  end
64
63
 
65
- def markdown_issues (results, heading)
64
+ def markdown_issues(results, heading)
66
65
  message = "#### #{heading}\n\n"
67
66
 
68
67
  message << "File | Line | Hint | Found | Suggested\n"
@@ -72,8 +71,8 @@ module Danger
72
71
  filename = r['file'].split('/').last
73
72
  line = r['startLine']
74
73
  hint = r['hint']
75
- from = r['from'].gsub("\n", "<br />")
76
- to = r['to'].gsub("\n", "<br />")
74
+ from = r['from'].gsub("\n", '<br />')
75
+ to = r['to'].gsub("\n", '<br />')
77
76
 
78
77
  message << "#{filename} | #{line} | #{hint} | #{from} | #{to}\n"
79
78
  end
@@ -81,23 +80,23 @@ module Danger
81
80
  message
82
81
  end
83
82
 
84
- def send_inline_comment (results, method)
85
- dir = "#{Dir.pwd}/"
86
- results.each do |r|
87
- filename = r['file'].gsub(dir, "")
83
+ def send_inline_comment(results, method)
84
+ dir = "#{Dir.pwd}/"
85
+ results.each do |r|
86
+ filename = r['file'].gsub(dir, '')
88
87
 
89
- prompt = r['severity'] == 'Suggestion' || r['severity'] == 'Warning' ? "Why Not" : ""
90
- prompt = r['severity'] == 'Error' ? "Error description" : prompt
88
+ prompt = r['severity'] == 'Suggestion' || r['severity'] == 'Warning' ? 'Why Not' : ''
89
+ prompt = r['severity'] == 'Error' ? 'Error description' : prompt
91
90
 
92
- message = "Found #{r['hint']}\n\n```haskell\n#{r['from']}\n``` \n\n #{prompt} \n\n ```haskell\n#{r['to']}\n```"
93
- send(method, message, file: filename, line: r['startLine'])
94
- end
91
+ message = "Found #{r['hint']}\n\n```haskell\n#{r['from']}\n``` \n\n #{prompt} \n\n ```haskell\n#{r['to']}\n```"
92
+ send(method, message, file: filename, line: r['startLine'])
93
+ end
95
94
  end
96
95
 
97
- def to_hlint_options(options={})
96
+ def to_hlint_options(options = {})
98
97
  options.
99
98
  # filter not null
100
- select {|key, value| !value.nil?}.
99
+ reject { |_key, value| value.nil? }.
101
100
  # map booleans arguments equal true
102
101
  map { |key, value| value.is_a?(TrueClass) ? [key, ''] : [key, value] }.
103
102
  # map booleans arguments equal false
@@ -113,6 +112,5 @@ module Danger
113
112
  end
114
113
 
115
114
  private :send_inline_comment, :to_hlint_options, :markdown_issues
116
-
117
115
  end
118
116
  end
@@ -15,22 +15,15 @@ module Danger
15
15
  @hlint = @dangerfile.hlint
16
16
  allow(@hlint.git).to receive(:added_files).and_return([])
17
17
  allow(@hlint.git).to receive(:modified_files).and_return([])
18
-
19
- @hlint_response = '[{"module":"HaskellTestFile","decl":"foo","severity":"Warning","hint":"Use concatMap","file":"./HaskellTestFile.hs","startLine":6,"startColumn":10,"endLine":6,"endColumn":28,"from":"concat (map id xs)","to":"concatMap id xs","note":[],"refactorings":"[Replace {rtype = Expr, pos = SrcSpan {startLine = 6, startCol = 10, endLine = 6, endCol = 28}, subts = [(\"f\",SrcSpan {startLine = 6, startCol = 22, endLine = 6, endCol = 24}),(\"x\",SrcSpan {startLine = 6, startCol = 25, endLine = 6, endCol = 27})], orig = \"concatMap f x\"}]"}
20
- ,{"module":"HaskellTestFile","decl":"foo","severity":"Warning","hint":"Use id","file":"./HaskellTestFile.hs","startLine":6,"startColumn":18,"endLine":6,"endColumn":24,"from":"map id","to":"id","note":[],"refactorings":"[Replace {rtype = Expr, pos = SrcSpan {startLine = 6, startCol = 18, endLine = 6, endCol = 24}, subts = [], orig = \"id\"}]"}]'
21
-
22
18
  end
23
19
 
24
20
  # Some examples for writing tests
25
21
  # You should replace these with your own.
26
22
 
27
- it "collects Warnings" do
28
- expect(DangerHlint).to receive(:lint)
29
- .with(File.expand_path('spec/fixtures/HaskellTestFile.hs'), hash_including(:inline_mode => true))
30
- .and_return(@hlint_response)
31
-
23
+ it 'collects Warnings' do
24
+ @hlint.lint([File.expand_path('spec/fixtures/HaskellTestFile.hs')], inline_mode: true)
25
+ expect(@hlint.warnings).to all(include('severity' => 'Warning'))
32
26
  end
33
-
34
27
  end
35
28
  end
36
29
  end
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
  ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
- $:.unshift((ROOT + 'lib').to_s)
4
- $:.unshift((ROOT + 'spec').to_s)
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
5
 
6
6
  require 'bundler/setup'
7
7
  require 'pry'
@@ -11,7 +11,7 @@ require 'danger'
11
11
 
12
12
  # Use coloured output, it's the best.
13
13
  RSpec.configure do |config|
14
- config.filter_gems_from_backtrace "bundler"
14
+ config.filter_gems_from_backtrace 'bundler'
15
15
  config.color = true
16
16
  config.tty = true
17
17
  end
@@ -34,7 +34,7 @@ def testing_ui
34
34
 
35
35
  cork = Cork::Board.new(out: @output)
36
36
  def cork.string
37
- out.string.gsub(/\e\[([;\d]+)?m/, "")
37
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
38
38
  end
39
39
  cork
40
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-hlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Piazza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api