Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout/ClassStructure syntax error / cloberring error auto-corrections #9723

Open
marcandre opened this issue Apr 21, 2021 · 0 comments
Open
Assignees
Labels

Comments

@marcandre
Copy link
Contributor

Layout/ClassStructure has a bad algorithm for moving code with respect to empty lines before/after. Look for +1 in the code.

Heredocs

Looks like the cop assumes that heredocs are always followed by a empty line

      class Foo
        attr_reader :foo
        CONSTANT = <<~EOS
        ^^^^^^^^^^^^^^^^^ `constants` is supposed to appear [...]
          abc
        EOS
      end

gets auto-corrected to:

      class Foo
        CONSTANT = <<~EOS
          abc
        EOS
        attr_reader :fooend

If the config's order is switched, then

        class Foo
          CONSTANT = <<~EOS
            #{str}
          EOS
          attr_reader :foo
          ^^^^^^^^^^^^^ [...]
        end

generates a cloberring error.

Defs

Defs (except initialize??) can create issues when not separated with empty lines. E.g.:

        class Foo
          private
          def foo
          end
          public
          def bar
          ^^^^^^^ [...]
          end
        end

gets auto-corrected to:

        class Foo
          public
          def bar
          ^^^^^^^ [...]
          end
          private
          def foo
          endend

In general, it should have been clear that to swap two blocks of code and keep good empty lines is not possible with a single "cut" and "paste", but that is what the current code is attempting.

Noticed in my refactor, I'll handle it.

@marcandre marcandre self-assigned this Apr 21, 2021
@marcandre marcandre transferred this issue from rubocop/rubocop-ast Apr 21, 2021
@Darhazer Darhazer added the bug label Apr 12, 2022
@Darhazer Darhazer self-assigned this Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants