pronto-undercover 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 23a9e88cb350120dd32a0d30c92e6cf3dd5c015413c0ee3c16a700b6a4ada53d
4
- data.tar.gz: fa21ebfb5b108a702c33d4677e9dfa6d073123bce9f2f2c5181f3d6a03a72de9
3
+ metadata.gz: 3de1d2e492a7103e77d719748a7271d48bb3030413bc226ff9d709fb10bbd198
4
+ data.tar.gz: 35a280e62e729d415cb8763ad10671dce35db4127da44319c8be6d51e146a8f1
5
5
  SHA512:
6
- metadata.gz: 868fd2ee69c581041f33be5adce989896df204bad5fb48a263b4938cb303dffc0e03064670eefb055729fcea6c0dc62e7ce3d9199f9f3a00a2b2dd36bbd12656
7
- data.tar.gz: fd26c906d8e29db5ba13962f2833e8aa30146d237a946c2b87882314a4dbae839be40c3ab7e7f21debf0907dd45eb8c2baf4bc9c4085f446c9c416d47f2f6228
6
+ metadata.gz: d468fe8c175ecbe4ded4431e8f0102258166f1dbadaa33ed28b93d0f8c88fcface1ca4c4f3c8c21b3063f6c6844fb565067824f0133a99482289e126cbecaedc
7
+ data.tar.gz: 7f3472e588da2f7f3028cde205a903a7e7d3d64e8ec1e83f59542df2d4c2aa0a70ee4829789719c7817d01ad5fb8d2e7272e5f7cb8224f68ef00a2d6a34fe0e1
data/.rubocop.yml CHANGED
@@ -12,6 +12,10 @@ Layout/SpaceInsideHashLiteralBraces:
12
12
  Enabled: true
13
13
  EnforcedStyle: no_space
14
14
 
15
+ Metrics/LineLength:
16
+ Enabled: True
17
+ Max: 100
18
+
15
19
  Metrics/BlockLength:
16
20
  Enabled: true
17
21
  Exclude:
@@ -17,11 +17,12 @@ module Pronto
17
17
 
18
18
  # @return Array[Pronto::Message]
19
19
  def run
20
- return [] unless @patches.first
21
- report = ::Undercover::Report.new(
22
- @patch_changeset, undercover_options
23
- ).build
24
- report.build_warnings.map(&method(:undercover_warning_to_message))
20
+ return [] if !@patches || @patches.count.zero?
21
+
22
+ @patches
23
+ .select { |patch| patch.additions.positive? }
24
+ .map { |patch| patch_to_undercover_message(patch) }
25
+ .flatten.compact
25
26
  rescue Errno::ENOENT => e
26
27
  warn("Could not open file! #{e}")
27
28
  []
@@ -29,20 +30,40 @@ module Pronto
29
30
 
30
31
  private
31
32
 
32
- # rubocop:disable Metrics/AbcSize
33
- def undercover_warning_to_message(warning)
34
- lines = untested_lines_for(warning)
35
- msg = "#{warning.node.human_name} #{warning.node.name} missing tests" \
36
- " for line#{'s' if lines.size > 1} #{lines.join(', ')}" \
37
- " (coverage: #{warning.coverage_f})"
38
-
39
- line = @patches.find_line(
40
- Pathname.new(File.expand_path(warning.file_path)),
41
- warning.first_line
42
- )
43
- Message.new(warning.file_path, line, DEFAULT_LEVEL, msg)
33
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
34
+ def patch_to_undercover_message(patch)
35
+ offending_line_numbers(patch).map do |warning, msg_line_no|
36
+ patch
37
+ .added_lines
38
+ .select { |line| line.new_lineno == msg_line_no }
39
+ .map do |line|
40
+ lines = untested_lines_for(warning)
41
+ path = line.patch.delta.new_file[:path]
42
+ msg = "#{warning.node.human_name} #{warning.node.name} missing tests" \
43
+ " for line#{'s' if lines.size > 1} #{lines.join(', ')}" \
44
+ " (coverage: #{warning.coverage_f})"
45
+ Message.new(path, line, DEFAULT_LEVEL, msg)
46
+ end
47
+ end
48
+ end
49
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
50
+
51
+ def undercover_warnings
52
+ @undercover_warnings ||= ::Undercover::Report.new(
53
+ @patch_changeset, undercover_options
54
+ ).build.build_warnings
55
+ end
56
+
57
+ def offending_line_numbers(patch)
58
+ patch_lines = patch.added_lines.map(&:position)
59
+ path = patch.new_file_full_path.to_s
60
+ undercover_warnings
61
+ .select { |warning| File.expand_path(warning.file_path) == path }
62
+ .map do |warning|
63
+ first_line_no = patch_lines.find { |l| warning.uncovered?(l) }
64
+ [warning, first_line_no] if first_line_no
65
+ end.compact
44
66
  end
45
- # rubocop:enable Metrics/AbcSize
46
67
 
47
68
  def untested_lines_for(warning)
48
69
  warning.coverage.map do |ln, _cov|
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pronto
4
4
  module UndercoverVersion
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-undercover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Grodowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-07 00:00:00.000000000 Z
11
+ date: 2018-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pronto