Baseline Logoeslint-plugin-baseline-js

Config

Rule options, preset scopes, and detection limits.

Presets (Flat Config)

Register the plugin under baseline-js before using a preset. All helpers accept available and level. Their defaults are 'widely' and 'error'. They also accept baseline as an alias for available.

HelperReturn valueFile scopeAdditional detection
configs.baseline()Config arrayjs, cjs, mjs, jsx, ts, tsxOff
configs.recommended()Config objectjs, cjs, mjs, jsxauto for Web APIs and built-ins
configs['recommended-ts']()Config objectts, tsxtype-aware for Web APIs and built-ins

Choose a starting point

Use recommended for JavaScript. Choose recommended-ts for TypeScript with type information. Use baseline when you only want the mapped rules.

A preset does not configure your parser

TypeScript needs a TypeScript parser and a project. JSX also needs parser support. See Examples for complete project setups.

Rule options

Use these options with baseline-js/use-baseline.

OptionTypeDefaultDescription
available'widely', 'newly', or a year'widely'Set the Baseline threshold.
baselineSame as available—Compatibility alias. available takes precedence.
includeWebApisBoolean or an options objectfalseEnable additional Web API detection.
includeJsBuiltinsBoolean or an options objectfalseEnable additional JavaScript built-in detection.
ignoreFeaturesstring[][]Skip feature IDs across all detectors. Supports /regex/ strings.
ignoreNodeTypesstring[][]Skip reports on matching ESTree node types. Supports /regex/ strings.

available: 'widely' reports features that are not widely available. available: 'newly' reports features with Limited availability. A year reports features that entered Baseline after that year, plus features with Limited availability.

Additional Web API and built-in checks use the matched API member's Baseline status when available. Members grouped under one feature can have different dates or availability: URL.parse(), for example, is newer than the URL interface. Feature-level coverage tables describe the group; only, ignore, and ignoreFeatures continue to use feature IDs.

These checks use the data bundled with the installed plugin. See Concepts for the policy and coverage limits.

Feature detection

The rule always checks its mapped features. Additional Web API and built-in detection is off unless you enable it.

If you already use the rule directly, add these two options for the recommended detection behavior:

eslint.config.mjs
import baselineJs from 'eslint-plugin-baseline-js';

export default [
  {
    files: ['**/*.{js,mjs,cjs}'],
    plugins: { 'baseline-js': baselineJs },
    rules: {
      'baseline-js/use-baseline': ['error', {
        available: 'widely',
        includeWebApis: { preset: 'auto' }, 
        includeJsBuiltins: { preset: 'auto' }, 
      }],
    },
  },
];

Both includeWebApis and includeJsBuiltins accept the same options:

Common detection options
type Include = boolean | {
  preset?: 'safe' | 'auto' | 'type-aware';
};
ValueBehavior
false or omittedDisable this additional detector.
true, {}, or { preset: 'safe' }Enable patterns that do not need type information.
{ preset: 'auto' }Also use type information when the parser provides it.
{ preset: 'type-aware' }Enable checks that need types when the parser provides them.

Without type information, auto and type-aware skip instance-member and other type-dependent checks. They still run the remaining checks and do not throw an error.

The safe checks include global constructors, static members, and selected constructor options. Instance method arguments, such as Canvas context options and WebGL extension names, require type information and auto or type-aware mode. These checks verify the receiver's standard-library member before reporting a literal argument. They do not cover every API or usage pattern.

Typed checks use members declared in the program's standard libraries, including compiler-selected replacement libraries. A member added only by a user declaration does not establish native API usage.

Typed instance checks recognize well-known Symbol keys such as stream[Symbol.asyncIterator]. The key must retain its unique symbol type from the standard library. Custom keys, aliases widened to symbol, and custom member overrides do not establish native API usage. The string '@@iterator' is not a Symbol key.

Buffer constructor checks require an object literal with a known final maxByteLength value. An explicit non-undefined primitive literal qualifies. An unresolved value, getter, or later spread does not. ArrayBuffer options work in safe mode. SharedArrayBuffer options require type information for JavaScript built-in checks. Options variables remain outside these checks.

Advanced options: type overrides and accepted compatibility settings
Complete detection options
type Include = boolean | {
  preset?: 'safe' | 'auto' | 'type-aware' | 'heuristic';
  useTypes?: 'off' | 'auto' | 'require';
  heuristics?: 'off' | 'conservative' | 'aggressive';
  only?: string[];
  ignore?: string[];
};

