Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 1 addition & 68 deletions crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
67 changes: 67 additions & 0 deletions crates/oxc_linter/src/utils/nextjs.rs
Original file line number Diff line number Diff line change
@@ -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\\")
}
Expand Down
Loading