Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unnecessary-polyfills false positive for regexp.escape #2584

Open
kevinoid opened this issue Mar 2, 2025 · 0 comments
Open

no-unnecessary-polyfills false positive for regexp.escape #2584

kevinoid opened this issue Mar 2, 2025 · 0 comments
Labels

Comments

@kevinoid
Copy link

kevinoid commented Mar 2, 2025

The unicorn/no-unnecessary-polyfills rule is triggered by importing regexp.escape in a package with engines.node: ">=18". I believe this is a false-positive since RegExp.escape() is not supported by any version of Node.js (also confirmed by the core-js compat table).

Full reproduction:

npm init -y
npm pkg set type=module
npm pkg set engines.node=">=18"
npm install -D eslint eslint-plugin-unicorn
echo "import eslintPluginUnicorn from 'eslint-plugin-unicorn';
export default [eslintPluginUnicorn.configs.recommended];" >eslint.config.js
npm install regexp.escape
echo "import regexpEscape from 'regexp.escape';" >index.js
./node_modules/.bin/eslint .

I've bisected the regression to zloirock/core-js@7321cc1 ([email protected]) which added the feature es.regexp.escape.

The crux of the issue appears to be that coreJsCompat.entries['core-js/full/regexp/escape'] is ['es.regexp.escape', 'esnext.regexp.escape'] while coreJsCompat({ node: '>=18' }).list contains 'es.regexp.escape' but not 'esnext.regexp.escape', causing checkFeatures() to return true at

if (checkFeatures(features)) {

Thanks,
Kevin

@kevinoid kevinoid added the bug label Mar 2, 2025
kevinoid added a commit to kevinoid/swagger-spec-validator that referenced this issue Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant