single_cov 2.0.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e47ea219fd0ed2b3d8911ca9679c4de43988ba900072e7a3efe349275d230f8b
4
- data.tar.gz: 24410aaf39a37f4301723bc53b76cbccfeb596ceed364a4ebe4dfbdde54a3556
3
+ metadata.gz: 03abb741a629409eca737e84185cbd61c34a24a65fdb5b4c381d295f00690eed
4
+ data.tar.gz: fee46d0a03e4812f372c375745ff9a02229292bc1c153e028ee7dc46691edfb0
5
5
  SHA512:
6
- metadata.gz: 0dd92b86bfa607cfb908cfaa7fc2a5b8e74da99a92d6a116cc88dbf2b241cc27664c027814989cb6e7d180bed5d7dff65e181c76cb71181340e0d947d7a0d183
7
- data.tar.gz: c42f4b53dfc9e16cb72b57e8180cf81c9cad57dbf1be0f549ceb480e16dd31d7030130dfca58e731dc3398ff61a82d05eeafb9b5fa2a7b905dd43ca6ab60bfa4
6
+ metadata.gz: 52da7209346a1ec927241e0db7390d664ef155a6146642e0895964cbcaa7c6e704ee6dc027591032fcb4727546543de60aa68ddd57f9b7e5f8879b9c98169a73
7
+ data.tar.gz: 3f0ae6f966cb07c608efd71cc8b87787c7506363c8bf2e43c4e334cf88b51122f56d2ad56864afc302b7158339eb4c5f3d8935f8a924c3132e43ab216604f700
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SingleCov
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
data/lib/single_cov.rb CHANGED
@@ -4,6 +4,7 @@ module SingleCov
4
4
  MAX_OUTPUT = Integer(ENV["SINGLE_COV_MAX_OUTPUT"] || "40")
5
5
  RAILS_APP_FOLDERS = ["models", "serializers", "helpers", "controllers", "mailers", "views", "jobs", "channels"]
6
6
  UNCOVERED_COMMENT_MARKER = /#.*uncovered/
7
+ NOCOV_MARKER = /^\s*#\s*:nocov:/ # see https://github.com/simplecov-ruby/simplecov/blob/00376ea2f29ce7a7355b7c2d7d094b666b57cb9b/lib/simplecov/lines_classifier.rb#L16
7
8
  PREFIXES_TO_IGNORE = [] # things to not prefix with lib/ etc
8
9
 
9
10
  class << self
@@ -40,8 +41,10 @@ module SingleCov
40
41
  # ignore lines that are marked as uncovered via comments
41
42
  # TODO: warn when using uncovered but the section is indeed covered
42
43
  content = File.readlines("#{root}/#{file}")
44
+ nocov_lines_nums = nocov_line_numbers(content)
43
45
  uncovered.reject! do |line_start, _, _, _, _|
44
- content[line_start - 1].match?(UNCOVERED_COMMENT_MARKER)
46
+ content[line_start - 1].match?(UNCOVERED_COMMENT_MARKER) ||
47
+ nocov_lines_nums.include?(line_start)
45
48
  end
46
49
  next if uncovered.size == expected_uncovered
47
50
 
@@ -215,6 +218,19 @@ module SingleCov
215
218
  Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
216
219
  end
217
220
 
221
+ # @returns [Integer] 1-based line numbers that are inside :nocov: blocks
222
+ def nocov_line_numbers(content)
223
+ inside = false
224
+ content.each_with_index.filter_map do |line, index|
225
+ if line.match?(NOCOV_MARKER)
226
+ inside = !inside # toggle
227
+ nil # line itself cannot be uncovered since it is only a comment
228
+ elsif inside
229
+ index + 1
230
+ end
231
+ end
232
+ end
233
+
218
234
  def indexes(list, find)
219
235
  list.each_with_index.filter_map { |v, i| i if v == find }
220
236
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: single_cov
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser