Feature Flags - ESLint - Pluggable JavaScript Linter (original) (raw)

Table of Contents

  1. Flag Prefixes
  2. Active Flags
  3. Inactive Flags
  4. How to Use Feature Flags
    1. Enable Feature Flags with the CLI
    2. Enable Feature Flags with the API
    3. Enable Feature Flags in VS Code

ESLint ships experimental and future breaking changes behind feature flags to let users opt-in to behavior they want. Flags are used in these situations:

  1. When a feature is experimental and not ready to be enabled for everyone.
  2. When a feature is a breaking change that will be formally merged in the next major release, but users may opt-in to that behavior prior to the next major release.

Flag Prefixes

The prefix of a flag indicates its status:

A feature may move from unstable to being enabled by default without a major release if it is a non-breaking change.

The following policies apply to unstable_ flags.

Active Flags

The following flags are currently available for use in ESLint.

Flag Description
unstable_config_lookup_from_file Look up `eslint.config.js` from the file being linted.
unstable_native_nodejs_ts_config Use native Node.js to load TypeScript configuration.

Inactive Flags

The following flags were once used but are no longer active.

Flag Description Inactivity Reason
unstable_ts_config Enable TypeScript configuration files. This feature is now enabled by default.

How to Use Feature Flags

Because feature flags are strictly opt-in, you need to manually enable the flags that you want.

Enable Feature Flags with the CLI

On the command line, you can specify feature flags using the --flag option. You can specify as many flags as you’d like:

npm

npx eslint --flag flag_one --flag flag_two file.js 

yarn

yarn dlx eslint --flag flag_one --flag flag_two file.js 

pnpm

pnpm dlx eslint --flag flag_one --flag flag_two file.js 

bun

bunx eslint --flag flag_one --flag flag_two file.js 

Enable Feature Flags with the API

When using the API, you can pass a flags array to both the ESLint and Linter classes:

const { ESLint, Linter } = require("eslint");

const eslint = new ESLint({
    flags: ["flag_one", "flag_two"],
});

const linter = new Linter({
    flags: ["flag_one", "flag_two"],
});

Enable Feature Flags in VS Code

To enable flags in the VS Code ESLint Extension for the editor, specify the flags you’d like in the eslint.options setting in your settings.json file:

{
    "eslint.options": { "flags": ["flag_one", "flag_two"] }
}

To enable flags in the VS Code ESLint Extension for a lint task, specify the eslint.lintTask.options settings:

{
    "eslint.lintTask.options": "--flag flag_one --flag flag_two ."
}