From 58777525869dd371a23c161b75e095d0da4a8381 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 24 Nov 2025 12:06:00 +0000 Subject: [PATCH] ci(lint): enable `no-console` rule (#16053) Enable `no-console` rule in our linting setup. Add `oxlint-disable` comments where we do want to log (in scripts). --- .github/scripts/check-conformance-changes.js | 2 ++ .github/scripts/generate-benchmark-matrix.js | 2 ++ .github/scripts/get-changed-files.js | 2 ++ .github/scripts/utils.js | 2 ++ apps/oxfmt/scripts/build.js | 2 ++ apps/oxlint/scripts/build.ts | 2 ++ crates/oxc_traverse/scripts/build.mjs | 1 + napi/parser/example.js | 2 +- napi/parser/scripts/visitor-keys.js | 1 + npm/oxfmt/scripts/generate-packages.js | 2 ++ npm/oxlint/scripts/generate-packages.js | 2 ++ oxlintrc.json | 3 +++ tasks/lint_rules/src/main.mjs | 2 ++ tasks/lint_rules/src/oxlint-rules.mjs | 8 ++++++-- tasks/transform_conformance/reporter.mjs | 2 ++ 15 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/scripts/check-conformance-changes.js b/.github/scripts/check-conformance-changes.js index d38cbb4316691..3570441efa7ee 100644 --- a/.github/scripts/check-conformance-changes.js +++ b/.github/scripts/check-conformance-changes.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +// oxlint-disable no-console + /** * Check if conformance tests should run based on changed files. * Uses cargo tree to determine dependencies of oxc_coverage crate. diff --git a/.github/scripts/generate-benchmark-matrix.js b/.github/scripts/generate-benchmark-matrix.js index 2591787c32339..4600c5746d6a5 100755 --- a/.github/scripts/generate-benchmark-matrix.js +++ b/.github/scripts/generate-benchmark-matrix.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +// oxlint-disable no-console + /** * Generate a dynamic matrix for benchmark jobs based on affected components. * This script determines which benchmark components need to run based on changed files. diff --git a/.github/scripts/get-changed-files.js b/.github/scripts/get-changed-files.js index 24ba10b4180a4..ec53352b0f6c9 100644 --- a/.github/scripts/get-changed-files.js +++ b/.github/scripts/get-changed-files.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +// oxlint-disable no-console + /** * Get changed files from GitHub events (pull request or push). * This module provides a reusable function for detecting changed files. diff --git a/.github/scripts/utils.js b/.github/scripts/utils.js index ae91051be0e26..d28acf3a28dbe 100644 --- a/.github/scripts/utils.js +++ b/.github/scripts/utils.js @@ -2,6 +2,8 @@ * Common utilities for GitHub Actions scripts */ +// oxlint-disable no-console + const { execSync } = require('child_process'); /** diff --git a/apps/oxfmt/scripts/build.js b/apps/oxfmt/scripts/build.js index 7dde18c8896af..b01e3e7b4fd86 100644 --- a/apps/oxfmt/scripts/build.js +++ b/apps/oxfmt/scripts/build.js @@ -1,3 +1,5 @@ +// oxlint-disable no-console + import { execSync } from 'node:child_process'; import { copyFileSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; diff --git a/apps/oxlint/scripts/build.ts b/apps/oxlint/scripts/build.ts index 3dd3dab68754b..aec7fb5021e07 100755 --- a/apps/oxlint/scripts/build.ts +++ b/apps/oxlint/scripts/build.ts @@ -1,3 +1,5 @@ +// oxlint-disable no-console + import { execSync } from 'node:child_process'; import { copyFileSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; diff --git a/crates/oxc_traverse/scripts/build.mjs b/crates/oxc_traverse/scripts/build.mjs index b786186516b98..9568e603b94fc 100644 --- a/crates/oxc_traverse/scripts/build.mjs +++ b/crates/oxc_traverse/scripts/build.mjs @@ -44,6 +44,7 @@ await Promise.all([ async function writeToFile(filename, code) { code = `${PREAMBLE}${code}`; const path = pathJoin(outputDirPath, filename); + // oxlint-disable-next-line no-console console.log('Writing:', path); await writeFile(path, code); await execAsync(`rustfmt ${JSON.stringify(path)}`); diff --git a/napi/parser/example.js b/napi/parser/example.js index a832738e715a2..398954e5d5b6a 100644 --- a/napi/parser/example.js +++ b/napi/parser/example.js @@ -25,5 +25,5 @@ const file = args.positionals[0] ?? 'test.js'; const code = fs.readFileSync(file, 'utf-8'); const result = parseSync(file, code, args.values); -// oxlint-disable-next-line typescript-eslint/no-misused-spread +// oxlint-disable-next-line no-console, typescript-eslint/no-misused-spread console.dir({ ...result }, { depth: Infinity }); diff --git a/napi/parser/scripts/visitor-keys.js b/napi/parser/scripts/visitor-keys.js index fde0ed9fcf9ff..bfbba1a24ce33 100644 --- a/napi/parser/scripts/visitor-keys.js +++ b/napi/parser/scripts/visitor-keys.js @@ -1,4 +1,5 @@ import { visitorKeys } from '@typescript-eslint/visitor-keys'; const keys = Object.entries(visitorKeys).map(([name, keys]) => ({ name, keys })); +// oxlint-disable-next-line no-console console.log(JSON.stringify(keys)); diff --git a/npm/oxfmt/scripts/generate-packages.js b/npm/oxfmt/scripts/generate-packages.js index 286d36ac03fc3..dad898f3f7f07 100644 --- a/npm/oxfmt/scripts/generate-packages.js +++ b/npm/oxfmt/scripts/generate-packages.js @@ -1,5 +1,7 @@ // Code copied from [Rome](https://github.com/rome/tools/blob/lsp/v0.28.0/npm/rome/scripts/generate-packages.mjs) +// oxlint-disable no-console + import * as fs from 'node:fs'; import { resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; diff --git a/npm/oxlint/scripts/generate-packages.js b/npm/oxlint/scripts/generate-packages.js index c239252179e9f..2e3127212ec72 100644 --- a/npm/oxlint/scripts/generate-packages.js +++ b/npm/oxlint/scripts/generate-packages.js @@ -1,5 +1,7 @@ // Code copied from [Rome](https://github.com/rome/tools/blob/lsp/v0.28.0/npm/rome/scripts/generate-packages.mjs) +// oxlint-disable no-console + import * as fs from 'node:fs'; import { resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; diff --git a/oxlintrc.json b/oxlintrc.json index 981e45562788f..1200b16709867 100644 --- a/oxlintrc.json +++ b/oxlintrc.json @@ -16,6 +16,9 @@ "correctness": "error", "perf": "error" }, + "rules": { + "no-console": "error" + }, "overrides": [ { "files": ["**/editors/vscode/tests/*.spec.ts"], diff --git a/tasks/lint_rules/src/main.mjs b/tasks/lint_rules/src/main.mjs index 30de74eae8ef6..2733c3d03d46e 100644 --- a/tasks/lint_rules/src/main.mjs +++ b/tasks/lint_rules/src/main.mjs @@ -1,3 +1,5 @@ +// oxlint-disable no-console + import { parseArgs } from 'node:util'; import { ALL_TARGET_PLUGINS, createESLintLinter, loadTargetPluginRules } from './eslint-rules.mjs'; import { renderMarkdown } from './markdown-renderer.mjs'; diff --git a/tasks/lint_rules/src/oxlint-rules.mjs b/tasks/lint_rules/src/oxlint-rules.mjs index 2eb83d7763847..5dc2c955f1c04 100644 --- a/tasks/lint_rules/src/oxlint-rules.mjs +++ b/tasks/lint_rules/src/oxlint-rules.mjs @@ -345,8 +345,12 @@ 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 { + // oxlint-disable-next-line no-console + console.log(`👀 ${name} is implemented but not found in their rules`); + } } }; diff --git a/tasks/transform_conformance/reporter.mjs b/tasks/transform_conformance/reporter.mjs index b94fc5c78c4fe..0fedb8d464f9a 100644 --- a/tasks/transform_conformance/reporter.mjs +++ b/tasks/transform_conformance/reporter.mjs @@ -1,3 +1,5 @@ +// oxlint-disable no-console + import { join as pathJoin } from 'path'; import { JsonReporter } from 'vitest/reporters';