Skip to content

Commit 1e93ceb

Browse files
committed
refactor(linter/no-unwanted-polyfillio): move NEXT_POLYFILLED_FEATURES to shared utils (#14793)
1 parent 10182e8 commit 1e93ceb

File tree

2 files changed

+68
-68
lines changed

2 files changed

+68
-68
lines changed

crates/oxc_linter/src/rules/nextjs/no_unwanted_polyfillio.rs

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use oxc_span::Span;
1111
use crate::{
1212
context::LintContext,
1313
rule::Rule,
14-
utils::{find_url_query_value, get_next_script_import_local_name},
14+
utils::{NEXT_POLYFILLED_FEATURES, find_url_query_value, get_next_script_import_local_name},
1515
};
1616

1717
fn no_unwanted_polyfillio_diagnostic(polyfill_name: &str, span: Span) -> OxcDiagnostic {
@@ -47,73 +47,6 @@ declare_oxc_lint!(
4747
correctness
4848
);
4949

50-
// 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
51-
const NEXT_POLYFILLED_FEATURES: phf::Set<&'static str> = phf::phf_set![
52-
"Array.from",
53-
"Array.of",
54-
"Array.prototype.@@iterator",
55-
"Array.prototype.at",
56-
"Array.prototype.copyWithin",
57-
"Array.prototype.fill",
58-
"Array.prototype.find",
59-
"Array.prototype.findIndex",
60-
"Array.prototype.flat",
61-
"Array.prototype.flatMap",
62-
"Array.prototype.includes",
63-
"Function.prototype.name",
64-
"Map",
65-
"Number.EPSILON",
66-
"Number.Epsilon",
67-
"Number.MAX_SAFE_INTEGER",
68-
"Number.MIN_SAFE_INTEGER",
69-
"Number.isFinite",
70-
"Number.isInteger",
71-
"Number.isNaN",
72-
"Number.isSafeInteger",
73-
"Number.parseFloat",
74-
"Number.parseInt",
75-
"Object.assign",
76-
"Object.entries",
77-
"Object.fromEntries",
78-
"Object.getOwnPropertyDescriptor",
79-
"Object.getOwnPropertyDescriptors",
80-
"Object.is",
81-
"Object.keys",
82-
"Object.values",
83-
"Promise",
84-
"Promise.prototype.finally",
85-
"Reflect",
86-
"Set",
87-
"String.fromCodePoint",
88-
"String.prototype.@@iterator",
89-
"String.prototype.codePointAt",
90-
"String.prototype.endsWith",
91-
"String.prototype.includes",
92-
"String.prototype.padEnd",
93-
"String.prototype.padStart",
94-
"String.prototype.repeat",
95-
"String.prototype.startsWith",
96-
"String.prototype.trimEnd",
97-
"String.prototype.trimStart",
98-
"String.raw",
99-
"Symbol",
100-
"Symbol.asyncIterator",
101-
"URL",
102-
"URL.prototype.toJSON",
103-
"URLSearchParams",
104-
"WeakMap",
105-
"WeakSet",
106-
"es2015", // Should be covered by babel-preset-env instead.
107-
"es2016", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
108-
"es2017", // contains polyfilled 'Object.entries', 'Object.getOwnPropertyDescriptors', 'Object.values', 'String.prototype.padEnd' and 'String.prototype.padStart'
109-
"es2018", // contains polyfilled 'Promise.prototype.finally' and ''Symbol.asyncIterator'
110-
"es2019", // Contains polyfilled 'Object.fromEntries' and polyfilled 'Array.prototype.flat', 'Array.prototype.flatMap', 'String.prototype.trimEnd' and 'String.prototype.trimStart'
111-
"es5", // Should be covered by babel-preset-env instead.
112-
"es6", // Should be covered by babel-preset-env instead.
113-
"es7", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'];
114-
"fetch",
115-
];
116-
11750
impl Rule for NoUnwantedPolyfillio {
11851
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
11952
let AstKind::JSXOpeningElement(jsx_el) = node.kind() else {

crates/oxc_linter/src/utils/nextjs.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
use crate::LintContext;
22

3+
// 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
4+
pub const NEXT_POLYFILLED_FEATURES: phf::Set<&'static str> = phf::phf_set![
5+
"Array.from",
6+
"Array.of",
7+
"Array.prototype.@@iterator",
8+
"Array.prototype.at",
9+
"Array.prototype.copyWithin",
10+
"Array.prototype.fill",
11+
"Array.prototype.find",
12+
"Array.prototype.findIndex",
13+
"Array.prototype.flat",
14+
"Array.prototype.flatMap",
15+
"Array.prototype.includes",
16+
"Function.prototype.name",
17+
"Map",
18+
"Number.EPSILON",
19+
"Number.Epsilon",
20+
"Number.MAX_SAFE_INTEGER",
21+
"Number.MIN_SAFE_INTEGER",
22+
"Number.isFinite",
23+
"Number.isInteger",
24+
"Number.isNaN",
25+
"Number.isSafeInteger",
26+
"Number.parseFloat",
27+
"Number.parseInt",
28+
"Object.assign",
29+
"Object.entries",
30+
"Object.fromEntries",
31+
"Object.getOwnPropertyDescriptor",
32+
"Object.getOwnPropertyDescriptors",
33+
"Object.is",
34+
"Object.keys",
35+
"Object.values",
36+
"Promise",
37+
"Promise.prototype.finally",
38+
"Reflect",
39+
"Set",
40+
"String.fromCodePoint",
41+
"String.prototype.@@iterator",
42+
"String.prototype.codePointAt",
43+
"String.prototype.endsWith",
44+
"String.prototype.includes",
45+
"String.prototype.padEnd",
46+
"String.prototype.padStart",
47+
"String.prototype.repeat",
48+
"String.prototype.startsWith",
49+
"String.prototype.trimEnd",
50+
"String.prototype.trimStart",
51+
"String.raw",
52+
"Symbol",
53+
"Symbol.asyncIterator",
54+
"URL",
55+
"URL.prototype.toJSON",
56+
"URLSearchParams",
57+
"WeakMap",
58+
"WeakSet",
59+
"es2015", // Should be covered by babel-preset-env instead.
60+
"es2016", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
61+
"es2017", // contains polyfilled 'Object.entries', 'Object.getOwnPropertyDescriptors', 'Object.values', 'String.prototype.padEnd' and 'String.prototype.padStart'
62+
"es2018", // contains polyfilled 'Promise.prototype.finally' and ''Symbol.asyncIterator'
63+
"es2019", // Contains polyfilled 'Object.fromEntries' and polyfilled 'Array.prototype.flat', 'Array.prototype.flatMap', 'String.prototype.trimEnd' and 'String.prototype.trimStart'
64+
"es5", // Should be covered by babel-preset-env instead.
65+
"es6", // Should be covered by babel-preset-env instead.
66+
"es7", // contains polyfilled 'Array.prototype.includes', 'String.prototype.padEnd' and 'String.prototype.padStart'
67+
"fetch",
68+
];
69+
370
pub fn is_in_app_dir(file_path: &str) -> bool {
471
file_path.contains("app/") || file_path.contains("app\\")
572
}

0 commit comments

Comments
 (0)