DEV Community

Mike Rispoli
Mike Rispoli

Posted on

Format on save for ERB and Ruby files in Zed IDE

Something that I really wanted when working with (Zed)[https://zed.dev] and Ruby on Rails was format on save ability for my .rb and .erb files. The setup is simple so I thought I'd give it a share:

First open your settings.json file with cmnd + , or going to Zed -> Settings -> Open Settings.

Then add a key for languages with the following:

{
  ...other_settings_here,
  "languages": {
    "Ruby": {
      "format_on_save": "on",
      "formatter": {
        "external": {
          "command": "./bin/bundle",
          "arguments": [
            "exec",
            "rubocop",
            "--auto-correct",
            "--stdin",
            "corrected.rb",
            "--stderr"
          ]
        }
      }
    },
    "ERB": {
      "formatter": [
        {
          "external": {
            "command": "sh",
            "arguments": [
              "-c",
              "f=erblinttemp_$RANDOM$RANDOM.html.erb; cat > $f; erblint -a $f &>/dev/null; cat $f; rm $f;"
            ]
          }
        },
        {
          "external": {
            "command": "htmlbeautifier",
            "arguments": []
          }
        }
      ],
      "format_on_save": "on"
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

There you have it format on save for your template files and ruby files ready to go.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay