You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ha...@apache.org on 2026/08/15 07:21:44 UTC
(superset) branch master updated: fix(lint-metrics): record oxlint plugin rules under their canonical id (#43198)
This is an automated email from the ASF dual-hosted git repository.
hainenber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 7679c5641ab fix(lint-metrics): record oxlint plugin rules under their canonical id (#43198)
7679c5641ab is described below
commit 7679c5641ab6171425dc85cf2e783d20f5a67ff4
Author: Bikash <bi...@gmail.com>
AuthorDate: Sat Aug 15 12:51:38 2026 +0530
fix(lint-metrics): record oxlint plugin rules under their canonical id (#43198)
Co-authored-by: bikashJMV <bi...@jmv.co.in>
Co-authored-by: Claude Opus 5 (1M context) <no...@anthropic.com>
---
.../scripts/oxlint-metrics-uploader.js | 58 +++++++++++++++++-----
.../spec/scripts/oxlint-metrics-uploader.test.js | 58 ++++++++++++++++++++++
2 files changed, 103 insertions(+), 13 deletions(-)
diff --git a/superset-frontend/scripts/oxlint-metrics-uploader.js b/superset-frontend/scripts/oxlint-metrics-uploader.js
index 84e0859b07e..5b8008009cc 100644
--- a/superset-frontend/scripts/oxlint-metrics-uploader.js
+++ b/superset-frontend/scripts/oxlint-metrics-uploader.js
@@ -35,6 +35,43 @@ if (SERVICE_ACCOUNT_KEY.client_email) {
const DATETIME = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
+/**
+ * Turn an oxlint diagnostic code into the canonical rule id used by the metrics
+ * series.
+ *
+ * oxlint reports `<plugin>(<rule>)`, where the plugin is the linter the rule came
+ * from: `eslint(no-console)`, `react-hooks(exhaustive-deps)`, `react(jsx-key)`,
+ * `jest(no-conditional-expect)`, `oxc(erasing-op)`, and the legacy
+ * `eslint-plugin-unicorn(no-new-array)` spelling.
+ *
+ * `eslint` is the implicit namespace, so its rules keep their bare name and stay
+ * comparable with the rows recorded before the oxlint migration. Every other
+ * plugin becomes `<plugin>/<rule>`, which is the id those rules are known by in
+ * config and in the pre-migration history.
+ *
+ * @param {string | undefined} code the diagnostic's `code` field
+ * @returns {string} the rule id to record
+ */
+function parseRuleId(code) {
+ if (!code) {
+ return 'unknown';
+ }
+
+ const match = code.match(/^([\w-]+)\(([^)]+)\)$/);
+ if (!match) {
+ return code;
+ }
+
+ const [, namespace, rule] = match;
+ if (namespace === 'eslint') {
+ return rule;
+ }
+
+ // `eslint-plugin-unicorn(...)` is the same rule as `unicorn/...`
+ const plugin = namespace.replace(/^eslint-plugin-/, '');
+ return `${plugin}/${rule}`;
+}
+
async function writeToGoogleSheet(data, range, headers, append = false) {
if (!sheets) {
console.log('No Google Sheets credentials, skipping upload');
@@ -101,17 +138,7 @@ async function runOxlintAndProcess() {
// OXC JSON format has diagnostics array
if (results.diagnostics && Array.isArray(results.diagnostics)) {
results.diagnostics.forEach(diagnostic => {
- // Extract rule ID from code like "eslint(no-unused-vars)" or "eslint-plugin-unicorn(no-new-array)"
- const codeMatch = diagnostic.code?.match(
- /^(?:eslint(?:-plugin-(\w+))?\()([^)]+)\)$/,
- );
- let ruleId = diagnostic.code || 'unknown';
-
- if (codeMatch) {
- const plugin = codeMatch[1];
- const rule = codeMatch[2];
- ruleId = plugin ? `${plugin}/${rule}` : rule;
- }
+ const ruleId = parseRuleId(diagnostic.code);
const file = diagnostic.filename || 'unknown';
const line = diagnostic.labels?.[0]?.span?.line || 0;
@@ -251,5 +278,10 @@ async function runOxlintAndProcess() {
}
}
-// Run the process
-runOxlintAndProcess().catch(console.error);
+// Run the process, unless this file was imported (e.g. by a test) rather than
+// executed, in which case nothing should be linted or uploaded on import.
+if (require.main === module) {
+ runOxlintAndProcess().catch(console.error);
+}
+
+module.exports = { parseRuleId };
diff --git a/superset-frontend/spec/scripts/oxlint-metrics-uploader.test.js b/superset-frontend/spec/scripts/oxlint-metrics-uploader.test.js
new file mode 100644
index 00000000000..0a8426b6613
--- /dev/null
+++ b/superset-frontend/spec/scripts/oxlint-metrics-uploader.test.js
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+const { parseRuleId } = require('../../scripts/oxlint-metrics-uploader');
+
+test('eslint rules keep their bare name', () => {
+ expect(parseRuleId('eslint(no-console)')).toBe('no-console');
+ expect(parseRuleId('eslint(prefer-destructuring)')).toBe(
+ 'prefer-destructuring',
+ );
+});
+
+test('plugin rules are recorded under plugin/rule (#42981)', () => {
+ // These are the codes oxlint actually emits. They previously fell through to
+ // the raw `react-hooks(exhaustive-deps)` string, so the rows no longer lined
+ // up with the ids the same rules were recorded under before the migration.
+ expect(parseRuleId('react-hooks(exhaustive-deps)')).toBe(
+ 'react-hooks/exhaustive-deps',
+ );
+ expect(parseRuleId('react-hooks(rules-of-hooks)')).toBe(
+ 'react-hooks/rules-of-hooks',
+ );
+ expect(parseRuleId('react(jsx-key)')).toBe('react/jsx-key');
+ expect(parseRuleId('jest(no-conditional-expect)')).toBe(
+ 'jest/no-conditional-expect',
+ );
+ expect(parseRuleId('oxc(erasing-op)')).toBe('oxc/erasing-op');
+ expect(parseRuleId('typescript(no-explicit-any)')).toBe(
+ 'typescript/no-explicit-any',
+ );
+});
+
+test('the legacy eslint-plugin- prefix still collapses to the plugin name', () => {
+ expect(parseRuleId('eslint-plugin-unicorn(no-new-array)')).toBe(
+ 'unicorn/no-new-array',
+ );
+});
+
+test('an unrecognized or missing code is passed through rather than dropped', () => {
+ expect(parseRuleId('something-unparseable')).toBe('something-unparseable');
+ expect(parseRuleId(undefined)).toBe('unknown');
+ expect(parseRuleId('')).toBe('unknown');
+});