Skip to content

Commit e68a018

Browse files
committed
Fix rubocop offenses across the codebase
1 parent 5396f5d commit e68a018

32 files changed

Lines changed: 112 additions & 125 deletions

.rubocop.yml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,11 @@ AllCops:
1919
TargetRubyVersion: 2.7
2020
NewCops: enable
2121

22-
Bundler/OrderedGems:
23-
Description: Gems should be alphabetically sorted within groups.
24-
Enabled: false
25-
2622
Layout/AccessModifierIndentation:
2723
Description: Modifiers should be indented as deep as method definitions,
2824
or as deep as the class/module keyword, depending on configuration.
2925
EnforcedStyle: outdent
3026

31-
# Open for revision would like table style but the impact
32-
# would probably be huge
33-
Layout/HashAlignment:
34-
Enabled: false
35-
36-
Layout/HeredocIndentation:
37-
Description: Checks the indentation of the here document bodies.
38-
Enabled: false
39-
4027
Layout/LineLength:
4128
Description: Checks the length of lines in the source code.
4229
AllowURI: true
@@ -72,10 +59,6 @@ Metrics/BlockNesting:
7259
Metrics/ClassLength:
7360
Max: 300
7461

75-
Style/Next:
76-
Description: Prefer `if` guards over `next` inside loops for readability.
77-
Enabled: false
78-
7962
Metrics/ModuleLength:
8063
Description: Avoid modules longer than 100 lines of code.
8164
Max: 300
@@ -138,22 +121,6 @@ Style/CollectionMethods:
138121
find: "detect"
139122
find_all: "select"
140123

141-
Style/Documentation:
142-
Description: Checks for missing top-level documentation of classes and modules.
143-
Enabled: false
144-
145-
Style/DoubleNegation:
146-
Description: Checks for uses of double negation (!!).
147-
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-bang-bang
148-
Enabled: false
149-
150-
Style/EnvHome:
151-
Enabled: false
152-
153-
Style/ExplicitBlockArgument:
154-
# capturing as a proc has a performance hit, so is a case by case choice
155-
Enabled: false
156-
157124
Style/FrozenStringLiteralComment:
158125
Description:
159126
Add the frozen_string_literal comment to the top of files to help transition
@@ -162,19 +129,10 @@ Style/FrozenStringLiteralComment:
162129
Exclude:
163130
- "spec/fixtures/**/*"
164131

165-
Style/GuardClause:
166-
Description: Use a guard clause instead of wrapping the code inside a conditional expression.
167-
Enabled: false
168-
169132
Style/HashSyntax:
170133
Description: Checks hash literal syntax.
171134
EnforcedStyle: ruby19
172135

173-
Style/RegexpLiteral:
174-
Description: Use / or %r around regular expressions.
175-
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#percent-r
176-
Enabled: false
177-
178136
Style/SpecialGlobalVars:
179137
Description: Looks for uses of Perl-style global variables.
180138
Exclude:

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
source "https://rubygems.org"
44

55
group :development do
6-
gem "nokogiri"
7-
gem "cuprite"
86
gem "aruba", ">= 2.0"
97
gem "capybara"
10-
gem "rackup"
118
gem "cucumber"
9+
gem "cuprite"
10+
gem "nokogiri"
11+
gem "rackup"
1212
gem "rake"
1313
gem "rspec"
1414
if RUBY_VERSION > "3.2"

benchmarks/result.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative "../test_projects/faked_project/lib/faked_project"
1010
result = Coverage.result
1111

12+
# Minimal formatter used by the benchmark to exercise SimpleCov::Result.
1213
class MyFormatter
1314
def format(result)
1415
result.files.map do |file|

features/step_definitions/html_steps.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
expect(count).to eq(expected_count.to_i)
8787
end
8888

89-
Then /^I should see a (.+) coverage summary of (\d+)\/(\d+)( for the file)?$/ do |coverage_type, hit, total, for_file|
89+
Then %r{^I should see a (.+) coverage summary of (\d+)/(\d+)( for the file)?$} do |coverage_type, hit, total, for_file|
9090
missed = total - hit
9191

9292
if for_file
@@ -116,7 +116,7 @@
116116
end
117117
end
118118

