Skip to content

Commit 6c2aecf

Browse files
committed
Sweep two thirds of the rubocop directives out of the code
63 rubocop:disable and enable markers become 22, all three ways. Whole-file judgments move into .rubocop.yml, justification and all: the Metrics exemptions for the one-concern homes (Production, CoverageViolations, the usage document, the location conventions, the viewer-data validator, the sandbox harness, the dogfood report), the Naming/PredicateMethod allowance for commands that report whether they acted, the class-variable fakes that mirror Minitest's own flag, and the behavior-describing specs no single class owns. Fixtures are now excluded wholesale as the byte-stable inputs they are, which retires their inline markers and the per-fixture exclusion list. The two directive lines inside fixtures become plain comments rather than disappearing, so the line numbers the specs assert against stay put. Two sites are refactored instead: the RSpec stand-ins in the test tracker spec become verified class and instance doubles, and the shadowing inspect's unused parameter gains its underscore. What remains inline is the deliberate minimum, each with its reason: Marshal on our own pipes, stderr that must not be warn, the literal /dev/null of a git diff, evals whose foreign location is the point, and their kin.
1 parent 925ad2d commit 6c2aecf

25 files changed

Lines changed: 95 additions & 65 deletions

.rubocop.yml

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ plugins:
55

66
AllCops:
77
Exclude:
8-
- "spec/fixtures/iso-8859.rb"
9-
- "spec/fixtures/utf-8.rb"
10-
- "spec/fixtures/utf-8-magic.rb"
11-
- "spec/fixtures/euc-jp.rb"
12-
- "spec/fixtures/empty_euc-jp.rb"
13-
- "spec/fixtures/euc-jp-shebang.rb"
8+
# Fixtures are byte-stable test inputs: their line numbers, layout,
9+
# and sometimes their encodings are what the specs assert against,
10+
# so they are not subject to style.
11+
- "spec/fixtures/**/*"
1412
- "test_projects/**/*"
1513
- "tmp/**/*"
1614
- "vendor/bundle/**/*"
@@ -51,6 +49,37 @@ Metrics/ModuleLength:
5149
# One settings module per concern; the explicit writers beside each
5250
# dual-purpose reader push this one just past the default.
5351
- "lib/simplecov/configuration/merging.rb"
52+
# One cohesive runtime state machine, kept in one place for the same
53+
# reason a state machine is not split across files by size alone.
54+
- "lib/simplecov/production.rb"
55+
# One check per threshold family; each reads better next to the others.
56+
- "lib/simplecov/coverage_violations.rb"
57+
# One usage document; its length is the command surface, not logic.
58+
- "lib/simplecov/cli/usage.rb"
59+
# One home for the per-construct, per-Ruby-version Coverage location
60+
# conventions; splitting it would scatter closely-related resolvers.
61+
- "lib/simplecov/static_coverage_extractor/location_conventions.rb"
62+
# One check per section the viewer reads; the length tracks the
63+
# document's surface, not an accumulation of concerns.
64+
- "lib/simplecov/formatter/html_formatter/viewer_data_validator.rb"
65+
# One cohesive sandbox harness; splitting it would scatter
66+
# closely-related helpers.
67+
- "spec/support/sandbox_project.rb"
68+
69+
Metrics/ClassLength:
70+
Exclude:
71+
# The same two one-concern homes the ModuleLength exclusions cover;
72+
# this cop counts their `class << self` bodies.
73+
- "lib/simplecov/production.rb"
74+
- "lib/simplecov/coverage_violations.rb"
75+
76+
Metrics/MethodLength:
77+
Exclude:
78+
- "spec/support/dogfood_report.rb"
79+
80+
Metrics/AbcSize:
81+
Exclude:
82+
- "spec/support/dogfood_report.rb"
5483

5584
Metrics/BlockLength:
5685
Description: Checks if the length of a block exceeds some maximum value.
@@ -69,31 +98,46 @@ Metrics/ParameterLists:
6998
Naming/FileName:
7099
Description: makes sure that Ruby source files have snake_case names.
71100
Exclude:
72-
- "spec/fixtures/utf-8.rb"
73101
- "lib/simplecov-html.rb"
74102

