From 6b7fa68d14ae68911ea4451616516916b50b3f70 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Tue, 11 Jan 2022 07:14:08 +0100 Subject: [PATCH 1/2] Update polyfill for eslint no-unwanted-polyfillio rule --- .../lib/rules/no-unwanted-polyfillio.js | 16 ++++++++++------ packages/next-polyfill-nomodule/src/index.js | 1 + .../no-unwanted-polyfillio.test.ts | 12 ++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) 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 891903d18977..40f373136026 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,6 +21,9 @@ const NEXT_POLYFILLED_FEATURES = [ 'Number.isSafeInteger', 'Number.MAX_SAFE_INTEGER', 'Number.MIN_SAFE_INTEGER', + 'Number.parseFloat', + 'Number.parseInt', + 'Object.assign', 'Object.entries', 'Object.getOwnPropertyDescriptor', 'Object.getOwnPropertyDescriptors', @@ -42,21 +46,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 unpolyfilled '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' ] //------------------------------------------------------------------------------ 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..475249285787 100644 --- a/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts +++ b/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts @@ -48,6 +48,18 @@ ruleTester.run('unwanted-polyfillsio', rule, { ); }`, + `import {Head} from 'next/document'; + + export class ES2019Features extends Head { + render() { + return ( +
+

Hello title

+ +
+ ); + } + }`, ], invalid: [ From d38d03d402b2996681fc4caa76ba9fe34a1e6738 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 8 Aug 2022 00:14:47 -0500 Subject: [PATCH 2/2] update test --- .../lib/rules/no-unwanted-polyfillio.js | 3 +- .../no-unwanted-polyfillio.test.ts | 32 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) 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 3694fda190be..7fc24d756e92 100644 --- a/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js +++ b/packages/eslint-plugin-next/lib/rules/no-unwanted-polyfillio.js @@ -25,6 +25,7 @@ const NEXT_POLYFILLED_FEATURES = [ 'Number.parseInt', 'Object.assign', 'Object.entries', + 'Object.fromEntries', 'Object.getOwnPropertyDescriptor', 'Object.getOwnPropertyDescriptors', 'Object.is', @@ -57,7 +58,7 @@ const NEXT_POLYFILLED_FEATURES = [ '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 unpolyfilled 'Object.fromEntries' and polyfilled 'Array.prototype.flat', 'Array.prototype.flatMap', 'String.prototype.trimEnd' and 'String.prototype.trimStart' + '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', // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart' 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 475249285787..7283183736c4 100644 --- a/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts +++ b/test/unit/eslint-plugin-next/no-unwanted-polyfillio.test.ts @@ -48,18 +48,6 @@ ruleTester.run('unwanted-polyfillsio', rule, { ); }`, - `import {Head} from 'next/document'; - - export class ES2019Features extends Head { - render() { - return ( -
-

Hello title

- -
- ); - } - }`, ], invalid: [ @@ -123,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', + }, + ], + }, ], })