tools icon indicating copy to clipboard operation
tools copied to clipboard

📎 Allow "$schema" in rome.json

Open simon04 opened this issue 3 years ago • 4 comments

Description

As a web developer I love good developer experience. For configuration files, JSON schemas are super helpful. I'd like to add $schema to my rome.json

{
  "$schema": "https://raw.githubusercontent.com/rome/tools/main/editors/vscode/configuration_schema.json",
  "formatter": {
    "indentStyle": "space"
  }
}

However, rome format fails:

> node_modules/.bin/rome --version
Rome CLI version 10.0.1

> node_modules/.bin/rome format --write app/
Error: Rome couldn't load the configuration file, here's why: 
unknown field `$schema`, expected one of `files`, `formatter`, `linter`, `javascript` at line 2 column 11
error Command failed with exit code 1.

Related: #3602

simon04 avatar Nov 12 '22 19:11 simon04

Great idea! I believe we currently define a JSON schema in the VSCode extension for rome.json files, but having it inline would be the best experience.

sebmck avatar Nov 12 '22 22:11 sebmck

We can also setup a shorter URL so you could do something like:

{
  "$schema": "https://rome.tools/schema/10.0.1"
}

sebmck avatar Nov 12 '22 22:11 sebmck

Having a shorter URL is the long term plan, but I don't know if we would be able to provide that for the next release. Although, we can provide another alternative for the next release while we work on the URL.

The option is to create a configuration_schema.json that we publish inside the rome npm package. Then, when running the command rome init, we generate something like this:

{
  "$schema": "./node_modules/rome/configuration_schema.json",
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  }
}

This will also be documented on our website. Is this solution satisfactory? The nice addendum of this solution is that the schema will always be up to date every time the package rome is updated.

Of course this solution might not cover all the cases (deno for example, for the absence of node_modules/ folder), but we don't target deno for the time being.

ematipico avatar Nov 15 '22 10:11 ematipico

Is this solution satisfactory?

Yes (from my point of view). The JSON schema and Rust serve would need to be adapted to allow a toplevel $schema property. Thank you!

simon04 avatar Nov 15 '22 18:11 simon04