single_cov 2.1.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: 03abb741a629409eca737e84185cbd61c34a24a65fdb5b4c381d295f00690eed
4
- data.tar.gz: fee46d0a03e4812f372c375745ff9a02229292bc1c153e028ee7dc46691edfb0
3
+ metadata.gz: 12be958e8135fecd7c8e8dc446b97cae5dd0a7d1397c33ea851cffdeb7389ee0
4
+ data.tar.gz: 315153f27ef5c680a52584c95e28d96904b10c3c9a094d5e19b06ebac66dbfc1
5
5
  SHA512:
6
- metadata.gz: 52da7209346a1ec927241e0db7390d664ef155a6146642e0895964cbcaa7c6e704ee6dc027591032fcb4727546543de60aa68ddd57f9b7e5f8879b9c98169a73
7
- data.tar.gz: 3f0ae6f966cb07c608efd71cc8b87787c7506363c8bf2e43c4e334cf88b51122f56d2ad56864afc302b7158339eb4c5f3d8935f8a924c3132e43ab216604f700
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.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
data/lib/single_cov.rb CHANGED
@@ -5,6 +5,9 @@ module SingleCov
5
5
  RAILS_APP_FOLDERS = ["models", "serializers", "helpers", "controllers", "mailers", "views", "jobs", "channels"]
6
6
  UNCOVERED_COMMENT_MARKER = /#.*uncovered/
7
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/
8
11
  PREFIXES_TO_IGNORE = [] # things to not prefix with lib/ etc
9
12
 
10
13
  class << self
@@ -43,7 +46,9 @@ module SingleCov
43
46
  content = File.readlines("#{root}/#{file}")
44
47
  nocov_lines_nums = nocov_line_numbers(content)
45
48
  uncovered.reject! do |line_start, _, _, _, _|
46
- 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
47
52
  nocov_lines_nums.include?(line_start)
48
53
  end
49
54
  next if uncovered.size == expected_uncovered
@@ -218,14 +223,24 @@ module SingleCov
218
223
  Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
219
224
  end
220
225
 
221
- # @returns [Integer] 1-based line numbers that are inside :nocov: blocks
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
222
229
  def nocov_line_numbers(content)
223
- inside = false
230
+ nocov = false
231
+ disabled = false
224
232
  content.each_with_index.filter_map do |line, index|
233
+ # marker lines themselves cannot be uncovered since they are only comments
225
234
  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
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
229
244
  index + 1
230
245
  end
231
246
  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.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser