KEMBAR78
Private method has Style/EndlessMethod false-positive that would cause Layout/LineLength offense · Issue #14594 · rubocop/rubocop · GitHub
Skip to content

Private method has Style/EndlessMethod false-positive that would cause Layout/LineLength offense #14594

@owst

Description

@owst

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
end

The 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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions