single_cov 2.0.0 → 2.2.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: 12be958e8135fecd7c8e8dc446b97cae5dd0a7d1397c33ea851cffdeb7389ee0
4
+ data.tar.gz: 315153f27ef5c680a52584c95e28d96904b10c3c9a094d5e19b06ebac66dbfc1
5
5
  SHA512:
6
- metadata.gz: 0dd92b86bfa607cfb908cfaa7fc2a5b8e74da99a92d6a116cc88dbf2b241cc27664c027814989cb6e7d180bed5d7dff65e181c76cb71181340e0d947d7a0d183
7
- data.tar.gz: c42f4b53dfc9e16cb72b57e8180cf81c9cad57dbf1be0f549ceb480e16dd31d7030130dfca58e731dc3398ff61a82d05eeafb9b5fa2a7b905dd43ca6ab60bfa4
6
+ metadata.gz: e3c97161e9ef85134dd6456b5e4ee75c0c9f0c5fe238f64bb5fbf9b9551e3773833f00ace1f567e4071e33f95d0b85fb79d0841765e1b2ddac83cd9a70ada3a9
7
+ data.tar.gz: 3bbf1d85f580c4affb6672c5d8b5ac4523b896379b282146484d7199ff9fb79263c96b692b22edd47b5bdd32269a3ac547ea67e4b48d38d32e5ff4956519406b
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SingleCov
3
- VERSION = "2.0.0"
3
+ VERSION = "2.2.0"
4
4
  end
data/lib/single_cov.rb CHANGED
@@ -4,6 +4,10 @@ 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
8
+ SIMPLECOV_DISABLE_MARKER = /#\s*simplecov:disable\b/ # see https://github.com/simplecov-ruby/simplecov/blob/main/docs/Configuration.md#ignoringskipping-code
9
+ SIMPLECOV_DISABLE_BLOCK_MARKER = /^\s*#\s*simplecov:disable\b/
10
+ SIMPLECOV_ENABLE_BLOCK_MARKER = /^\s*#\s*simplecov:enable\b/
7
11
  PREFIXES_TO_IGNORE = [] # things to not prefix with lib/ etc
8
12
 
9
13
  class << self
@@ -40,8 +44,12 @@ module SingleCov
40
44
  # ignore lines that are marked as uncovered via comments
41
45
  # TODO: warn when using uncovered but the section is indeed covered
42
46
  content = File.readlines("#{root}/#{file}")
47
+ nocov_lines_nums = nocov_line_numbers(content)
43
48
  uncovered.reject! do |line_start, _, _, _, _|
44
- content[line_start - 1].match?(UNCOVERED_COMMENT_MARKER)
49
+ line = content[line_start - 1]
50
+ line.match?(UNCOVERED_COMMENT_MARKER) ||
51
+ line.match?(SIMPLECOV_DISABLE_MARKER) || # inline, block markers are comments and never uncovered
52
+ nocov_lines_nums.include?(line_start)
45
53
  end
46
54
  next if uncovered.size == expected_uncovered
47
55
 
@@ -215,6 +223,29 @@ module SingleCov
215
223
  Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
216
224
  end
217
225
 
226
+ # @returns [Integer] 1-based line numbers that are inside :nocov: or simplecov:disable blocks
227
+ # categories (line/branch/method) are ignored, every disable ignores lines and branches
228
+ # unclosed simplecov:disable runs until end of file, like simplecov
229
+ def nocov_line_numbers(content)
230
+ nocov = false
231
+ disabled = false
232
+ content.each_with_index.filter_map do |line, index|
233
+ # marker lines themselves cannot be uncovered since they are only comments
234
+ if line.match?(NOCOV_MARKER)
235
+ nocov = !nocov # toggle
236
+ nil
237
+ elsif line.match?(SIMPLECOV_DISABLE_BLOCK_MARKER)
238
+ disabled = true
239
+ nil
240
+ elsif line.match?(SIMPLECOV_ENABLE_BLOCK_MARKER)
241
+ disabled = false
242
+ nil
243
+ elsif nocov || disabled
244
+ index + 1
245
+ end
246
+ end
247
+ end
248
+
218
249
  def indexes(list, find)
219
250
  list.each_with_index.filter_map { |v, i| i if v == find }
220
251
  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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser