Skip to content

Commit 79282f1

Browse files
committed
Apply or suppress changes suggested by more modern rubocop.
1 parent 65e5be4 commit 79282f1

26 files changed

+78
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.2...main)
22

3+
* [CHANGE] Add changes or suppress warnings for issues found by newer rubocop (by [@faisal][])
34
* [CHANGE] Update CI checkout action to v4 (by [@faisal][])
45

56
# v4.9.2 / 2025-04-08 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.9.1...v4.9.2)

lib/rubycritic/cli/options/file.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ def paths
9696
options['paths']
9797
end
9898

99+
# rubocop:disable Naming/PredicateMethod
99100
def value_for(value)
100101
value = value.to_s
101102
value == 'true' unless value.empty?
102103
end
104+
# rubocop:enable Naming/PredicateMethod
103105
end
104106
end
105107
end

lib/rubycritic/commands/status_reporter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def update_status
2626
end
2727

2828
def current_status
29-
satisfy_minimum_score_rule ? SUCCESS : SCORE_BELOW_MINIMUM
29+
satisfy_minimum_score_rule? ? SUCCESS : SCORE_BELOW_MINIMUM
3030
end
3131

32-
def satisfy_minimum_score_rule
32+
def satisfy_minimum_score_rule?
3333
score >= @options[:minimum_score].to_f
3434
end
3535

lib/rubycritic/rake_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_task
7171

7272
def print_starting_up_output
7373
puts "\n\n!!! Running `#{name}` rake command\n"
74-
puts "!!! Inspecting #{paths} #{options.empty? ? '' : "with options #{options}"}\n\n"
74+
puts "!!! Inspecting #{paths} #{"with options #{options}" unless options.empty?}\n\n"
7575
end
7676

7777
def options_as_arguments

lib/rubycritic/source_control_systems/git.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def head_reference
5050
end
5151

5252
def travel_to_head
53-
stash_successful = stash_changes
53+
stash_successful = stash_changes?
5454
yield
5555
ensure
5656
travel_to_original_state if stash_successful
@@ -88,7 +88,7 @@ def self.current_branch
8888

8989
private
9090

91-
def stash_changes
91+
def stash_changes?
9292
stashes_count_before = stashes_count
9393
git('stash')
9494
stashes_count_after = stashes_count

lib/rubycritic/source_control_systems/perforce.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ def date_of_last_commit(path)
5252
Time.strptime(perforce_files[Perforce.key_file(path)].last_commit, '%s').strftime('%Y-%m-%d %H:%M:%S %z')
5353
end
5454

55+
# rubocop:disable Style/CollectionQuerying
5556
def revision?
5657
!perforce_files.values.count(&:opened?).zero?
5758
end
59+
# rubocop:enable Style/CollectionQuerying
5860

5961
def head_reference
6062
perforce_files.values.map(&:head).max_by(&:to_i)

test/fakefs_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ class File < StringIO
88
# $VERBOSE = nil to suppress warnings when we override flock.
99
original_verbose = $VERBOSE
1010
$VERBOSE = nil
11+
12+
# rubocop:disable Naming/PredicateMethod
1113
def flock(*)
1214
true
1315
end
16+
# rubocop:enable Naming/PredicateMethod
1417
$VERBOSE = original_verbose
1518
end
1619
end

test/lib/rubycritic/analysers/helpers/methods_counter_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
context 'when a file contains Ruby code' do
99
it 'calculates the number of methods' do
1010
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb')
11+
1112
_(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 2
1213
end
1314
end
1415

1516
context 'when a file is empty' do
1617
it 'returns 0 as the number of methods' do
1718
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb')
19+
1820
_(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 0
1921
end
2022
end
2123

2224
context 'when a file has no method' do
2325
it 'does not blow up and returns 0 as the number of methods' do
2426
analysed_module = AnalysedModuleDouble.new(path: 'test/samples/no_methods.rb')
27+
2528
capture_output_streams do
2629
_(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 0
2730
end

test/lib/rubycritic/analysers/helpers/modules_locator_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
pathname: Pathname.new('test/samples/module_names.rb'),
1414
methods_count: 1
1515
)
16+
1617
_(RubyCritic::ModulesLocator.new(analysed_module).names)
1718
.must_equal ['Foo', 'Foo::Bar', 'Foo::Baz', 'Foo::Qux', 'Foo::Quux::Corge']
1819
end
@@ -24,6 +25,7 @@
2425
pathname: Pathname.new('test/samples/empty.rb'),
2526
methods_count: 1
2627
)
28+
2729
_(RubyCritic::ModulesLocator.new(analysed_module).names).must_equal ['Empty']
2830
end
2931
end
@@ -34,6 +36,7 @@
3436
pathname: Pathname.new('test/samples/no_methods.rb'),
3537
methods_count: 0
3638
)
39+
3740
capture_output_streams do
3841
_(RubyCritic::ModulesLocator.new(analysed_module).names).must_equal ['Foo::NoMethods']
3942
end

test/lib/rubycritic/analysers/smells/flay_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121

2222
it 'creates smells with messages' do
2323
smell = @analysed_modules.first.smells.first
24+
2425
_(smell.message).must_be_instance_of String
2526
end
2627

2728
it 'creates smells with scores' do
2829
smell = @analysed_modules.first.smells.first
30+
2931
_(smell.score).must_be_kind_of Numeric
3032
end
3133

3234
it 'creates smells with more than one location' do
3335
smell = @analysed_modules.first.smells.first
36+
3437
_(smell.multiple_locations?).must_equal true
3538
end
3639

0 commit comments

Comments
 (0)