-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
It seems like the private keyword is not counted when considering if a Style/EndlessMethod correction would exceed the line length. With a line-length of 100:
class Example
def without_private_this_will_not_exceed_line_length
Other.my_mid_length_method_name
end
def without_private_this_will_exceed_line_length_aaaaaaaaaaaaaaaaaa
Other.my_mid_length_method_name
end
private def with_private_this_will_exceed_line_length_but_not_without
Other.my_mid_length_method_name
end
endThe first and third methods have Style/EndlessMethod offenses, but correcting the third leads to a line that is too long.
Steps to reproduce the problem
Ruby file as above. Rubocop config:
AllCops:
TargetRubyVersion: 3.4
EnabledByDefault: true
NewCops: enable
Layout/LineLength:
Max: 100
Style/EndlessMethod:
Enabled: true
EnforcedStyle: require_single_line
Expected behavior
Offense for without_private_this_will_not_exceed_line_length, but no offense for with_private_this_will_exceed_line_length_but_not_without (because it exceeds the max line length due to private). N.b. there is no offense for without_private_this_will_exceed_line_length_aaaaaaaaaaaaaaaaaa.
Actual behavior
Offense for without_private_this_will_not_exceed_line_length and with_private_this_will_exceed_line_length_but_not_without, correcting causes a Layout/LineLength offense for with_private_this_will_exceed_line_length_but_not_without.
RuboCop version
1.81.1 (using Parser 3.3.9.0, Prism 1.4.0, rubocop-ast 1.47.1, analyzing as Ruby 3.4, running on ruby 3.4.5) [arm64-darwin24]