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

Format tool removes whitespace from heredoc #4400

Closed
straight-shoota opened this issue May 11, 2017 · 1 comment
Closed

Format tool removes whitespace from heredoc #4400

straight-shoota opened this issue May 11, 2017 · 1 comment
Labels
help wanted This issue is generally accepted and needs someone to pick it up kind:bug topic:tools:formatter
Milestone

Comments

@straight-shoota
Copy link
Member

straight-shoota commented May 11, 2017

The format tool shows an odd and unwanted behaviour with heredocs: In some cases, when the heredoc uses leading whitespace, the formatter removes a single whitespace at the beginning. Multiple runs of the formatter each remove only one whitespace until there is none left. It removes only leading whitespace which is to be ignored, so the meaning of the source code does not change. Nevertheless, the leading whitespace is usually there for a reason (readability) and it is annoying to revert.

Example:

{
  "foo" => <<-END
    bar
    END,
}

Result of crystal tool format:

{
  "foo" => <<-END
   bar
   END,
}

Result of running crystal tool format four times:

{
  "foo" => <<-END
bar
END,
}

I found this to happen only when the heredoc is a value in a hash definition, but there might be other cases, too. The heredoc without the hash will not be altered:

<<-END
    bar
    END,
@mverzilli mverzilli added help wanted This issue is generally accepted and needs someone to pick it up kind:bug topic:tools labels May 14, 2017
@straight-shoota
Copy link
Member Author

Could be related to #4000

@asterite asterite added this to the Next milestone Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted This issue is generally accepted and needs someone to pick it up kind:bug topic:tools:formatter
Projects
None yet
Development

No branches or pull requests

3 participants