Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.2...main)

* [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
2 changes: 2 additions & 0 deletions lib/rubycritic/cli/options/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ def paths
options['paths']
end

# rubocop:disable Naming/PredicateMethod
def value_for(value)
value = value.to_s
value == 'true' unless value.empty?
end
# rubocop:enable Naming/PredicateMethod
end
end
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"
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
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
5 changes: 5 additions & 0 deletions test/lib/rubycritic/core/analysed_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
it 'returns the remediation cost of fixing the analysed_module' do
smells = [SmellDouble.new(cost: 1), SmellDouble.new(cost: 2)]
analysed_module = RubyCritic::AnalysedModule.new(smells: smells, complexity: 0)

_(analysed_module.cost).must_equal 3
end
end
Expand All @@ -58,13 +59,15 @@
context 'when the file has no methods' do
it 'returns a placeholder' do
analysed_module = RubyCritic::AnalysedModule.new(complexity: 0, methods_count: 0)

_(analysed_module.complexity_per_method).must_equal 'N/A'
end
end

context 'when the file has at least one method' do
it 'returns the average complexity per method' do
analysed_module = RubyCritic::AnalysedModule.new(complexity: 10, methods_count: 2)

_(analysed_module.complexity_per_method).must_equal 5
end
end
Expand All @@ -73,6 +76,7 @@
describe '#smells?' do
it 'returns true if the analysed_module has at least one smell' do
analysed_module = RubyCritic::AnalysedModule.new(smells: [SmellDouble.new])

_(analysed_module.smells?).must_equal true
end
end
Expand All @@ -82,6 +86,7 @@
location = RubyCritic::Location.new('./foo', '42')
smells = [RubyCritic::Smell.new(locations: [location])]
analysed_module = RubyCritic::AnalysedModule.new(smells: smells)

_(analysed_module.smells_at_location(location)).must_equal smells
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/lib/rubycritic/core/analysed_modules_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@

it 'registers one AnalysedModule element per existent file' do
analysed_modules_collection = RubyCritic::AnalysedModulesCollection.new(paths, analysed_modules)

_(analysed_modules_collection.count).must_equal 1
analysed_module = analysed_modules_collection.first

_(analysed_module.name).must_equal 'Name'
_(analysed_module.churn).must_equal 2
_(analysed_module.complexity).must_equal 2
Expand Down
2 changes: 2 additions & 0 deletions test/lib/rubycritic/core/location_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
it 'is comparable' do
location1 = RubyCritic::Location.new('./foo', 42)
location2 = RubyCritic::Location.new('./foo', 42)

_(location1).must_equal location2
end

it 'is sortable' do
location1 = RubyCritic::Location.new('./foo', 42)
location2 = RubyCritic::Location.new('./bar', 23)
location3 = RubyCritic::Location.new('./bar', 16)

_([location1, location2, location3].sort).must_equal [location3, location2, location1]
end
end
5 changes: 5 additions & 0 deletions test/lib/rubycritic/core/smell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
it 'returns true if the smell has a location that matches the location passed as argument' do
location = RubyCritic::Location.new('./foo', '42')
smell = RubyCritic::Smell.new(locations: [location])

_(smell.at_location?(location)).must_equal true
end
end
Expand All @@ -54,6 +55,7 @@
location1 = RubyCritic::Location.new('./foo', '42')
location2 = RubyCritic::Location.new('./foo', '23')
smell = RubyCritic::Smell.new(locations: [location1, location2])

_(smell.multiple_locations?).must_equal true
end
end
Expand All @@ -68,6 +70,7 @@
}
smell1 = RubyCritic::Smell.new(attributes)
smell2 = RubyCritic::Smell.new(attributes)

_(smell1).must_equal smell2
end
end
Expand Down Expand Up @@ -106,11 +109,13 @@
describe 'default attributes' do
it 'has :new for status' do
smell = RubyCritic::Smell.new

_(smell.status).must_equal(:new)
end

it 'is has an empty array for locations' do
smell = RubyCritic::Smell.new

_(smell.locations).must_equal([])
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/lib/rubycritic/core/smells_array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
smell1 = RubyCritic::Smell.new(locations: [location1])
smell2 = RubyCritic::Smell.new(locations: [location2])
smell3 = RubyCritic::Smell.new(locations: [location3])

_([smell1, smell2, smell3].sort).must_equal [smell3, smell2, smell1]
end

it 'implements set intersection' do
smell1 = RubyCritic::Smell.new(context: '#bar')
smell2 = RubyCritic::Smell.new(context: '#bar')
smell3 = RubyCritic::Smell.new(context: '#foo')

_([smell1, smell3] & [smell2]).must_equal [smell1]
end

it 'implements set union' do
smell1 = RubyCritic::Smell.new(context: '#bar')
smell2 = RubyCritic::Smell.new(context: '#bar')
smell3 = RubyCritic::Smell.new(context: '#foo')

_([smell1, smell3] | [smell2]).must_equal [smell1, smell3]
end
end
Loading
Loading