useTypes overrides the preset's type setting. safe defaults to off, auto to auto, and type-aware to require.

Type information requires a parser service with a TypeScript program. Selecting a preset alone does not create one.

Type settings apply independently to Web API and JavaScript built-in checks. Enabling types for one detector does not enable types for the other.

The schema also accepts preset: 'heuristic' and heuristics. These options do not add heuristic detection in the current implementation. Use safe, auto, or type-aware for the behavior described above.

Feature filters

only and ignore accept exact web-features IDs within that detector. They do not support regular expressions or change the mapped-rule checks. An empty only array does not limit detection. Add this rules property to your existing config object.

Filter additional built-in checks
rules: {
  'baseline-js/use-baseline': ['error', {
    available: 'widely',
    includeJsBuiltins: {
      preset: 'auto',
      only: ['iterator-join', 'set-methods'], 
    },
  }],
}

Choose the right filter

Use only to narrow one additional detector. The instance methods in this example also need type information. Use ignoreFeatures to suppress a feature across all detectors.

Ignore features or report node types
rules: {
  'baseline-js/use-baseline': ['error', {
    available: 2018,
    ignoreFeatures: ['nullish-coalescing', '/^optional-/'], 
    ignoreNodeTypes: ['WithStatement', '/Expression$/'], 
  }],
}

Legacy config (.eslintrc)

Use Flat Config with this package. Its ESM default export does not load correctly through ESLint 9's legacy plugin loader.

Seeing a missing-rule error?

Definition for rule 'baseline-js/use-baseline' was not found can result from the legacy plugin loader. Move the setup to eslint.config.mjs using a preset above.

ESLint 10 also removes legacy config support. See Examples for supported Flat Config setups.

Use with oxlint

Load the package as an oxlint JavaScript plugin.

.oxlintrc.json
{
  "jsPlugins": ["eslint-plugin-baseline-js"], 
  "rules": {
    "baseline-js/use-baseline": [
      "warn",
      {
        "available": "widely",
        "includeWebApis": { "preset": "auto" },
        "includeJsBuiltins": { "preset": "auto" }
      }
    ]
  }
}

Type information is required for some checks

The plugin's instance-member checks need TypeScript parser services. The oxlint integration does not provide them. This skips checks such as Set.prototype.difference() and Iterator.prototype.join(). Use ESLint with a configured TypeScript parser for these checks.

See oxlint for setup details and the FAQ for detection limits.

Messages

The highlighted line shows the reported usage. Messages name the API or feature, your configured Baseline target, and the reason it does not meet that target. Each message ends with a Feature ID for use in ignoreFeatures.

Static APIs use canonical paths such as 'Object.groupBy'. Additional instance-member checks use descriptions such as The 'union' member of Set instances. These members can be methods or properties.

In call patterns, ... marks unspecified values and | separates alternatives.

With available: 'widely', a feature must be widely available.

example.js
const year = new Date().getYear(); 
ESLint report
'Date.prototype.getYear' does not meet your Baseline Widely available target. It has Limited availability. Feature ID: date-get-year-set-year.

When diagnostic text changes, tests that snapshot it need updated expectations.

Why does a message contain a date such as ≤2018?

An upper-bound date keeps its ≤ prefix in the message. The policy compares the numeric year. A date of ≤2018 exceeds a 2017 target and meets a 2018 target.

Standalone rules

Most projects should use baseline-js/use-baseline. It enables mapped checks based on the selected Baseline threshold.

These rules are also exported directly. When enabled directly, they report matching usage without checking a Baseline threshold.

RuleChecks
baseline-js/no-atomics-pauseAtomics.pause calls and member access.
baseline-js/no-bigint64arrayBigInt64Array and BigUint64Array construction, calls, and member access.
baseline-js/no-function-caller-argumentsNon-computed .caller and .arguments access on known function objects.
baseline-js/no-math-sum-preciseMath.sumPrecise calls and member access.
baseline-js/no-temporalDirect Temporal member access and construction.

The global-based rules check for shadowed globals and support window and globalThis prefixes. They do not follow aliases. no-function-caller-arguments recognizes function expressions, function declarations and function initializers without reassignment, and unshadowed Function.prototype. It skips unknown receivers, parameters, imports, aliases, and reassigned bindings.

Last updated on

On this page