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

Closing Heredoc Indentation #5406

Closed
siegfault opened this issue Jan 5, 2018 · 6 comments
Closed

Closing Heredoc Indentation #5406

siegfault opened this issue Jan 5, 2018 · 6 comments

Comments

@siegfault
Copy link
Contributor

When autocorrecting heredoc indentation, the heredoc close is ignored. I think I would expect it to be realigned with the heredoc open.

The following examples use

class Foo
  <<-SQL.strip_indent
    foo
SQL
end

as starting code.


Expected behavior

When running rubocop, I'd expect to see a violation for SQL needing to be indented two spaces and for the autocorrect to result in

class Foo
  <<-SQL.strip_indent
    foo
  SQL
end

Actual behavior

Instead, there are no violations.

Steps to reproduce the problem

See above.

RuboCop version

$ rubocop -V
0.52.1 (using Parser 2.4.0.2, running on ruby 2.3.1 x86_64-linux)

Further Discussion

I'm not sure whether this would fall on the IndentHeredoc rule (which currently only handles the innards of the heredoc), the IndentationWidth rule (which handles the opening), a new ClosingHeredocIndentation rule, or somewhere else. I'd be happy to work on this if given some indication of a preferred location.

@siegfault
Copy link
Contributor Author

Any thoughts here?

@Drenmi
Copy link
Collaborator

Drenmi commented Feb 6, 2018

Either IndentationWidth or ClosingHeredocIndentation seem like a good place. 🙂

@siegfault
Copy link
Contributor Author

Sounds good - thanks! I'll see if I can take a look at this this weekend.

@Drenmi
Copy link
Collaborator

Drenmi commented Feb 7, 2018

Swell! Feel free to ping me here if you have any questions.

@siegfault
Copy link
Contributor Author

@Drenmi I opened #5557 and would love comments! I started with IndentationWidth since I thought that might be preferable, but got a bit stumped trying to make it work there. Then I got ClosingHeredocIndenation working. Knowing what I know now, I might revisit an IndentationWidth implementation, but that will probably have to wait until the weekend.

@Drenmi
Copy link
Collaborator

Drenmi commented Feb 11, 2018

I opened #5557 and would love comments!

Will have a look!

I started with IndentationWidth since I thought that might be preferable, but got a bit stumped trying to make it work there.

Expected so. It's already an insanely complex thing. 🙂

siegfault added a commit to siegfault/rubocop that referenced this issue May 22, 2018
This cop checks the indentation of here document closings.

```ruby
class Foo
  def bar
    <<~SQL
      'Hi'
  SQL
  end
end
```

```ruby
class Foo
  def bar
    <<~SQL
      'Hi'
    SQL
  end
end
```
@bbatsov bbatsov closed this as completed in 6987573 Jun 3, 2018
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

No branches or pull requests

2 participants