Skip to content

Comments are duplicated during autocorrection by Style/AccessorGrouping #14370

@r7kamura

Description

@r7kamura

Expected behavior

For example, when running autocorrect with the following configuration:

Style/AccessorGrouping:
  EnforcedStyle: separated
# frozen_string_literal: true

class Foo
  attr_reader :a, # a
    :b # b
end

In this case, the expected change was as follows:

# frozen_string_literal: true

class Foo
  # a
  attr_reader :a
  # b
  attr_reader :b
end

Actual behavior

The trailing comment ends up duplicated as shown below:

# frozen_string_literal: true

class Foo
  # a
  attr_reader :a
  # b
  attr_reader :b # b
end

It seems that when the original code spans multiple lines without parentheses, the trailing comment gets duplicated.

Steps to reproduce the problem

The issue can be easily reproduced by running autocorrect with the code and configuration described above.

RuboCop version

$ bundle exec rubocop -V
1.78.0 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 2.7, running on ruby 3.4.2) [x86_64-linux]
  - rubocop-performance 1.25.0
  - rubocop-rake 0.7.1
  - rubocop-rspec 3.6.0

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy