From d808547ce63367f570e1778841020d2d0b5caa83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 14:04:37 +0000 Subject: [PATCH 1/3] Initial plan From 163c0ddab1e34782092a099129db5ede602a3730 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 14:10:54 +0000 Subject: [PATCH 2/3] Initial investigation: identified lint errors to fix in tasks/lint_rules/src files Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com> --- oxlintrc.json.backup | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 oxlintrc.json.backup diff --git a/oxlintrc.json.backup b/oxlintrc.json.backup new file mode 100644 index 0000000000000..7659b21a38d68 --- /dev/null +++ b/oxlintrc.json.backup @@ -0,0 +1,31 @@ +{ + "$schema": "./node_modules/oxlint/configuration_schema.json", + "plugins": [ + "typescript", + "unicorn", + "react", + "react-perf", + "oxc", + "import", + "jsdoc", + "node", + "promise", + "vitest" + ], + "categories": { + "correctness": "error", + "perf": "error" + }, + "ignorePatterns": [ + "**/fixtures/**", + "**/generated/**", + "npm/runtime/**", + "tasks/coverage/**", + "crates/oxc_semantic/tests/**", + "tasks/e2e/**", // TODO + "napi/**", // TODO + "editors/vscode/tests/**", // TODO, + "tasks/lint_rules/src/oxlint-rules.mjs", // TODO + "tasks/lint_rules/src/main.mjs" // TODO + ] +} From 9e9805a6ae5ceaa4cbf743ddef2f90300f650e29 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 14:22:49 +0000 Subject: [PATCH 3/3] Fixed lint errors and removed ignore patterns for tasks/lint_rules/src files Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com> --- .../rust/document_symbols_cache_v23-06-25.pkl | Bin 0 -> 1093 bytes oxlintrc.json | 3 +- oxlintrc.json.backup | 31 -------- tasks/lint_rules/src/main.mjs | 32 ++++++--- tasks/lint_rules/src/oxlint-rules.mjs | 67 ++++++++++-------- tasks/lint_rules/src/result-reporter.mjs | 14 ++-- 6 files changed, 70 insertions(+), 77 deletions(-) create mode 100644 .serena/cache/rust/document_symbols_cache_v23-06-25.pkl delete mode 100644 oxlintrc.json.backup diff --git a/.serena/cache/rust/document_symbols_cache_v23-06-25.pkl b/.serena/cache/rust/document_symbols_cache_v23-06-25.pkl new file mode 100644 index 0000000000000000000000000000000000000000..55d0561b1dad4931858310fc8677b45e5b6d541e GIT binary patch literal 1093 zcmcJO&ubGw6vxF(>>88UQbk0mML}|DCTVS(^w2{OYFQ8wJO-KFed*g~vK!`ydMS7+ z6z2H+e|;O8mKKB_(uIY2v)}p7`+gq#NBlhy59ZGqg|1U}Vx`Ut_rrJ%R$7xv1J-M| zWnfks2c|ncwOb#Rwm@OC-ybI*vShC}?5UmM-af!^e~=7zcgN7rV6aUi>YPz0h(b+S zzvgF|a_}j4pM7#{t>-;4$%~BQb`VaTSUwOM8O#i%EX?R4)Qu`mfGU@|b;`K;QgD+% zu?UY-R7R!T7{x0-)PT)ci%(;LtMQ@tp>07!>hiMqws6AMwWQ^7?Yi3F1CcKIa@Nmp zs(F)BI3DL34y2S=PC*)96kz19(oAIeJDtCGWk-ud*bGgT*iw53UzI}&N6T<;8qnPR z&r8qFo%`b8DdsveP*hWRG*i5C^uLJRjd3`sUa3yYIG$L$V;FId(CCxeme|SZ+ zs-Ag|>$eoq4aF)eUQ~*g%S4Q?@IAg>3Qyd?Hy$@R?b`*38vhahg%ELUaTT$up5KB{ c?KN&FTK5HE=RP37h{q-H9roay&dGNF0odk?p#T5? literal 0 HcmV?d00001 diff --git a/oxlintrc.json b/oxlintrc.json index 7659b21a38d68..b648fb6956852 100644 --- a/oxlintrc.json +++ b/oxlintrc.json @@ -25,7 +25,6 @@ "tasks/e2e/**", // TODO "napi/**", // TODO "editors/vscode/tests/**", // TODO, - "tasks/lint_rules/src/oxlint-rules.mjs", // TODO - "tasks/lint_rules/src/main.mjs" // TODO + ] } diff --git a/oxlintrc.json.backup b/oxlintrc.json.backup deleted file mode 100644 index 7659b21a38d68..0000000000000 --- a/oxlintrc.json.backup +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "./node_modules/oxlint/configuration_schema.json", - "plugins": [ - "typescript", - "unicorn", - "react", - "react-perf", - "oxc", - "import", - "jsdoc", - "node", - "promise", - "vitest" - ], - "categories": { - "correctness": "error", - "perf": "error" - }, - "ignorePatterns": [ - "**/fixtures/**", - "**/generated/**", - "npm/runtime/**", - "tasks/coverage/**", - "crates/oxc_semantic/tests/**", - "tasks/e2e/**", // TODO - "napi/**", // TODO - "editors/vscode/tests/**", // TODO, - "tasks/lint_rules/src/oxlint-rules.mjs", // TODO - "tasks/lint_rules/src/main.mjs" // TODO - ] -} diff --git a/tasks/lint_rules/src/main.mjs b/tasks/lint_rules/src/main.mjs index ef424a4252704..d10623ef1d0cd 100644 --- a/tasks/lint_rules/src/main.mjs +++ b/tasks/lint_rules/src/main.mjs @@ -1,6 +1,11 @@ import { parseArgs } from 'node:util'; -import { ALL_TARGET_PLUGINS, createESLintLinter, loadTargetPluginRules } from './eslint-rules.mjs'; import { renderMarkdown } from './markdown-renderer.mjs'; +import { updateGitHubIssue } from './result-reporter.mjs'; +import { + ALL_TARGET_PLUGINS, + createESLintLinter, + loadTargetPluginRules, +} from './eslint-rules.mjs'; import { createRuleEntries, overrideTypeScriptPluginStatusWithEslintPluginStatus as syncTypeScriptPluginStatusWithEslintPluginStatus, @@ -9,7 +14,6 @@ import { updateImplementedStatus, updateNotSupportedStatus, } from './oxlint-rules.mjs'; -import { updateGitHubIssue } from './result-reporter.mjs'; const HELP = ` Usage: @@ -20,7 +24,7 @@ Options: --update: Update the issue instead of printing to stdout --help, -h: Print this help message -Plugins: ${Array.from(ALL_TARGET_PLUGINS.keys()).join(', ')} +Plugins: ${[...ALL_TARGET_PLUGINS.keys()].join(', ')} `; (async () => { @@ -30,13 +34,15 @@ Plugins: ${Array.from(ALL_TARGET_PLUGINS.keys()).join(', ')} const { values } = parseArgs({ options: { // Mainly for debugging - target: { type: 'string', short: 't', multiple: true }, + help: { short: 'h', type: 'boolean' }, + target: { multiple: true, short: 't', type: 'string' }, update: { type: 'boolean' }, - help: { type: 'boolean', short: 'h' }, }, }); - if (values.help) return console.log(HELP); + if (values.help) { + return console.log(HELP); + } const targetPluginNames = new Set(values.target ?? ALL_TARGET_PLUGINS.keys()); for (const pluginName of targetPluginNames) { @@ -66,19 +72,25 @@ Plugins: ${Array.from(ALL_TARGET_PLUGINS.keys()).join(', ')} // Render list and update if necessary // const results = await Promise.allSettled( - Array.from(targetPluginNames).map((pluginName) => { + [...targetPluginNames].map((pluginName) => { const pluginMeta = /** @type {import("./eslint-rules.mjs").TargetPluginMeta} */ ( ALL_TARGET_PLUGINS.get(pluginName) ); const content = renderMarkdown(pluginName, pluginMeta, ruleEntries); - if (!values.update) return Promise.resolve(content); + if (!values.update) { + return Promise.resolve(content); + } // Requires `env.GITHUB_TOKEN` return updateGitHubIssue(pluginMeta, content); }), ); for (const result of results) { - if (result.status === 'fulfilled') console.log(result.value); - if (result.status === 'rejected') console.error(result.reason); + if (result.status === 'fulfilled') { + console.log(result.value); + } + if (result.status === 'rejected') { + console.error(result.reason); + } } })(); diff --git a/tasks/lint_rules/src/oxlint-rules.mjs b/tasks/lint_rules/src/oxlint-rules.mjs index 4a7a05f824fdf..46f6f11c7becc 100644 --- a/tasks/lint_rules/src/oxlint-rules.mjs +++ b/tasks/lint_rules/src/oxlint-rules.mjs @@ -15,29 +15,26 @@ const readAllImplementedRuleNames = async () => { line = line.trim(); // Skip commented out rules - if (line.startsWith('//')) continue; - - if (line === 'oxc_macros::declare_all_lint_rules! {') { - found = true; - continue; - } - if (found && line === '}') { - return rules; - } - - if (found) { - let prefixedName = line - .replaceAll(',', '') - .replaceAll('::', '/') - .replaceAll('_', '-'); - - // Ignore no reference rules - if (prefixedName.startsWith('oxc/')) continue; - if (prefixedName.startsWith('node/')) { - prefixedName = prefixedName.replace(/^node/, 'n'); + if (!line.startsWith('//')) { + if (line === 'oxc_macros::declare_all_lint_rules! {') { + found = true; + } else if (found && line === '}') { + return rules; + } else if (found) { + let prefixedName = line + .replaceAll(',', '') + .replaceAll('::', '/') + .replaceAll('_', '-'); + + // Ignore no reference rules + if (!prefixedName.startsWith('oxc/')) { + if (prefixedName.startsWith('node/')) { + prefixedName = prefixedName.replace(/^node/, 'n'); + } + + rules.add(prefixedName); + } } - - rules.add(prefixedName); } } @@ -243,7 +240,12 @@ export const createRuleEntries = (loadedAllRules) => { for (const [name, rule] of loadedAllRules) { // Default eslint rules are not prefixed - const prefixedName = name.includes('/') ? name : `eslint/${name}`; + let prefixedName = ''; + if (name.includes('/')) { + prefixedName = name; + } else { + prefixedName = `eslint/${name}`; + } const docsUrl = rule.meta?.docs?.url ?? ''; const isDeprecated = rule.meta?.deprecated ?? false; @@ -252,10 +254,10 @@ export const createRuleEntries = (loadedAllRules) => { rulesEntry.set(prefixedName, { docsUrl, isDeprecated: !!isDeprecated, - isRecommended, // Will be updated later isImplemented: false, isNotSupported: false, + isRecommended, }); } @@ -268,8 +270,11 @@ export const updateImplementedStatus = async (ruleEntries) => { for (const name of implementedRuleNames) { const rule = ruleEntries.get(name); - if (rule) rule.isImplemented = true; - else console.log(`👀 ${name} is implemented but not found in their rules`); + if (rule) { + rule.isImplemented = true; + } else { + console.log(`👀 ${name} is implemented but not found in their rules`); + } } }; @@ -277,7 +282,9 @@ export const updateImplementedStatus = async (ruleEntries) => { export const updateNotSupportedStatus = (ruleEntries) => { for (const name of NOT_SUPPORTED_RULE_NAMES) { const rule = ruleEntries.get(name); - if (rule) rule.isNotSupported = true; + if (rule) { + rule.isNotSupported = true; + } } }; @@ -296,7 +303,9 @@ const getArrayEntries = (constName, fileContent) => { // ``` const regSearch = new RegExp(`const ${constName}[^=]+= \\[([^\\]]+)`, 's'); - const vitestCompatibleRules = fileContent.match(regSearch)?.[1]; + const FIRST_CAPTURE_GROUP = 1; + const matchResult = fileContent.match(regSearch); + const vitestCompatibleRules = matchResult?.[FIRST_CAPTURE_GROUP]; if (!vitestCompatibleRules) { throw new Error('Failed to find the list of vitest-compatible rules'); } @@ -310,7 +319,7 @@ const getArrayEntries = (constName, fileContent) => { line .replace(/"/g, '') .split(',') - .filter((s) => s !== '') + .filter((str) => str !== '') ) .flat(), ); diff --git a/tasks/lint_rules/src/result-reporter.mjs b/tasks/lint_rules/src/result-reporter.mjs index cd5f6b3430818..d57ab8798a053 100644 --- a/tasks/lint_rules/src/result-reporter.mjs +++ b/tasks/lint_rules/src/result-reporter.mjs @@ -9,17 +9,21 @@ export const updateGitHubIssue = async ({ issueNo }, markdown) => { const res = await fetch( `https://api.github.com/repos/oxc-project/oxc/issues/${issueNo}`, { - method: 'PATCH', + Accept: 'application/vnd.github+json', + Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, + body: JSON.stringify({ body: markdown }), headers: { Accept: 'application/vnd.github+json', Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, }, - body: JSON.stringify({ body: markdown }), + method: 'PATCH', }, ); - if (!res.ok) throw new Error(res.statusText); - } catch (err) { - throw new Error(`Failed to update issue: ${issueUrl}`, { cause: err }); + if (!res.ok) { + throw new Error(res.statusText); + } + } catch (error) { + throw new Error(`Failed to update issue: ${issueUrl}`, { cause: error }); } return `✅ ${issueUrl} is successfully updated`;