diff --git a/.rubocop.yml b/.rubocop.yml index b170ace2..3eac785b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/lib/simplecov.rb b/lib/simplecov.rb index 12202c9e..3c7acfce 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -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 # @@ -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? @@ -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 diff --git a/lib/simplecov/command_guesser.rb b/lib/simplecov/command_guesser.rb index bc949ffd..b0e2dd18 100644 --- a/lib/simplecov/command_guesser.rb +++ b/lib/simplecov/command_guesser.rb @@ -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 diff --git a/lib/simplecov/configuration.rb b/lib/simplecov/configuration.rb index 617e5f6e..6c2cc3d4 100644 --- a/lib/simplecov/configuration.rb +++ b/lib/simplecov/configuration.rb @@ -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 # @@ -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 @@ -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 # diff --git a/lib/simplecov/defaults.rb b/lib/simplecov/defaults.rb index 21cba877..2d82d952 100644 --- a/lib/simplecov/defaults.rb +++ b/lib/simplecov/defaults.rb @@ -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 diff --git a/lib/simplecov/formatter/simple_formatter.rb b/lib/simplecov/formatter/simple_formatter.rb index 5f66af24..b99338c0 100644 --- a/lib/simplecov/formatter/simple_formatter.rb +++ b/lib/simplecov/formatter/simple_formatter.rb @@ -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" diff --git a/lib/simplecov/load_global_config.rb b/lib/simplecov/load_global_config.rb index 64dc62ae..758bbcfc 100644 --- a/lib/simplecov/load_global_config.rb +++ b/lib/simplecov/load_global_config.rb @@ -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) diff --git a/lib/simplecov/result.rb b/lib/simplecov/result.rb index 51726f1a..7741678c 100644 --- a/lib/simplecov/result.rb +++ b/lib/simplecov/result.rb @@ -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 diff --git a/lib/simplecov/source_file/line.rb b/lib/simplecov/source_file/line.rb index 7aab40c2..2491e586 100644 --- a/lib/simplecov/source_file/line.rb +++ b/lib/simplecov/source_file/line.rb @@ -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 diff --git a/simplecov.gemspec b/simplecov.gemspec index c770c14d..21f35eeb 100644 --- a/simplecov.gemspec +++ b/simplecov.gemspec @@ -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" diff --git a/spec/filters_spec.rb b/spec/filters_spec.rb index 82028303..fa25d12f 100644 --- a/spec/filters_spec.rb +++ b/spec/filters_spec.rb @@ -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 diff --git a/spec/last_run_spec.rb b/spec/last_run_spec.rb index a1543067..b6d7d295 100644 --- a/spec/last_run_spec.rb +++ b/spec/last_run_spec.rb @@ -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 diff --git a/spec/result_merger_spec.rb b/spec/result_merger_spec.rb index 0bbb70f0..d9544e42 100644 --- a/spec/result_merger_spec.rb +++ b/spec/result_merger_spec.rb @@ -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 diff --git a/spec/support/fail_rspec_on_ruby_warning.rb b/spec/support/fail_rspec_on_ruby_warning.rb index b5115161..5d99c2b2 100644 --- a/spec/support/fail_rspec_on_ruby_warning.rb +++ b/spec/support/fail_rspec_on_ruby_warning.rb @@ -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