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

Fix HEREDOCs in Style/Multiline*BraceLayout Cops #3088

Merged
merged 1 commit into from
Apr 28, 2016

Conversation

panthomakos
Copy link
Contributor

@jonas054 this relates to a previous Pull Request you made. NOTE: I have not adjusted the comment correction behavior. The tests still exist for that and are not impacted by this change. This only relates to HEREDOC edits that can cause invalid code.

#2873 introduced some changes to HEREDOC handling. While
these changes fixed some issues with auto-correcting and comments, they
also broke the handling of some HEREDOC use-cases.

For example, this code cannot be corrected in the symmetrical or same
line style because EOM) on the last line would be invalid code.

foo(a,
  b: <<-EOM
    bar
  EOM
)

# invalid
foo(a,
  b: <<-EOM
    bar
  EOM)

Additionally, this code cannot be corrected in the symmetrical or same
line style because <<-EOM).to(<<-EOM2 would not be valid code.

foo(<<-EOM
    bar
  EOM
).to(<<-EOM2
  baz
EOM2
)

# invalid
foo(<<-EOM).to(<<-EOM2
    bar
  EOM
  baz
EOM2
)

This change simply ignores HEREDOCs that cannot be corrected. The
determination is made by checking the HEREDOC's last line.

For example, the following can be corrected because the HEREDOC ends on
a non-conflicting line.

foo(a,
  b: {
    c: <<-EOM
      bar
    EOM
  }
)

# valid
foo(a,
  b: {
    c: <<-EOM
      bar
    EOM
  })

@panthomakos panthomakos force-pushed the heredoc-fix branch 2 times, most recently from 98e34ff to 9d5479e Compare April 27, 2016 22:05
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 28, 2016

The build is failing.

rubocop#2873 introduced some changes to HEREDOC handling. While
these changes fixed some issues with auto-correcting and comments, they
also broke the handling of some HEREDOC use-cases.

For example, this code cannot be corrected in the symmetrical or same
line style because `EOM)` on the last line would be invalid code.

    foo(a,
      b: <<-EOM
        bar
      EOM
    )

    # invalid
    foo(a,
      b: <<-EOM
        bar
      EOM)

Additionally, this code cannot be corrected in the symmetrical or same
line style because `<<-EOM).to(<<-EOM2` would not be valid code.

    foo(<<-EOM
        bar
      EOM
    ).to(<<-EOM2
      baz
    EOM2
    )

    # invalid
    foo(<<-EOM).to(<<-EOM2
        bar
      EOM
      baz
    EOM2
    )

This change simply ignores HEREDOCs that cannot be corrected. The
determination is made by checking the HEREDOC's last line.

For example, the following can be corrected because the HEREDOC ends on
a non-conflicting line.

    foo(a,
      b: {
        c: <<-EOM
          bar
        EOM
      }
    )

    # valid
    foo(a,
      b: {
        c: <<-EOM
          bar
        EOM
      })
@panthomakos
Copy link
Contributor Author

@bbatsov sorry about that - rebased and fixed

@bbatsov bbatsov merged commit 0196a34 into rubocop:master Apr 28, 2016
Neodelf pushed a commit to Neodelf/rubocop that referenced this pull request Oct 15, 2016
rubocop#2873 introduced some changes to HEREDOC handling. While
these changes fixed some issues with auto-correcting and comments, they
also broke the handling of some HEREDOC use-cases.

For example, this code cannot be corrected in the symmetrical or same
line style because `EOM)` on the last line would be invalid code.

    foo(a,
      b: <<-EOM
        bar
      EOM
    )

    # invalid
    foo(a,
      b: <<-EOM
        bar
      EOM)

Additionally, this code cannot be corrected in the symmetrical or same
line style because `<<-EOM).to(<<-EOM2` would not be valid code.

    foo(<<-EOM
        bar
      EOM
    ).to(<<-EOM2
      baz
    EOM2
    )

    # invalid
    foo(<<-EOM).to(<<-EOM2
        bar
      EOM
      baz
    EOM2
    )

This change simply ignores HEREDOCs that cannot be corrected. The
determination is made by checking the HEREDOC's last line.

For example, the following can be corrected because the HEREDOC ends on
a non-conflicting line.

    foo(a,
      b: {
        c: <<-EOM
          bar
        EOM
      }
    )

    # valid
    foo(a,
      b: {
        c: <<-EOM
          bar
        EOM
      })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants