Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

Avoid importing polyfill packages for features that are already available as built-ins in your target environments. Keeping unused polyfills in a project adds bundle weight and maintenance overhead without any benefit.
Recommendedrecommended · ☑️ unopinionated
The rule reads your target environments from the targets option or, if that is not set, from the browserslist or engines field in the nearest package.json. It then cross-references imported module names against the core-js compatibility data to detect polyfills whose features are fully supported by all targets.
This rule requires either a targets option or a browserslist/engines field in package.json. Without target information the rule does nothing.

Examples

// package.json engines: { "node": ">=8" }
// Object.assign is built-in since Node 4 — polyfill is unnecessary
import assign from 'object-assign';

// core-js polyfill for a feature your targets already support
import 'core-js/features/array/flat';

Options

Type: object

targets

Type: string | string[] | object The target environments to check against. Accepts any value supported by the core-js-compat targets option: a Browserslist query string, an array of query strings, or a targets object. When omitted, the rule falls back to the browserslist field in package.json, then the engines field.
// Browserslist query string
"unicorn/no-unnecessary-polyfills": ["error", { "targets": "node >=12" }]

// Array of queries
"unicorn/no-unnecessary-polyfills": [
  "error",
  { "targets": ["node 14.1.0", "chrome 95"] }
]

// Targets object
"unicorn/no-unnecessary-polyfills": [
  "error",
  { "targets": { "node": "current", "firefox": "15" } }
]
Prefer setting browserslist or engines in package.json rather than repeating the targets in your ESLint config. That way the same targets drive both your linter and your bundler/transpiler.

Build docs developers (and LLMs) love