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

Update polyfill for eslint no-unwanted-polyfillio rule #33170

Merged
merged 4 commits into from Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js
@@ -1,3 +1,4 @@
// Keep in sync with next.js polyfills file : https://github.com/vercel/next.js/blob/master/packages/next-polyfill-nomodule/src/index.js
const NEXT_POLYFILLED_FEATURES = [
'Array.prototype.@@iterator',
'Array.prototype.copyWithin',
Expand All @@ -20,7 +21,11 @@ const NEXT_POLYFILLED_FEATURES = [
'Number.isSafeInteger',
'Number.MAX_SAFE_INTEGER',
'Number.MIN_SAFE_INTEGER',
'Number.parseFloat',
'Number.parseInt',
'Object.assign',
'Object.entries',
'Object.fromEntries',
'Object.getOwnPropertyDescriptor',
'Object.getOwnPropertyDescriptors',
'Object.is',
Expand All @@ -42,21 +47,21 @@ const NEXT_POLYFILLED_FEATURES = [
'String.prototype.startsWith',
'String.prototype.trimEnd',
'String.prototype.trimStart',
'String.prototype.trim',
'URL',
'URL.prototype.toJSON',
'URLSearchParams',
'WeakMap',
'WeakSet',
'Promise',
'Promise.prototype.finally',
'es2015', // Should be covered by babel-preset-env instead.
'es2016', // Should be covered by babel-preset-env instead.
'es2017', // Should be covered by babel-preset-env instead.
'es2018', // Should be covered by babel-preset-env instead.
'es2019', // Should be covered by babel-preset-env instead.
'es2016', // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
'es2017', // contains polyfilled 'Object.entries', 'Object.getOwnPropertyDescriptors', 'Object.values', 'String.prototype.padEnd' and 'String.prototype.padStart'
'es2018', // contains polyfilled 'Promise.prototype.finally' and ''Symbol.asyncIterator'
'es2019', // Contains polyfilled 'Object.fromEntries' and polyfilled 'Array.prototype.flat', 'Array.prototype.flatMap', 'String.prototype.trimEnd' and 'String.prototype.trimStart'
'es5', // Should be covered by babel-preset-env instead.
'es6', // Should be covered by babel-preset-env instead.
'es7', // Should be covered by babel-preset-env instead.
'es7', // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
]

const url = 'https://nextjs.org/docs/messages/no-unwanted-polyfillio'
Expand Down
1 change: 1 addition & 0 deletions packages/next-polyfill-nomodule/src/index.js
@@ -1,4 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies */
// Keep in sync with eslint no-unwanted-polyfillio rule: https://github.com/vercel/next.js/blob/master/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js
import 'core-js/features/array/copy-within'
import 'core-js/features/array/fill'
import 'core-js/features/array/find'
Expand Down
20 changes: 20 additions & 0 deletions test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts
Expand Up @@ -111,5 +111,25 @@ ruleTester.run('unwanted-polyfillsio', rule, {
},
],
},
{
code: `import {Head} from 'next/document';

export class ES2019Features extends Head {
render() {
return (
<div>
<h1>Hello title</h1>
<script src='https://polyfill.io/v3/polyfill.min.js?features=Object.fromEntries'></script>
</div>
);
}
}`,
errors: [
{
message:
'No duplicate polyfills from Polyfill.io are allowed. Object.fromEntries is already shipped with Next.js. See: https://nextjs.org/docs/messages/no-unwanted-polyfillio',
},
],
},
],
})