Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To automatically format Ruby or .erb files in VS Code, you can follow these steps:

  1. Install the ‘Ruby’ extension (if not already installed).
  2. Press Ctrl + Shift + P (Windows/Linux) or Command + Shift + P (Mac) to open the Command Palette.
  3. Type ‘Preferences: Open Settings (JSON)’ in the Command Palette and press Enter.
  4. In the ‘settings.json’ file, add the following line:

    "ruby.format": "rubocop"

  5. Save the file and close it.

  6. Open a Ruby or .erb file and press Ctrl + Shift + I (Windows/Linux) or Command + Shift + I (Mac) to format the file.

Alternatively, you can also click on the ‘Format Document’ option in the context menu (right-click) of the editor.