103+
Naming/PredicateMethod:
104+
# Commands that report whether they acted. Their names are verbs
105+
# because the action is the point and the boolean is the receipt, so
106+
# neither a `?` (they are not questions) nor a bare command (callers
107+
# do read the answer) would say it better.
108+
AllowedMethods:
109+
- stop
110+
- store
111+
- store_result
112+
- remove_filter
113+
- warn_decline
114+
75115
inherit_mode:
76116
merge:
77117
- Exclude
78118

79-
# Spec fixtures are byte-stable test inputs (line numbers and `puts`
80-
# statements matter for coverage assertions), and spec/support/ holds
81-
# helper modules — neither directory is a real spec suite, so the
82-
# RSpec department shouldn't touch them. (The fixture rspec runners
83-
# under spec/fixtures/frameworks/ are intentionally minimal:
84-
# `expect(1).to eq(2)` is the point.)
119+
# spec/support/ holds helper modules, not a spec suite, so the RSpec
120+
# department shouldn't touch it. (Fixtures are excluded wholesale under
121+
# AllCops.)
85122
RSpec:
86123
Exclude:
87-
- "spec/fixtures/**/*"
88124
- "spec/support/**/*"
89-
RSpec/ExpectActual:
90-
Exclude:
91-
- "spec/fixtures/**/*"
92125
RSpec/DescribeClass:
93126
Exclude:
94-
- "spec/fixtures/**/*"
95127
# End-to-end sandbox specs describe user-visible behaviors, not classes.
96128
- "spec/sandbox/**/*"
129+
# These specs describe cross-cutting behaviors and contracts —
130+
# exit codes, output streams, file formats, build artifacts — that
131+
# no single class owns.
132+
- "spec/assets_spec.rb"
133+
- "spec/config_loader_spec.rb"
134+
- "spec/coverage_for_eval_spec.rb"
135+
- "spec/deleted_source_spec.rb"
136+
- "spec/formatter/coverage_schema_spec.rb"
137+
- "spec/gemspec_spec.rb"
138+
- "spec/production_integration_spec.rb"
139+
- "spec/return_codes_spec.rb"
140+
- "spec/stderr_output_spec.rb"
97141

98142
RSpec/ExampleLength:
99143
Max: 20 # TODO: Lower to 5
@@ -124,13 +168,18 @@ Style/CollectionMethods:
124168
find: "detect"
125169
find_all: "select"
126170

171+
Style/ClassVars:
172+
Exclude:
173+
# The minitest plugin's arming flag is a class variable on
174+
# Minitest itself, so the fakes standing in for Minitest here have
175+
# to carry one too.
176+
- "spec/simplecov_spec.rb"
177+
127178
Style/FrozenStringLiteralComment:
128179
Description:
129180
Add the frozen_string_literal comment to the top of files to help transition
130181
from Ruby 2.3.0 to Ruby 3.0.
131182
EnforcedStyle: always
132-
Exclude:
133-
- "spec/fixtures/**/*"
134183

135184
Style/EnvHome:
136185
# `Dir.home` raises ArgumentError on JRuby when HOME is unset, defeating

lib/simplecov/cli/usage.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module CLI
55
# The `simplecov help` text. A method so its default paths resolve at
66
# call time against the active `.simplecov`.
77
#
8-
# rubocop:disable Metrics/ModuleLength -- the module is one usage
9-
# document; its length is the command surface, not logic.
108
module Usage
119
extend self
1210

@@ -153,6 +151,5 @@ def text(cli)
153151
USAGE
154152
end
155153
end
156-
# rubocop:enable Metrics/ModuleLength
157154
end
158155
end

lib/simplecov/configuration/filters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def add_filter(filter_argument = nil, &block)
111111
# Returns true when at least one filter was removed, false otherwise.
112112
# `reject!` answers nil when it rejected nothing, which is the whole
113113
# of "was anything removed".
114-
def remove_filter(filter_argument) # rubocop:disable Naming/PredicateMethod
114+
def remove_filter(filter_argument)
115115
rejected = filters.reject! do |filter|
116116
filter.respond_to?(:filter_argument) && filter.filter_argument.eql?(filter_argument)
117117
end

