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 Ruby #1456

Closed
1 task
erbridge opened this issue Sep 14, 2022 · 6 comments
Closed
1 task

Format Ruby #1456

erbridge opened this issue Sep 14, 2022 · 6 comments
Assignees
Labels
e Effort (I know how and it's quick) requires research Is this still an issue? What are viable solutions? vv Very Valuable won't fix
Milestone

Comments

@erbridge
Copy link
Contributor

User story

As a developer I need to have my Ruby code formatted by a computer so that I know it follows the repository code standards and doesn't have make formatting choices.

Acceptance criteria

  • Ruby code is formatted while committing

Implementation notes & questions

Implementation plan

To be written by the developer

@erbridge erbridge added vv Very Valuable e Effort (I know how and it's quick) tech-debt labels Sep 14, 2022
@erbridge erbridge added this to the Tech debt milestone Sep 14, 2022
@erbridge erbridge self-assigned this Sep 28, 2022
@erbridge erbridge removed this from the Tech debt milestone Oct 18, 2022
@erbridge erbridge moved this to Next in PlaceCal roadmap Oct 18, 2022
@erbridge erbridge removed their assignment Oct 18, 2022
@erbridge erbridge moved this from Next to Now in PlaceCal roadmap Oct 18, 2022
@katjam katjam added this to the Tech debt milestone Jan 8, 2024
@katjam katjam removed the chore label Jan 11, 2024
@r-ferrier r-ferrier added the requires research Is this still an issue? What are viable solutions? label Jan 15, 2024
@aaaaargZombies
Copy link
Contributor

https://github.com/adamzapasnik/prettier-plugin-erb - might be useful

@r-ferrier
Copy link
Contributor

Thios has been a trip! Prettier for ruby works really well but it is not in accordance with rubocop. I changed some of the rules but I can't get the two to agree on indentation.

Prettier wants this:
Screenshot 2024-02-14 at 17 17 08

Rubocop wants this:
Screenshot 2024-02-14 at 17 16 58

Prettier's suggestion is really odd to me and I'm unable to work out what phrase to search for to find out why it would be doing this - the only kind of indentation rules I'm finding are two do with the age old 2 vs 4 spaces battle, nothing about indenting to the starting position of the opening bracket.

Given the above I think I might use it for a one off file format, and then run the files through rubocop? This would at least tidy some things up, whilst stopping the two from clashing. What do we think?

@r-ferrier
Copy link
Contributor

discussed in tech standup - can we just run this on erb files?

@r-ferrier
Copy link
Contributor

r-ferrier commented Feb 19, 2024

unfortunately the erb arm of this plugin is currently very broken. I've just tried to add it and ran into several problems, then found this:

adamzapasnik/prettier-plugin-erb#137

I then tried to find another erb editor and discovered erb-lint, which runs on rubocop - https://github.com/Shopify/erb-lint

BUT setting this up has been quite painful. It requires a lot of special config rules to stop rubocop from doing mad things to your erb, because it treats every block as a separate file, for example injecting "frozen string literal" into files thousands of times! I've tried adding config rules to address this (Shopify/erb_lint#222) but it's still introducing lots of changes that just break the erb, like reformatting variable assignation, for example

<% build = ENV['GIT_REV'] ? ENV['GIT_REV'][0,7] : 'main' %>

becomes

<% ENV['GIT_REV'] ? ENV['GIT_REV'][0, 7] : 'main' %>

which is extremely not helpful! The main thing it does everywhere in spades is reformatting double quotations to single quotations, and it doesn't do any helpful long line or weird space reformatting, although it does tell you about long lines.

So, the summary is, this is more work than it's worth to introduce and I'm going to close this now as being thoroughly researched.

@github-project-automation github-project-automation bot moved this from Now to Done in PlaceCal roadmap Feb 19, 2024
@r-ferrier
Copy link
Contributor

@aaaaargZombies tagging you in case you're interested!

@aaaaargZombies
Copy link
Contributor

At least we (you) tried. We will have to continue with our ugly templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e Effort (I know how and it's quick) requires research Is this still an issue? What are viable solutions? vv Very Valuable won't fix
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants