Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.2...main)

* [CHANGE] Bump aruba, byebug, cucumber, fakefs, rake, reek dependencies (by [@faisal][])
* [BUGFIX] Work around issue preventing feature execution on Ruby 3.5.0dev (by [@faisal][])
* [CHANGE] Add changes or suppress warnings for issues found by newer rubocop (by [@faisal][])
* [CHANGE] Update CI checkout action to v4 (by [@faisal][])

# v4.9.2 / 2025-04-08 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.9.1...v4.9.2)
Expand Down
16 changes: 16 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# frozen_string_literal: true

if RUBY_VERSION == '3.5.0' && RUBY_PATCHLEVEL == -1
module Cucumber
module Core
module Test
module Location
singleton_class.send(:alias_method, :original_from_source_location, :from_source_location)
def self.from_source_location(file, start_line, _start_column = nil, _end_line = nil, _end_column = nil)
original_from_source_location(file, start_line)
end
end
end
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faisal One question, how long do you think we should have this monkey patch? Is there any way to have a breaking condition to remember us removing it?

Like onces Cucumber is at version X, raise "we do not need this patch please remove me"

Just wondering 🤔 to don't have unnecessary code in the future

Copy link
Contributor Author

@faisal faisal Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrestled with this question. The initial version of the patch did a version check on Cucumber as well as Ruby, but tests then failed when they updated Cucumber without fixing the issue.

I think our options are:

  • Leave it as is for now, but watch updates for a fix. In practice we're already in this situation with Ruby, since the non-dev version of Ruby won't run this workaround.
  • Make it specific to Cucumber's current version range, and live with having to update that version range when they continue revving Cucumber without a fix.

In either case, if we merge this I think we should open an issue to revert the workaround at such time when it becomes unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm watching for cucumber/cucumber-ruby-core#292 to land, or to be closed out in favor of something equivalent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Yeah, I agreed, let's keep it as it is and wait for cucumber/cucumber-ruby-core#292 to be merged, in good news, there is already a PR.

JFI: I'm trying to get someone with powers to merge this ASAP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last option would be to rework or replace that feature so as to not call cucumber-core. That seems more involved than is warranted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! that is another great option. do you have an estimation on which tests are using that feature? How long would it take?
I mean, either way we can begin with merging this PR then we can stop using that feature and upgrade cucumber as needed.


require_relative '../../lib/rubycritic'
require_relative '../../lib/rubycritic/cli/application'
require_relative '../../lib/rubycritic/commands/status_reporter'
Expand All @@ -11,6 +26,7 @@
#
class RubyCriticWorld
extend Minitest::Assertions

attr_accessor :assertions

def initialize
Expand Down
1 change: 1 addition & 0 deletions lib/rubycritic/analysers/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module RubyCritic
module Analyser
class Attributes
include Colorize

def initialize(analysed_modules)
@analysed_modules = analysed_modules
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubycritic/analysers/churn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module RubyCritic
module Analyser
class Churn
include Colorize

attr_writer :source_control_system

def initialize(analysed_modules)
Expand Down
1 change: 1 addition & 0 deletions lib/rubycritic/analysers/complexity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module RubyCritic
module Analyser
class Complexity
include Colorize

def initialize(analysed_modules)
@flog = Flog.new
@analysed_modules = analysed_modules
Expand Down
1 change: 1 addition & 0 deletions lib/rubycritic/analysers/smells/flay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module RubyCritic
module Analyser
class FlaySmells
include Colorize

def initialize(analysed_modules)
@analysed_modules = paths_to_analysed_modules(analysed_modules)
@flay = Flay.new(@analysed_modules.keys)
Expand Down
1 change: 1 addition & 0 deletions lib/rubycritic/analysers/smells/flog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module RubyCritic
module Analyser
class FlogSmells
include Colorize

HIGH_COMPLEXITY_SCORE_THRESHOLD = 25
VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD = 60

Expand Down
1 change: 1 addition & 0 deletions lib/rubycritic/analysers/smells/reek.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module RubyCritic
module Analyser
class ReekSmells
include Colorize

def initialize(analysed_modules)
@analysed_modules = analysed_modules
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubycritic/commands/status_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def update_status
end

def current_status
satisfy_minimum_score_rule ? SUCCESS : SCORE_BELOW_MINIMUM
satisfy_minimum_score_rule? ? SUCCESS : SCORE_BELOW_MINIMUM
end

def satisfy_minimum_score_rule
def satisfy_minimum_score_rule?
score >= @options[:minimum_score].to_f
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubycritic/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run_task

def print_starting_up_output
puts "\n\n!!! Running `#{name}` rake command\n"
puts "!!! Inspecting #{paths} #{options.empty? ? '' : "with options #{options}"}\n\n"
puts "!!! Inspecting #{paths} #{"with options #{options}" unless options.empty?}\n\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faisal maybe changing this to single quotes helps the reading? what do you think?

Suggested change
puts "!!! Inspecting #{paths} #{"with options #{options}" unless options.empty?}\n\n"
puts "!!! Inspecting #{paths} #{'with options #{options}' unless options.empty?}\n\n"

end

