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.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more