119-
expect(summary_text).to match(/#{hit}\/#{total}.*#{missed}|#{total} .+ #{hit} .+ #{missed}/)
119+
expect(summary_text).to match(%r{#{hit}/#{total}.*#{missed}|#{total} .+ #{hit} .+ #{missed}})
120120
end
121121

122122
When /^I open the detailed view for "(.+)"$/ do |file_path|

features/step_definitions/simplecov_steps.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
case framework
99
when /RSpec/i
1010
"spec"
11-
when /Test\/Unit/i
11+
when %r{Test/Unit}i
1212
"test"
1313
when /Cucumber/i
1414
"features/support"

features/step_definitions/web_steps.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
22

3+
# Cucumber world helpers for scoping Capybara assertions to a selector.
34
module WithinHelpers
4-
def with_scope(locator)
5-
locator ? within(locator) { yield } : yield
5+
def with_scope(locator, &block)
6+
locator ? within(locator, &block) : yield
67
end
78
end
89
World(WithinHelpers)
@@ -40,7 +41,7 @@ def with_scope(locator)
4041
end
4142
end
4243

43-
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
44+
Then %r{^(?:|I )should see /([^/]*)/(?: within "([^"]*)")?$} do |regexp, selector|
4445
regexp = Regexp.new(regexp)
4546
with_scope(selector) do
4647
expect(page).to have_xpath("//*", text: regexp)
@@ -53,7 +54,7 @@ def with_scope(locator)
5354
end
5455
end
5556

56-
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
57+
Then %r{^(?:|I )should not see /([^/]*)/(?: within "([^"]*)")?$} do |regexp, selector|
5758
regexp = Regexp.new(regexp)
5859
with_scope(selector) do
5960
expect(page).to have_no_xpath("//*", text: regexp)

lib/minitest/simplecov_plugin.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
# https://github.com/seattlerb/minitest#writing-extensions
55
module Minitest
66
def self.plugin_simplecov_init(_options)
7-
if defined?(SimpleCov)
8-
SimpleCov.external_at_exit = true
7+
return unless defined?(SimpleCov)
98

10-
Minitest.after_run do
11-
SimpleCov.at_exit_behavior
12-
end
9+
SimpleCov.external_at_exit = true
10+
11+
Minitest.after_run do
12+
SimpleCov.at_exit_behavior
1313
end
1414
end
1515
end

lib/simplecov.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ def process_results_and_report_error
248248
exit_status = process_result(result)
249249

250250
# Force exit with stored status (see github issue #5)
251-
if exit_status.positive?
252-
warn("SimpleCov failed with exit #{exit_status} due to a coverage related error") if print_error_status
253-
Kernel.exit exit_status
254-
end
251+
return unless exit_status.positive?
252+
253+
warn("SimpleCov failed with exit #{exit_status} due to a coverage related error") if print_error_status
254+
Kernel.exit exit_status
255255
end
256256

257257
# @api private

lib/simplecov/command_guesser.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def parallel_data
2929
end
3030

3131
COMMAND_LINE_FRAMEWORKS = {
32-
%r{test/functional/} => "Functional Tests",
33-
%r{test/\{.*functional.*\}/} => "Functional Tests",
34-
%r{test/integration/} => "Integration Tests",
35-
%r{test/} => "Unit Tests",
36-
/spec/ => "RSpec",
37-
/cucumber/ => "Cucumber Features",
38-
/features/ => "Cucumber Features"
32+
%r{test/functional/} => "Functional Tests",
33+
%r{test/\{.*functional.*\}/} => "Functional Tests",
34+
%r{test/integration/} => "Integration Tests",
35+
%r{test/} => "Unit Tests",
36+
/spec/ => "RSpec",
37+
/cucumber/ => "Cucumber Features",
38+
/features/ => "Cucumber Features"
3939
}.freeze
4040
private_constant :COMMAND_LINE_FRAMEWORKS
4141

lib/simplecov/configuration.rb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,19 +518,15 @@ def enable_coverage_for_eval
518518

519519
def raise_if_criterion_disabled(criterion)
520520
raise_if_criterion_unsupported(criterion)
521-
# rubocop:disable Style/IfUnlessModifier
522-
unless coverage_criterion_enabled?(criterion)
523-
raise "Coverage criterion #{criterion}, is disabled! Please enable it first through enable_coverage #{criterion} (if supported)"
524-
end
525-
# rubocop:enable Style/IfUnlessModifier
521+
return if coverage_criterion_enabled?(criterion)
522+
523+
raise "Coverage criterion #{criterion}, is disabled! Please enable it first through enable_coverage #{criterion} (if supported)"
526524
end
527525

528526
def raise_if_criterion_unsupported(criterion)
529-
# rubocop:disable Style/IfUnlessModifier
530-
unless SUPPORTED_COVERAGE_CRITERIA.member?(criterion)
531-
raise "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}"
532-
end
533-
# rubocop:enable Style/IfUnlessModifier
527+
return if SUPPORTED_COVERAGE_CRITERIA.member?(criterion)
528+
529+
raise "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}"
534530
end
535531

536532
def minimum_possible_coverage_exceeded(coverage_option)
@@ -563,11 +559,9 @@ def restore_ivars(block_context, saved)
563559
def parse_filter(filter_argument = nil, &filter_proc)
564560
filter = filter_argument || filter_proc
565561

566-
if filter
567-
SimpleCov::Filter.build_filter(filter)
568-
else
569-
raise ArgumentError, "Please specify either a filter or a block to filter with"
570-
end
562+
raise ArgumentError, "Please specify either a filter or a block to filter with" unless filter
563+
564+
SimpleCov::Filter.build_filter(filter)
571565
end
572566
end
573567
end

0 commit comments

Comments
 (0)