def options_as_arguments
Expand Down
4 changes: 2 additions & 2 deletions lib/rubycritic/source_control_systems/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def head_reference
end

def travel_to_head
stash_successful = stash_changes
stash_successful = stash_changes?
yield
ensure
travel_to_original_state if stash_successful
Expand Down Expand Up @@ -88,7 +88,7 @@ def self.current_branch

private

def stash_changes
def stash_changes?
stashes_count_before = stashes_count
git('stash')
stashes_count_after = stashes_count
Expand Down
2 changes: 2 additions & 0 deletions lib/rubycritic/source_control_systems/perforce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def date_of_last_commit(path)
Time.strptime(perforce_files[Perforce.key_file(path)].last_commit, '%s').strftime('%Y-%m-%d %H:%M:%S %z')
end

# rubocop:disable Style/CollectionQuerying
def revision?
!perforce_files.values.count(&:opened?).zero?
end
# rubocop:enable Style/CollectionQuerying

def head_reference
perforce_files.values.map(&:head).max_by(&:to_i)
Expand Down
12 changes: 6 additions & 6 deletions rubycritic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ Gem::Specification.new do |spec|
spec.add_dependency 'launchy', '>= 2.5.2'
spec.add_dependency 'parser', '>= 3.3.0.5'
spec.add_dependency 'rainbow', '~> 3.1.1'
spec.add_dependency 'reek', '~> 6.4.0', '< 7.0'
spec.add_dependency 'reek', '~> 6.5.0', '< 7.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most significant change (not a dev dependency): https://github.com/troessner/reek/blob/master/CHANGELOG.md

But based on the reek changelog it should be fine to merge.

spec.add_dependency 'rexml'
spec.add_dependency 'ruby_parser', '~> 3.21'
spec.add_dependency 'simplecov', '>= 0.22.0'
spec.add_dependency 'tty-which', '~> 0.5.0'
spec.add_dependency 'virtus', '~> 2.0'

spec.add_development_dependency 'aruba', '~> 2.3.0'
spec.add_development_dependency 'aruba', '~> 2.3.1', '>= 2.3.1'
spec.add_development_dependency 'bundler', '>= 2.0.0'
if RUBY_PLATFORM == 'java'
spec.add_development_dependency 'pry-debugger-jruby'
else
spec.add_development_dependency 'byebug', '~> 11.0', '>= 10.0'
spec.add_development_dependency 'byebug', '~> 12.0', '>= 10.0'
end
spec.add_development_dependency 'cucumber', '~> 9.2.1', '!= 9.0.0'
spec.add_development_dependency 'cucumber', '~> 10.0.0', '!= 9.0.0'
spec.add_development_dependency 'diff-lcs', '~> 1.3'
spec.add_development_dependency 'fakefs', '~> 2.6.0'
spec.add_development_dependency 'fakefs', '~> 3.0.0'
spec.add_development_dependency 'irb'
spec.add_development_dependency 'mdl', '~> 0.13.0', '>= 0.12.0'
spec.add_development_dependency 'minitest', '~> 5.25.2', '>= 5.3.0'
spec.add_development_dependency 'minitest-around', '~> 0.5.0', '>= 0.4.0'
spec.add_development_dependency 'mocha', '~> 2.7.1'
spec.add_development_dependency 'ostruct'
spec.add_development_dependency 'rake', '~> 13.2.0', '>= 11.0.0'
spec.add_development_dependency 'rake', '~> 13.3.0', '>= 11.0.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faisal one more question: why did you bump the dependencies in the same PR? Was that needed to make CI pass?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, could we split it? Sorry for asking a lot but want to make sure we are not blowing it up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR wound up collapsing a bunch of other PRs: #504, #512, #524.

In particular, FakeFS < 3 absolutely spewed the console with fakefs-2.6.0/lib/fakefs/globber.rb:54: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information) warnings in test runs. The others were a combination of nice-to-have modernization and chicken-and-egg updates. It's not ideal, but it did get us out of a pile of parallel smaller PRs all of which failed. I expected we could have a conversation about it before merging, but since it works I don't think we should revert the merge unless we find specific problems.

spec.add_development_dependency 'rdoc'
spec.add_development_dependency 'rexml', '>= 3.2.0'
spec.add_development_dependency 'rubocop', '>= 1.72.0', '< 2.0'
Expand Down
3 changes: 3 additions & 0 deletions test/fakefs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ class File < StringIO
# $VERBOSE = nil to suppress warnings when we override flock.
original_verbose = $VERBOSE
$VERBOSE = nil

# rubocop:disable Naming/PredicateMethod
def flock(*)
true
end
# rubocop:enable Naming/PredicateMethod
$VERBOSE = original_verbose
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rubycritic/analysers/helpers/methods_counter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@
context 'when a file contains Ruby code' do
it 'calculates the number of methods' do
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb')

