diff --git a/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js b/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js index f874fba64266..7fc24d756e92 100644 --- a/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js +++ b/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', @@ -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', @@ -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' diff --git a/packages/next-polyfill-nomodule/src/index.js b/packages/next-polyfill-nomodule/src/index.js index df37098a1fff..740973850bfb 100644 --- a/packages/next-polyfill-nomodule/src/index.js +++ b/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' diff --git a/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts b/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts index 5cf18a170023..7283183736c4 100644 --- a/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts +++ b/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts @@ -111,5 +111,25 @@ ruleTester.run('unwanted-polyfillsio', rule, { }, ], }, + { + code: `import {Head} from 'next/document'; + + export class ES2019Features extends Head { + render() { + return ( +
+

Hello title

+ +
+ ); + } + }`, + 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', + }, + ], + }, ], })