From ae3d265715352920742c8efd1508f365e7f19efd Mon Sep 17 00:00:00 2001 From: Jan Grodowski Date: Thu, 4 Jan 2024 15:22:16 +0100 Subject: [PATCH] Rubocop update --- .rubocop.yml | 1 + Gemfile | 10 ++++++++++ lib/undercover/changeset.rb | 3 ++- lib/undercover/formatter.rb | 12 ++++++------ lib/undercover/result.rb | 10 +++++----- undercover.gemspec | 16 ++-------------- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1c92c79..ab469f1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ AllCops: TargetRubyVersion: 2.7.0 Exclude: - spec/fixtures/**/* + SuggestExtensions: false Style/RegexpLiteral: EnforcedStyle: slashes diff --git a/Gemfile b/Gemfile index 7f4f5e9..b710dce 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,13 @@ source 'https://rubygems.org' gemspec + +gem 'bundler' +gem 'pry' +gem 'rake', '~> 13.0' +gem 'rspec', '~> 3.0' +gem 'rubocop' +gem 'simplecov' +gem 'simplecov-html' +gem 'simplecov-lcov', '~> 0.8' +gem 'timecop' diff --git a/lib/undercover/changeset.rb b/lib/undercover/changeset.rb index 78f2309..c7b9316 100644 --- a/lib/undercover/changeset.rb +++ b/lib/undercover/changeset.rb @@ -59,7 +59,8 @@ def each_changed_line # TODO: add specs def validate(lcov_report_path) return :no_changes if files.empty? - return :stale_coverage if last_modified > File.mtime(lcov_report_path) + + :stale_coverage if last_modified > File.mtime(lcov_report_path) end private diff --git a/lib/undercover/formatter.rb b/lib/undercover/formatter.rb index 28b7256..7e011bc 100644 --- a/lib/undercover/formatter.rb +++ b/lib/undercover/formatter.rb @@ -17,21 +17,21 @@ def to_s def formatted_warnings @results.map.with_index(1) do |res, idx| "🚨 #{idx}) node `#{res.node.name}` type: #{res.node.human_name},\n" + - (' ' * pad_size) + "loc: #{res.file_path_with_lines}," \ - " coverage: #{res.coverage_f * 100}%\n" + + (' ' * pad_size) + "loc: #{res.file_path_with_lines}, " \ + "coverage: #{res.coverage_f * 100}%\n" + res.pretty_print end end def success - "#{Rainbow('undercover').bold.green}: ✅ No coverage" \ - ' is missing in latest changes' + "#{Rainbow('undercover').bold.green}: ✅ No coverage " \ + 'is missing in latest changes' end def warnings_header "#{Rainbow('undercover').bold.red}: " \ - '👮‍♂️ some methods have no test coverage! Please add specs for' \ - ' methods listed below' + '👮‍♂️ some methods have no test coverage! Please add specs for ' \ + 'methods listed below' end def pad_size diff --git a/lib/undercover/result.rb b/lib/undercover/result.rb index 5a6b902..8bdfead 100644 --- a/lib/undercover/result.rb +++ b/lib/undercover/result.rb @@ -54,7 +54,7 @@ def coverage_f lines[ln] = 0 end end - return 1.0 if lines.keys.size.zero? + return 1.0 if lines.keys.empty? (lines.values.sum.to_f / lines.keys.size).round(4) end @@ -84,7 +84,7 @@ def pretty_print pad = node.last_line.to_s.length pretty_print_lines.map do |covered, (num, line)| formatted_line = "#{num.to_s.rjust(pad)}: #{line}" - if line.strip.length.zero? + if line.strip.empty? Rainbow(formatted_line).darkgray.dark elsif covered.nil? Rainbow(formatted_line).darkgray.dark + \ @@ -107,8 +107,8 @@ def file_path_with_lines end def inspect - "#" + "#" end alias to_s inspect @@ -119,7 +119,7 @@ def count_covered_branches(line_number) branches = coverage.select { |cov| cov.size == 4 && cov[0] == line_number } count_covered = branches.count { |cov| cov[3].positive? } - return '' if branches.size.zero? + return '' if branches.empty? if count_covered < branches.size Rainbow(' branches: ').italic.darkgray.dark + \ diff --git a/undercover.gemspec b/undercover.gemspec index 7410376..5c7eefc 100644 --- a/undercover.gemspec +++ b/undercover.gemspec @@ -4,15 +4,14 @@ lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'undercover/version' -# rubocop:disable Metrics/BlockLength Gem::Specification.new do |spec| spec.name = 'undercover' spec.version = Undercover::VERSION spec.authors = ['Jan Grodowski'] spec.email = ['jgrodowski@gmail.com'] - spec.summary = 'Actionable code coverage - detects untested' \ - ' code blocks in recent changes' + spec.summary = 'Actionable code coverage - detects untested ' \ + 'code blocks in recent changes' spec.homepage = 'https://github.com/grodowski/undercover' spec.license = 'MIT' spec.metadata = { @@ -32,15 +31,4 @@ Gem::Specification.new do |spec| spec.add_dependency 'imagen', '>= 0.1.8' spec.add_dependency 'rainbow', '>= 2.1', '< 4.0' spec.add_dependency 'rugged', '>= 0.27', '< 1.8' - - spec.add_development_dependency 'bundler' - spec.add_development_dependency 'pry' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'rubocop', '~> 1.28.2' - spec.add_development_dependency 'simplecov' - spec.add_development_dependency 'simplecov-html' - spec.add_development_dependency 'simplecov-lcov', '~> 0.8' - spec.add_development_dependency 'timecop' end -# rubocop:enable Metrics/BlockLength