Examples
Complete Baseline setups for JavaScript, TypeScript, CSS, and HTML.
Use these examples in eslint.config.mjs with ESLint 9 or 10.
See Config for all rule options and preset scopes.
Start with your project
Use the JavaScript example for .js files. Choose TypeScript when you need checks on typed instance methods.
For styles and markup too, use Full (JS + CSS + HTML).
JavaScript
The recommended preset enables both detectors with preset: 'auto'.
It applies to js, cjs, mjs, and jsx files. It uses types only when your parser provides them.
import baselineJs from 'eslint-plugin-baseline-js';
export default [
{ plugins: { 'baseline-js': baselineJs } },
baselineJs.configs.recommended({ available: 'widely', level: 'warn' }),
];Using JSX?
Add languageOptions.parserOptions.ecmaFeatures.jsx: true or use a parser that supports JSX.
This checks JavaScript usage in JSX files. It does not check HTML attributes or React-specific browser support.
TypeScript
Install the parser and TypeScript alongside the plugin:
pnpm add -D eslint eslint-plugin-baseline-js typescript @typescript-eslint/parserThe TypeScript preset targets ts and tsx files. Configure the parser in the same config object.
import tsParser from '@typescript-eslint/parser';
import baselineJs from 'eslint-plugin-baseline-js';
export default [
{ plugins: { 'baseline-js': baselineJs } },
{
...baselineJs.configs['recommended-ts']({ available: 'widely' }),
languageOptions: {
parser: tsParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
},
];Set up a tsconfig.json for these checks
Your tsconfig.json must include the files you lint.
Its library declarations must include the APIs you use so TypeScript can resolve their types.
For example, a browser project using Iterator helpers can include DOM and ESNext declarations:
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "ESNext"],
"jsx": "preserve",
"strict": true,
"noEmit": true
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
}TypeScript declarations do not add browser support or polyfills.
Without type information, the plugin skips instance-member checks such as Set.prototype.difference() and Iterator.prototype.join().
Try an instance method that needs type information:
const left = new Set([1, 2]);
left.difference(new Set([2])); With available: 'widely', the bundled data produces this report:
The 'difference' member of Set instances does not meet your Baseline Widely available target. It is Baseline Newly available. Feature ID: set-methods.No report on an instance method?
Check the parser project and the receiver's type. A missing declaration or a value typed as any can hide a check.
See the FAQ for the full checklist.
Mixed JavaScript and TypeScript
Use both presets. Each applies to its own file extensions.
The added JavaScript preset covers .js, .cjs, .mjs, and .jsx alongside your TypeScript block.
import tsParser from '@typescript-eslint/parser';
import baselineJs from 'eslint-plugin-baseline-js';
export default [
{ plugins: { 'baseline-js': baselineJs } },
baselineJs.configs.recommended({ available: 'widely' }),
{
...baselineJs.configs['recommended-ts']({ available: 'widely' }),
languageOptions: {
parser: tsParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
},
];Year and feature filters
This setup reports detected features that entered Baseline after 2020. It also reports features with Limited availability.
ignoreFeatures applies to every detector. The only filter limits additional built-in checks to exact feature IDs.
import baselineJs from 'eslint-plugin-baseline-js';
export default [
{
files: ['**/*.{js,mjs,cjs}'],
plugins: { 'baseline-js': baselineJs },
rules: {
'baseline-js/use-baseline': ['error', {
available: 2020,
ignoreFeatures: ['nullish-coalescing', '/^optional-/'],
includeWebApis: { preset: 'safe' },
includeJsBuiltins: {
preset: 'safe',
only: ['array-group'],
},
}],
},
},
];Disable checks for test files
Order matters
Place the override after the preset so it takes precedence. The highlighted lines disable only this rule for matching test files.
import baselineJs from 'eslint-plugin-baseline-js';
export default [
{ plugins: { 'baseline-js': baselineJs } },
baselineJs.configs.recommended(),
{
files: ['**/*.test.{js,mjs,cjs}'],
rules: { 'baseline-js/use-baseline': 'off' },
},
];Full (JS + CSS + HTML)
Check JavaScript, CSS, and HTML with one ESLint config and one Baseline target.
This example combines eslint-plugin-baseline-js, @eslint/css, and @html-eslint/eslint-plugin.
Install the plugins and browser globals:
pnpm add -D eslint eslint-plugin-baseline-js @eslint/css @html-eslint/eslint-plugin globalsSave this as eslint.config.mjs in your project root:
import css from "@eslint/css";
import html from "@html-eslint/eslint-plugin";
import baselineJs, { BASELINE } from "eslint-plugin-baseline-js";
import globals from "globals";
const available = BASELINE.WIDELY;
export default [
// JavaScript, including JSX.
{
...baselineJs.configs.recommended({ available }),
plugins: { "baseline-js": baselineJs },
languageOptions: {
globals: globals.browser,
parserOptions: { ecmaFeatures: { jsx: true } },
},
},
// CSS files.
{
files: ["**/*.css"],
plugins: { css },
language: "css/css",
rules: {
"css/use-baseline": ["error", { available }],
},
},
// HTML files.
{
files: ["**/*.html"],
plugins: { "@html-eslint": html },
language: "@html-eslint/html",
rules: {
"@html-eslint/use-baseline": ["error", { available }],
},
},
];Run all three checks:
pnpm exec eslint .One target, three file types
Change available once to use BASELINE.NEWLY or a year such as 2024 across all three plugins.
Keep browser globals inside the JavaScript block so they do not apply to the CSS or HTML language.
This example uses HTML ESLint's language setup. It does not need a separate @html-eslint/parser import.
For TypeScript, add the parser block from Mixed JavaScript and TypeScript and pass the same available value.
Each plugin has its own data version and detection coverage. The HTML and CSS blocks check standalone files. See the HTML rule and CSS rule for their options.
The same config is available in the examples directory.
Try each language
Save a sample file and run ESLint. Each tab shows a reported feature alongside widely available usage.
const year = new Date().getYear();
const fullYear = new Date().getFullYear();'Date.prototype.getYear' does not meet your Baseline Widely available target. It has Limited availability. Feature ID: date-get-year-set-year.These reports can change when a plugin updates its feature data.
Migrating from legacy config
Use the Flat Config examples above with ESLint 9 or 10.
ESLint 9's legacy .eslintrc plugin loader does not load this package's rule exports correctly.
ESLint 10 removes legacy config support.
oxlint
See oxlint for the JavaScript plugin setup and type-information limits.
Constants
The package exports BASELINE.WIDELY and BASELINE.NEWLY as alternatives to the 'widely' and 'newly' strings.
Last updated on