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-jsSupported 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.
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:
const date = new Date();
const year = date.getYear(); Then run ESLint:
pnpm exec eslint example.jsYou’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:
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 typescriptAdd the TypeScript block alongside the JavaScript preset. The green lines mark the parser and type-aware settings:
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:
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
Check your whole app
Use one Baseline target for JavaScript, TypeScript, CSS, and HTML.
Choose your settings
Compare presets and learn how to handle specific exceptions.
Use Oxlint
Add the rule through Oxlint's JavaScript plugin support.
Explore coverage
See the mapped features and supported detection patterns.
Further reading
- What is Baseline? from the W3C WebDX Community Group.
- Bringing Baseline into Product Development — and Keeping It Safe in Practice: a case study from this project's author.
Last updated on