_(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 2
end
end

context 'when a file is empty' do
it 'returns 0 as the number of methods' do
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb')

_(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 0
end
end

context 'when a file has no method' do
it 'does not blow up and returns 0 as the number of methods' do
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/no_methods.rb')

capture_output_streams do
_(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 0
end
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rubycritic/analysers/helpers/modules_locator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
pathname: Pathname.new('test/samples/module_names.rb'),
methods_count: 1
)

_(RubyCritic::ModulesLocator.new(analysed_module).names)
.must_equal ['Foo', 'Foo::Bar', 'Foo::Baz', 'Foo::Qux', 'Foo::Quux::Corge']
end
Expand All @@ -24,6 +25,7 @@
pathname: Pathname.new('test/samples/empty.rb'),
methods_count: 1
)

_(RubyCritic::ModulesLocator.new(analysed_module).names).must_equal ['Empty']
end
end
Expand All @@ -34,6 +36,7 @@
pathname: Pathname.new('test/samples/no_methods.rb'),
methods_count: 0
)

capture_output_streams do
_(RubyCritic::ModulesLocator.new(analysed_module).names).must_equal ['Foo::NoMethods']
end
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rubycritic/analysers/smells/flay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@

it 'creates smells with messages' do
smell = @analysed_modules.first.smells.first

_(smell.message).must_be_instance_of String
end

it 'creates smells with scores' do
smell = @analysed_modules.first.smells.first

_(smell.score).must_be_kind_of Numeric
end

it 'creates smells with more than one location' do
smell = @analysed_modules.first.smells.first

_(smell.multiple_locations?).must_equal true
end

Expand Down
2 changes: 2 additions & 0 deletions test/lib/rubycritic/analysers/smells/flog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

it 'creates smells with messages' do
smell = @analysed_module.smells.first

_(smell.message).must_be_instance_of String
end

it 'creates smells with scores' do
smell = @analysed_module.smells.first

_(smell.score).must_be :>, 0
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rubycritic/analysers/smells/reek_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

it 'respects the .reek file' do
messages = @analysed_module.smells.map(&:message)

_(messages).wont_include "has the parameter name 'a'"
end

it 'creates smells with messages' do
first_smell = @analysed_module.smells.first

_(first_smell.message).must_equal "has boolean parameter 'reek'"

last_smell = @analysed_module.smells.last

_(last_smell.message).must_equal 'has no descriptive comment'
end
end
Expand Down
1 change: 1 addition & 0 deletions test/lib/rubycritic/browser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
describe '#open' do
it 'should be open report with launch browser' do
Launchy.stubs(:open).returns(true)

_(@browser.open).must_equal true
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/lib/rubycritic/commands/compare_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def abort(str); end
comparison.expects(:abort).once

status_reporter = comparison.execute

_(status_reporter.score).must_equal RubyCritic::Config.feature_branch_score
_(status_reporter.score).wont_equal RubyCritic::Config.base_branch_score
_(status_reporter.status_message).must_equal "Score: #{RubyCritic::Config.feature_branch_score}"
Expand All @@ -87,6 +88,7 @@ def abort(str); end
end
RubyCritic::SourceControlSystem::Git.stub(:switch_branch, copy_proc) do
status_reporter = RubyCritic::Command::Compare.new(options).execute

_(status_reporter.score).must_equal RubyCritic::Config.feature_branch_score
_(status_reporter.score).must_equal RubyCritic::Config.base_branch_score
_(status_reporter.status_message).must_equal "Score: #{RubyCritic::Config.feature_branch_score}"
Expand Down
6 changes: 6 additions & 0 deletions test/lib/rubycritic/commands/status_reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

it 'accept a score' do
@reporter.score = 50.0

_(@reporter.status).must_equal success_status
_(@reporter.status_message).must_equal 'Score: 50.0'
end

it 'should format the score' do
@reporter.score = 98.95258620689656

_(@reporter.status).must_equal success_status
_(@reporter.status_message).must_equal 'Score: 98.95'
end
Expand All @@ -49,12 +51,14 @@
let(:score) { 98.0 }
it 'should return the correct status' do
@reporter.score = score

_(@reporter.status).must_equal score_below_minimum
_(@reporter.status_message).must_equal 'Score (98.0) is below the minimum 99.0'
end

it 'should format the score' do
@reporter.score = 98.95258620689656

_(@reporter.status).must_equal score_below_minimum
_(@reporter.status_message).must_equal 'Score (98.95) is below the minimum 99.0'
end
Expand All @@ -64,6 +68,7 @@
let(:score) { 99.0 }
it 'should return the correct status' do
@reporter.score = score

_(@reporter.status).must_equal success_status
_(@reporter.status_message).must_equal 'Score: 99.0'
end
Expand All @@ -73,6 +78,7 @@
let(:score) { 100.0 }
it 'should return the correct status' do
@reporter.score = score

_(@reporter.status).must_equal success_status
_(@reporter.status_message).must_equal 'Score: 100.0'
end
Expand Down
2 changes: 2 additions & 0 deletions test/lib/rubycritic/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

it 'can be set to a relative path' do
RubyCritic::Config.root = 'foo'

_(RubyCritic::Config.root).must_equal File.expand_path('foo')
end

it 'can be set to an absolute path' do
RubyCritic::Config.root = '/foo'

_(RubyCritic::Config.root).must_equal '/foo'
end

Expand Down
Loading