Rails: Auto-Formatting on VSCode

Flavio Wuensche
2 min readJul 5, 2023

Use Syntax Tree to auto-format Ruby on Rails files on Visual Studio Code.

Photo by Pawel Czerwinski on Unsplash

Auto code formatters like prettier bring several benefits to the table.

  • They save you valuable time by automatically formatting your code, eliminating the need for manual formatting.
  • They ensure code is consistent and readable code across your entire project.
  • They reduce code review discussions related to formatting, making collaboration smoother.

Overall, you can focus on writing code without worrying about formatting rules. So, let's setup your Rails project so it can handle the formatting, while you enjoy the pure pleasure of coding.

Install the syntax_tree gem

You're only going to need one new dependency:

gem 'syntax_tree'

Then from the command line:

bundle install

Setup a .streetrc file

We can now setup a .streerc file at the root of the project:

--print-width=120
--plugins=plugin/single_quotes,plugin/trailing_comma
--ignore-files='**/node_modules/**'
--ignore-files='vendor/**'

Prevent conflicts with Rubocop

--

--

Flavio Wuensche

Building an open-source tool to keep track of technical debt on large codebases 🍒 cherrypush.com