lib/simplecov/coverage_violations.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ module SimpleCov
77
# Each method returns an array of violation hashes. All percents are
88
# rounded via `SimpleCov.round_coverage` so downstream consumers don't
99
# need to round again.
10-
# rubocop:disable Metrics/ModuleLength, Metrics/ClassLength -- one check
11-
# per threshold family, and each reads better next to the others than
12-
# split across files by size alone.
1310
module CoverageViolations
1411
class << self
1512
# @return [Array<Hash>] {:criterion, :expected, :actual}
@@ -320,5 +317,4 @@ def round(percent)
320317
end
321318
end
322319
end
323-
# rubocop:enable Metrics/ModuleLength, Metrics/ClassLength
324320
end

lib/simplecov/formatter/html_formatter/viewer_data_validator.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class HTMLFormatter
99
# dereferences without defensive fallbacks. One check per section
1010
# the viewer reads; the module's length tracks the document's
1111
# surface, not an accumulation of concerns.
12-
# rubocop:disable-next Metrics/ModuleLength
1312
module ViewerDataValidator
1413
META_STRINGS = %w[simplecov_version command_name project_name timestamp].freeze
1514
COVERAGE_FLAGS = {

lib/simplecov/production.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module SimpleCov
2525
# See the file-top comment. One cohesive runtime state machine; kept
2626
# in one class for the same reason a state machine is not split
2727
# across files by size alone.
28-
# rubocop:disable-next Metrics/ModuleLength, Metrics/ClassLength
2928
module Production
3029
class << self
3130
# Begin measuring. Returns true when measurement started, false —
@@ -86,7 +85,7 @@ def flush
8685
# Stop measuring: wind down the flush thread, deliver the final
8786
# delta, and halt the runtime's instrumentation. Returns false
8887
# when nothing was running.
89-
def stop # rubocop:disable Naming/PredicateMethod -- a command that reports whether it acted
88+
def stop
9089
return false unless running?
9190

9291
@running = false
@@ -276,7 +275,7 @@ def relativize(path)
276275
path[@root_prefix.length..]
277276
end
278277

279-
def warn_decline(reason) # rubocop:disable Naming/PredicateMethod -- the callers' falsy return value
278+
def warn_decline(reason)
280279
warn "[SimpleCov::Production] not starting: #{reason}"
281280
false
282281
end

lib/simplecov/production/file_sink.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def initialize(path:)
4949
@path = File.expand_path(path)
5050
end
5151

52-
def store(coverage) # rubocop:disable Naming/PredicateMethod -- the sink contract returns acceptance
52+
def store(coverage)
5353
FileUtils.mkdir_p(File.dirname(path))
5454
locked do |file|
5555
existing = self.class.parse(file.read, path)

lib/simplecov/result_merger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def read_resultset
173173
end
174174

175175
# Saves the given SimpleCov::Result in the resultset cache
176-
def store_result(result) # rubocop:disable Naming/PredicateMethod
176+
def store_result(result)
177177
synchronize_resultset do
178178
# Ensure we have the latest, in case it was already cached
179179
new_resultset = read_resultset

lib/simplecov/static_coverage_extractor/location_conventions.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ module StaticCoverageExtractor
1010
# changed several of these conventions, so every resolver here emits
1111
# whichever shape this Ruby's Coverage uses. See issues #1226 / #1233.
1212
#
13-
# rubocop:disable Metrics/ModuleLength -- one cohesive home for the
14-
# per-construct, per-Ruby-version Coverage location conventions;
15-
# splitting it would scatter closely-related resolvers.
1613
module LocationConventions
1714
LEGACY_COVERAGE_LOCATIONS = Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4")
1815

@@ -244,6 +241,5 @@ def value_position?(node)
244241
end
245242
# simplecov:enable
246243
end
247-
# rubocop:enable Metrics/ModuleLength
248244
end
249245
end

spec/assets_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "open3"
55
require "tmpdir"
66

7-
RSpec.describe "frontend asset compilation" do # rubocop:disable RSpec/DescribeClass
7+
RSpec.describe "frontend asset compilation" do
88
it "fails when the CSS minifier exits unsuccessfully" do
99
skip "the fake esbuild is a POSIX shell script" if Gem.win_platform?
1010

0 commit comments

Comments
 (0)