Formatter

Rome’s an opinionated formatter that has the goal to stop all ongoing debates over styles. It follows a similar philosophy to Prettier, only supporting few options to avoid that debates over styles turn into debates over Rome options. It deliberately resists the urge to add new options to prevent bike-shed discussions in teams so they can focus on what really matters instead.

Options

The language agnostic options supported by Rome are:

Other formatting options are available for specific languages as well. See the configuration options for details.

Use the formatter with the CLI

You can start by running the CLI with the --help flag:

npx rome format --help
yarn rome format --help
pnpm rome format --help

Which will show you the options available at the moment:

Rome Formatter

USAGE:
    rome format [OPTIONS] <INPUTS...>

    INPUTS can be one or more filesystem path, each pointing to a single file or an entire directory to be searched recursively for supported files

EXAMPLES:
    rome format ./scripts/file.js
    rome format ./
    rome format ./src ./internal ./scripts

OPTIONS:
    --write                                  Edit the files in place (beware!) instead of printing the diff to the console
    --skip-errors                            Skip over files containing syntax errors instead of emitting an error diagnostic.
    --max-diagnostics                        Cap the amount of diagnostics displayed (default: 50)
    --config-path                            Set the filesystem path to the directory of the rome.json configuration file
    --verbose                                Print additional verbose advices on diagnostics
    --indent-style <tabs|space>              Change the indention character (default: tabs)
    --indent-size <number>                   If the indentation style is set to spaces, determine how many spaces should be used for indentation (default: 2)
    --line-width <number>                    Change how many characters the formatter is allowed to print in a single line (default: 80)
    --quote-style <single|double>            Changes the quotation character for strings (default: double)
    --quote-properties <as-needed|preserve>  Changes when properties in object should be quoted (default: as-needed)
    --trailing-comma <all|es5|none>          Changes trailing commas in multi-line comma-separated syntactic structures (default: all)
    --semicolons <always|as-needed>          Changes when to print semicolons for statements (default: always)
    --stdin-file-path <string>               A file name with its extension to pass when reading from standard in, e.g. echo 'let a;' | rome format --stdin-file-path file.js

Configuration

You may want to configure rome using rome.json. The following defaults are applied:

{
  "formatter": {
    "enabled": true,
    "formatWithErrors": false,
    "indentStyle": "tab",
    "indentSize": 2,
    "lineWidth": 80,
    "ignore": []
  }
}

Ignoring Code

There are times when the way we format code might not be ideal. For these cases you can use a format suppression comment:

// rome-ignore format: <explanation>

Example:

const expr =
  // rome-ignore format: the array should not be formatted
  [
    (2 * n) / (r - l),
    0,
    (r + l) / (r - l),
    0,
    0,
    (2 * n) / (t - b),
    (t + b) / (t - b),
    0,
    0,
    0,
    -(f + n) / (f - n),
    -(2 * f * n) / (f - n),
    0,
    0,
    -1,
    0,
  ];