Skip to content

Commit

Permalink
Enable all new cops and autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Dec 26, 2023
1 parent d1820d4 commit da6f918
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AllCops:
- "vendor/bundle/**/*"
- "vendor/bundle/**/.*"
TargetRubyVersion: 2.5
NewCops: enable
# we might wanna adopt rspec and rake but it's a bit annoying for now
SuggestExtensions: false

Expand Down
12 changes: 6 additions & 6 deletions lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# @see https://github.com/simplecov-ruby/simplecov/issues/86
# @see https://jira.codehaus.org/browse/JRUBY-6106

warn 'Coverage may be inaccurate; set the "--debug" command line option,' \
' or do JRUBY_OPTS="--debug"' \
' or set the "debug.fullTrace=true" option in your .jrubyrc'
warn 'Coverage may be inaccurate; set the "--debug" command line option, ' \
'or do JRUBY_OPTS="--debug" ' \
'or set the "debug.fullTrace=true" option in your .jrubyrc'
end

#
Expand Down Expand Up @@ -347,9 +347,9 @@ def start_coverage_measurement
end

def start_coverage_with_criteria
start_arguments = coverage_criteria.map do |criterion|
start_arguments = coverage_criteria.to_h do |criterion|
[lookup_corresponding_ruby_coverage_name(criterion), true]
end.to_h
end

start_arguments[:eval] = true if coverage_for_eval_enabled?

Expand Down Expand Up @@ -432,7 +432,7 @@ def make_parallel_tests_available
end

def probably_running_parallel_tests?
ENV["TEST_ENV_NUMBER"] && ENV["PARALLEL_TEST_GROUPS"]
ENV.fetch("TEST_ENV_NUMBER", nil) && ENV.fetch("PARALLEL_TEST_GROUPS", nil)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/simplecov/command_guesser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def from_env
# If being run from inside parallel_tests set the command name according to the process number
return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"]

number = ENV["TEST_ENV_NUMBER"]
number = ENV.fetch("TEST_ENV_NUMBER", nil)
number = "1" if number.empty?
"(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
"(#{number}/#{ENV.fetch('PARALLEL_TEST_GROUPS', nil)})"
end

def from_command_line_options
Expand Down
6 changes: 3 additions & 3 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def coverage_dir(dir = nil)
return @coverage_dir if defined?(@coverage_dir) && dir.nil?

@coverage_path = nil # invalidate cache
@coverage_dir = (dir || "coverage")
@coverage_dir = dir || "coverage"
end

#
Expand Down Expand Up @@ -140,7 +140,7 @@ def print_error_status
def nocov_token(nocov_token = nil)
return @nocov_token if defined?(@nocov_token) && nocov_token.nil?

@nocov_token = (nocov_token || "nocov")
@nocov_token = nocov_token || "nocov"
end
alias skip_token nocov_token

Expand Down Expand Up @@ -344,7 +344,7 @@ def minimum_coverage_by_file(coverage = nil)
def refuse_coverage_drop(*criteria)
criteria = coverage_criteria if criteria.empty?

maximum_coverage_drop(criteria.map { |c| [c, 0] }.to_h)
maximum_coverage_drop(criteria.to_h { |c| [c, 0] })
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
load filename
rescue LoadError, StandardError
warn "Warning: Error occurred while trying to load #{filename}. " \
"Error message: #{$!.message}"
"Error message: #{$!.message}"
end
break
end
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/formatter/simple_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def format(result)
output = +""
result.groups.each do |name, files|
output << "Group: #{name}\n"
output << "=" * 40
output << ("=" * 40)
output << "\n"
files.each do |file|
output << "#{file.filename} (coverage: #{file.covered_percent.round(2)}%)\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/load_global_config.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "etc"
home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
home_dir = (Dir.home && File.expand_path("~")) || Etc.getpwuid.dir || (ENV.fetch("USER", nil) && File.expand_path("~#{ENV.fetch('USER', nil)}"))
if home_dir
global_config_path = File.join(home_dir, ".simplecov")
load global_config_path if File.exist?(global_config_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def self.from_hash(hash)

def coverage
keys = original_result.keys & filenames
Hash[keys.zip(original_result.values_at(*keys))]
keys.zip(original_result.values_at(*keys)).to_h
end

# Applies all configured SimpleCov filters on this result's source files
Expand Down
3 changes: 2 additions & 1 deletion lib/simplecov/source_file/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def status
return "skipped" if skipped?
return "never" if never?
return "missed" if missed?
return "covered" if covered?

"covered" if covered?
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion simplecov.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Gem::Specification.new do |gem|
"changelog_uri" => "https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md",
"documentation_uri" => "https://www.rubydoc.info/gems/simplecov/#{gem.version}",
"mailing_list_uri" => "https://groups.google.com/forum/#!forum/simplecov",
"source_code_uri" => "https://github.com/simplecov-ruby/simplecov/tree/v#{gem.version}"
"source_code_uri" => "https://github.com/simplecov-ruby/simplecov/tree/v#{gem.version}",
"rubygems_mfa_required" => "true"
}

gem.required_ruby_version = ">= 2.5.0"
Expand Down
6 changes: 3 additions & 3 deletions spec/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
expect(SimpleCov::StringFilter.new(parent_dir_name)).not_to be_matches subject
end

it "matches a new SimpleCov::RegexFilter /\/fixtures\//" do
it "matches a new SimpleCov::RegexFilter //fixtures//" do
expect(SimpleCov::RegexFilter.new(/\/fixtures\//)).to be_matches subject
end

it "doesn't match a new SimpleCov::RegexFilter /^\/fixtures\//" do
it "doesn't match a new SimpleCov::RegexFilter /^/fixtures//" do
expect(SimpleCov::RegexFilter.new(/^\/fixtures\//)).not_to be_matches subject
end

it "matches a new SimpleCov::RegexFilter /^\/spec\//" do
it "matches a new SimpleCov::RegexFilter /^/spec//" do
expect(SimpleCov::RegexFilter.new(/^\/spec\//)).to be_matches subject
end

Expand Down
2 changes: 1 addition & 1 deletion spec/last_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

context "reading" do
context "but the last_run file does not exist" do
before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }
before { FileUtils.rm_f(subject.last_run_path) }

it "returns nil" do
expect(subject.read).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/result_merger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

describe SimpleCov::ResultMerger do
after do
File.delete(SimpleCov::ResultMerger.resultset_path) if File.exist?(SimpleCov::ResultMerger.resultset_path)
FileUtils.rm_f(SimpleCov::ResultMerger.resultset_path)
end

let(:resultset1) do
Expand Down
4 changes: 1 addition & 3 deletions spec/support/fail_rspec_on_ruby_warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def write_other_warnings_to_tmp(other_warnings)
output_dir = File.join(@app_root, "tmp")
FileUtils.mkdir_p(output_dir)
output_file = File.join(output_dir, "warnings.txt")
File.open(output_file, "w") do |file|
file.write(other_warnings.join("\n") << "\n")
end
File.write(output_file, other_warnings.join("\n") << "\n")
puts
puts "Non-app warnings written to tmp/warnings.txt"
puts
Expand Down

0 comments on commit da6f918

Please sign in to comment.