diff --git a/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs b/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs index a45c0d0bab485..3ba04dfd7111f 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs @@ -11,7 +11,7 @@ use oxc_span::Span; use crate::{ context::LintContext, rule::Rule, - utils::{find_url_query_value, get_next_script_import_local_name}, + utils::{NEXT_POLYFILLED_FEATURES, find_url_query_value, get_next_script_import_local_name}, }; fn no_unwanted_polyfillio_diagnostic(polyfill_name: &str, span: Span) -> OxcDiagnostic { @@ -47,73 +47,6 @@ declare_oxc_lint!( correctness ); -// Keep in sync with next.js polyfills file : https://github.com/vercel/next.js/blob/v15.0.2/packages/next-polyfill-nomodule/src/index.js -const NEXT_POLYFILLED_FEATURES: phf::Set<&'static str> = phf::phf_set![ - "Array.from", - "Array.of", - "Array.prototype.@@iterator", - "Array.prototype.at", - "Array.prototype.copyWithin", - "Array.prototype.fill", - "Array.prototype.find", - "Array.prototype.findIndex", - "Array.prototype.flat", - "Array.prototype.flatMap", - "Array.prototype.includes", - "Function.prototype.name", - "Map", - "Number.EPSILON", - "Number.Epsilon", - "Number.MAX_SAFE_INTEGER", - "Number.MIN_SAFE_INTEGER", - "Number.isFinite", - "Number.isInteger", - "Number.isNaN", - "Number.isSafeInteger", - "Number.parseFloat", - "Number.parseInt", - "Object.assign", - "Object.entries", - "Object.fromEntries", - "Object.getOwnPropertyDescriptor", - "Object.getOwnPropertyDescriptors", - "Object.is", - "Object.keys", - "Object.values", - "Promise", - "Promise.prototype.finally", - "Reflect", - "Set", - "String.fromCodePoint", - "String.prototype.@@iterator", - "String.prototype.codePointAt", - "String.prototype.endsWith", - "String.prototype.includes", - "String.prototype.padEnd", - "String.prototype.padStart", - "String.prototype.repeat", - "String.prototype.startsWith", - "String.prototype.trimEnd", - "String.prototype.trimStart", - "String.raw", - "Symbol", - "Symbol.asyncIterator", - "URL", - "URL.prototype.toJSON", - "URLSearchParams", - "WeakMap", - "WeakSet", - "es2015", // 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", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart']; - "fetch", -]; - impl Rule for NoUnwantedPolyfillio { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { let AstKind::JSXOpeningElement(jsx_el) = node.kind() else { diff --git a/crates/oxc_linter/src/utils/nextjs.rs b/crates/oxc_linter/src/utils/nextjs.rs index ac5983e5bdd15..5446845ec84ad 100644 --- a/crates/oxc_linter/src/utils/nextjs.rs +++ b/crates/oxc_linter/src/utils/nextjs.rs @@ -1,5 +1,72 @@ use crate::LintContext; +// Keep in sync with next.js polyfills file : https://github.com/vercel/next.js/blob/v15.0.2/packages/next-polyfill-nomodule/src/index.js +pub const NEXT_POLYFILLED_FEATURES: phf::Set<&'static str> = phf::phf_set![ + "Array.from", + "Array.of", + "Array.prototype.@@iterator", + "Array.prototype.at", + "Array.prototype.copyWithin", + "Array.prototype.fill", + "Array.prototype.find", + "Array.prototype.findIndex", + "Array.prototype.flat", + "Array.prototype.flatMap", + "Array.prototype.includes", + "Function.prototype.name", + "Map", + "Number.EPSILON", + "Number.Epsilon", + "Number.MAX_SAFE_INTEGER", + "Number.MIN_SAFE_INTEGER", + "Number.isFinite", + "Number.isInteger", + "Number.isNaN", + "Number.isSafeInteger", + "Number.parseFloat", + "Number.parseInt", + "Object.assign", + "Object.entries", + "Object.fromEntries", + "Object.getOwnPropertyDescriptor", + "Object.getOwnPropertyDescriptors", + "Object.is", + "Object.keys", + "Object.values", + "Promise", + "Promise.prototype.finally", + "Reflect", + "Set", + "String.fromCodePoint", + "String.prototype.@@iterator", + "String.prototype.codePointAt", + "String.prototype.endsWith", + "String.prototype.includes", + "String.prototype.padEnd", + "String.prototype.padStart", + "String.prototype.repeat", + "String.prototype.startsWith", + "String.prototype.trimEnd", + "String.prototype.trimStart", + "String.raw", + "Symbol", + "Symbol.asyncIterator", + "URL", + "URL.prototype.toJSON", + "URLSearchParams", + "WeakMap", + "WeakSet", + "es2015", // 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", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart' + "fetch", +]; + pub fn is_in_app_dir(file_path: &str) -> bool { file_path.contains("app/") || file_path.contains("app\\") }