Linter

Rome’s linter statically analyzes your code to catch common errors and help you write more idiomatic code.

Use the linter via CLI

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

npx rome check --help
yarn rome check --help
pnpm rome check --help

Which will show you the options available at the moment:

Rome Check: Run the linter on a set of files

USAGE:
    rome check <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

OPTIONS:
    --apply                       Apply safe fixes
    --apply-suggested             Apply safe and suggested fixes
    --max-diagnostics             Cap the amount of diagnostics displayed - default 20

Code fixes

Lint rules may provide automatic code fixes. Rome distinguishes between two types of fixes:

Safe fixes are guaranteed to not change the semantics of your code, and can be applied without explicit review.

Suggested fixes may change the semantics of your program, and it’s, therefore, advised to manually review the changes.

Ignoring Code

There are times when a developer wants to ignore a lint rule for a specific line of the code.

You can achieve this by adding a suppression comment above the line that is triggering the lint diagnostic.

Suppression comments have the following format:

// rome-ignore lint: <explanation>
// rome-ignore lint/correctness/noDebugger: <explanation>

Where

Here’s an example:

// rome-ignore lint: reason
debugger;
// rome-ignore lint/correctness/noDebugger: reason
debugger;

Configuration

Enable a lint rule

Rules that are recommended are enabled by default. Rules that are not recommended are not enabled, but they should be enabled via configuration.

To enable rules, you need to change their diagnostics severity based on your needs:

{
  "linter": {
    "enabled": true,
    "rules": {
      "correctness": {
        "noDebugger": "error",
        "noSparseArray": "warn"
      }
    }
  }
}

Disable a lint rule

Just add "off" as value inside its configuration. For example:

{
  "linter": {
    "enabled": true,
    "rules": {
      "correctness": {
        "noCommentText": "off"
      },
      "style": {
        "noNegationElse": "off"
      }
    }
  }
}

Change the diagnostic severity

Most of Rome’s rules will emit an error, but you are free to change their severity. Just add "warn" as value of the rule. Example:

{
  "linter": {
    "enabled": true,
    "rules": {
      "correctness": {
        "noCommentText": "warn"
      },
      "style": {
        "noNegationElse": "error"
      }
    }
  }
}

This is useful in cases there’s being a refactor going on and there’s need to make the CI passing.

Rule options

Not all the rules require options, but when they do accept some, you can pass them by shaping the value of the rule in a different way.

{
  "linter": {
    "enabled": true,
    "rules": {
      "correctness": {
        "noCommentText": {
          "level": "warn",
          "options": {}
        }
      }
    }
  }
}