Baseline Logoeslint-plugin-baseline-js

Quick Start

Add Baseline checks and see your first warning in three steps.

Catch JavaScript features that exceed your browser support policy while you write code. eslint-plugin-baseline-js checks supported syntax, built-ins, and Web APIs with one rule.

Start with widely available features

The examples use widely for broad browser support. You can also choose newly or a year, such as 2024. See Scope & Terms for what each kind of check covers.

Quick Start

Install

Add ESLint and the plugin to your project:

pnpm add -D eslint eslint-plugin-baseline-js
Supported ESLint and Node.js versions

The plugin supports ESLint >=9.29.0 <11 and requires Node.js ^20.19.0 || >=22.12.0. Your ESLint version can have stricter Node.js requirements.

Configure JavaScript

Create eslint.config.mjs in your project root, or add the green lines to your existing flat config. Register the plugin, then enable its recommended preset.

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

export default [
  { plugins: { 'baseline-js': baselineJs } }, 
  baselineJs.configs.recommended({ available: 'widely', level: 'warn' }), 
];

Both versions work the same way. The constants help avoid typos when you reuse a target across configs. The recommended preset covers JavaScript files and enables Web API and built-in checks with preset: 'auto'.

Using TypeScript?

Keep this JavaScript block and add the TypeScript setup below. For a complete app setup, see JS + CSS + HTML.

Run the check

Create a small file to try it:

example.js
const date = new Date();
const year = date.getYear(); 

Then run ESLint:

pnpm exec eslint example.js

You’re all set

You should see a warning on getYear(). The preview shows the code and a shortened message together. Switch to Use instead to see the change:

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

Your Baseline check is active

Start with level: 'warn' to review existing code. Change it to 'error' when you want violations to fail your lint command.

Add TypeScript

Type information lets the rule recognize supported instance members, such as Set.prototype.difference(). Install the parser and TypeScript:

pnpm add -D @typescript-eslint/parser typescript

Add the TypeScript block alongside the JavaScript preset. The green lines mark the parser and type-aware settings:

eslint.config.mjs
import tsParser from '@typescript-eslint/parser'; 
import baselineJs from 'eslint-plugin-baseline-js';

export default [
  { plugins: { 'baseline-js': baselineJs } },
  baselineJs.configs.recommended({ available: 'widely', level: 'warn' }),
  {
    ...baselineJs.configs['recommended-ts']({ available: 'widely', level: 'warn' }), 
    languageOptions: {
      parser: tsParser, 
      parserOptions: {
        project: './tsconfig.json', 
        tsconfigRootDir: import.meta.dirname, 
      },
    },
  },
];

Point the parser at your project

Your tsconfig.json must include the files you lint and the library declarations for the APIs you use. See the complete TypeScript example for a starter config.

File scopes and checks that need types

recommended matches .js, .cjs, .mjs, and .jsx. JSX also needs parser settings. recommended-ts matches .ts and .tsx, so use both presets for a mixed project.

Without parser type information, the rule skips instance-member and other type-dependent checks. The preset does not configure a parser or throw an error itself. See Configuration for the detection options.

Use mapped rules without extra API checks

Use baseline if you want the mapped checks for syntax and some built-ins without enabling the extra API detectors. Spread the helper's array into your config:

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

export default [
  { plugins: { 'baseline-js': baselineJs } }, 
  ...baselineJs.configs.baseline({ available: 'widely', level: 'warn' }), 
];

Remember the spread

baseline() returns an array. recommended() and recommended-ts() return single config objects. All three still need the right parser settings for your files.

Next steps

Further reading

Last updated on

On this page