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/09/12 09:16:19 UTC
(superset) 03/03: feat: replace eslint config for custom Superset lint rule with Oxlint equivalent
This is an automated email from the ASF dual-hosted git repository.
hainenber pushed a commit to branch feat/migrate-eslint-custom-rules-to-oxlint
in repository https://gitbox.apache.org/repos/asf/superset.git
commit f6e9e61723e9a5d3762cb0d6a4de7e90db216334
Author: hainenber <do...@gmail.com>
AuthorDate: Sat Sep 12 16:15:52 2026 +0700
feat: replace eslint config for custom Superset lint rule with Oxlint equivalent
Signed-off-by: hainenber <do...@gmail.com>
---
.../custom-lint-rules/i18n-strings/index.js | 8 +-
superset-frontend/custom-lint-rules/icons/index.js | 8 +-
.../custom-lint-rules/theme-colors/index.js | 7 +-
superset-frontend/eslint.config.minimal.js | 131 ------------------
superset-frontend/oxlint.custom-lint-rules.mts | 114 ++++++++++++++++
superset-frontend/oxlint.json | 20 +--
.../scripts/oxlint-metrics-uploader.js | 151 +++++++++------------
7 files changed, 200 insertions(+), 239 deletions(-)
diff --git a/superset-frontend/custom-lint-rules/i18n-strings/index.js b/superset-frontend/custom-lint-rules/i18n-strings/index.js
index 41c26aa5921..0fdf67ccdb1 100644
--- a/superset-frontend/custom-lint-rules/i18n-strings/index.js
+++ b/superset-frontend/custom-lint-rules/i18n-strings/index.js
@@ -26,12 +26,10 @@
// Rule Definition
//------------------------------------------------------------------------------
-import { eslintCompatPlugin } from '@oxlint/plugins';
-
/** @type {{ rules: Record<string, import('oxlint').Rule.RuleModule> }} */
-const plugin = eslintCompatPlugin({
+const plugin = {
meta: {
- name: '@superset-ui/i18n-strings',
+ name: 'i18n-strings',
},
rules: {
'no-template-vars': {
@@ -247,6 +245,6 @@ const plugin = eslintCompatPlugin({
},
},
},
-});
+};
export default plugin;
diff --git a/superset-frontend/custom-lint-rules/icons/index.js b/superset-frontend/custom-lint-rules/icons/index.js
index a0c6d9d2e5c..b22ce322a19 100644
--- a/superset-frontend/custom-lint-rules/icons/index.js
+++ b/superset-frontend/custom-lint-rules/icons/index.js
@@ -17,8 +17,6 @@
* under the License.
*/
-import { eslintCompatPlugin } from '@oxlint/plugins';
-
/**
* @fileoverview Rule to warn about direct imports from @ant-design/icons
* @author Apache
@@ -53,9 +51,9 @@ import { eslintCompatPlugin } from '@oxlint/plugins';
*/
/** @type {{ rules: Record<string, import('oxlint').Rule.RuleModule> }} */
-const plugin = eslintCompatPlugin({
+const plugin = {
meta: {
- name: '@superset-ui/icons',
+ name: 'icons',
},
rules: {
'no-fa-icons-usage': {
@@ -110,6 +108,6 @@ const plugin = eslintCompatPlugin({
},
},
},
-});
+};
export default plugin;
diff --git a/superset-frontend/custom-lint-rules/theme-colors/index.js b/superset-frontend/custom-lint-rules/theme-colors/index.js
index aad00e91b57..69d1bd0386a 100644
--- a/superset-frontend/custom-lint-rules/theme-colors/index.js
+++ b/superset-frontend/custom-lint-rules/theme-colors/index.js
@@ -22,7 +22,6 @@
* @author Apache
*/
-import { eslintCompatPlugin } from '@oxlint/plugins';
import { COLOR_KEYWORDS } from './colors.js';
/**
@@ -92,9 +91,9 @@ const WARNING_MESSAGE =
*/
/** @type {{ rules: Record<string, import('oxlint').Rule.RuleModule> }} */
-const plugin = eslintCompatPlugin({
+const plugin = {
meta: {
- name: '@superset-ui/theme-colors',
+ name: 'theme-colors',
},
rules: {
'no-literal-colors': {
@@ -195,6 +194,6 @@ const plugin = eslintCompatPlugin({
},
},
},
-});
+};
export default plugin;
diff --git a/superset-frontend/eslint.config.minimal.js b/superset-frontend/eslint.config.minimal.js
deleted file mode 100644
index f183d7dae70..00000000000
--- a/superset-frontend/eslint.config.minimal.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- * 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.
- */
-
-/**
- * MINIMAL ESLint flat config - ONLY for rules OXC doesn't support.
- *
- * This config is run alongside the OXC (oxlint) linter, which handles the
- * bulk of linting. ESLint here only covers the custom Superset plugins that
- * oxlint cannot express. It is consumed by
- * `scripts/oxlint-metrics-uploader.js` (`npm run lint-stats`).
- *
- * Migrated from the legacy `.eslintrc.minimal.js` (eslintrc) format to flat
- * config for ESLint v9+/v10, where eslintrc is no longer supported.
- *
- * Only covers:
- * - Custom Superset plugins (theme-colors, icons, i18n-strings)
- */
-
-// Register the TypeScript require hook so ESLint can load the .ts plugin files
-// from eslint-rules/*.
-require('tsx/cjs');
-
-const tsParser = require('@typescript-eslint/parser');
-const themeColorsPlugin = require('@superset-ui/eslint-plugin-theme-colors');
-const iconsPlugin = require('@superset-ui/eslint-plugin-icons');
-const i18nStringsPlugin = require('@superset-ui/eslint-plugin-i18n-strings');
-
-module.exports = [
- // Files this config applies to. Flat config has no `--ext`; globs live here.
- // Only check src/ files where the theme/icon/i18n rules matter.
- {
- ignores: [
- 'node_modules/**',
- 'dist/**',
- 'build/**',
- '.next/**',
- 'coverage/**',
- '**/*.min.js',
- 'vendor/**',
- // Skip packages/plugins since they have different theming rules
- 'packages/**',
- 'plugins/**',
- // Skip generated/external/config files
- '**/*.generated.*',
- '**/*.config.js',
- '**/webpack.*',
- '*.json',
- ],
- },
- {
- files: ['**/*.{js,jsx,ts,tsx}'],
- languageOptions: {
- ecmaVersion: 2020,
- sourceType: 'module',
- // The @typescript-eslint parser handles both TS/TSX and plain JS/JSX and
- // is compatible with ESLint v10's scope manager. (The legacy
- // @babel/eslint-parser does not support ESLint v10.) The custom rules
- // here are pure AST visitors and do not require type information, so no
- // `project` is configured — this keeps parsing fast.
- parser: tsParser,
- parserOptions: {
- ecmaFeatures: {
- jsx: true,
- },
- },
- },
- // Don't report on eslint-disable comments for rules we don't have.
- linterOptions: {
- reportUnusedDisableDirectives: false,
- },
- plugins: {
- 'theme-colors': themeColorsPlugin,
- icons: iconsPlugin,
- 'i18n-strings': i18nStringsPlugin,
- },
- rules: {
- // Custom Superset plugins
- 'theme-colors/no-literal-colors': 'error',
- 'icons/no-fa-icons-usage': 'error',
- 'i18n-strings/no-template-vars': 'error',
- // Enabled only for controlPanel files via the override below.
- 'i18n-strings/no-eager-t-in-config': 'off',
- },
- },
- {
- // Eager t()/tn() in `label`/`description` config props is captured at
- // module-load time, before i18n initializes — labels stay in the fallback
- // language even after the user switches. Surfaced as a warning (with
- // autofix to `() => t(...)`) wherever this is a real foot-gun:
- // controlPanel files. Promote to `'error'` once the codebase is clean.
- files: ['**/controlPanel.{ts,tsx,js,jsx}'],
- rules: {
- 'i18n-strings/no-eager-t-in-config': 'warn',
- },
- },
- {
- // Disable custom rules in test/story files
- files: [
- '**/*.test.*',
- '**/*.spec.*',
- '**/*.stories.*',
- '**/test/**',
- '**/tests/**',
- '**/spec/**',
- '**/__tests__/**',
- '**/__mocks__/**',
- 'cypress-base/**',
- ],
- rules: {
- 'theme-colors/no-literal-colors': 'off',
- 'icons/no-fa-icons-usage': 'off',
- 'i18n-strings/no-template-vars': 'off',
- },
- },
-];
diff --git a/superset-frontend/oxlint.custom-lint-rules.mts b/superset-frontend/oxlint.custom-lint-rules.mts
new file mode 100644
index 00000000000..b66ea32146a
--- /dev/null
+++ b/superset-frontend/oxlint.custom-lint-rules.mts
@@ -0,0 +1,114 @@
+/**
+ * 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.
+ */
+
+/**
+ * MINIMAL ESLint flat config - ONLY for rules OXC doesn't support.
+ *
+ * This config is run alongside the OXC (oxlint) linter, which handles the
+ * bulk of linting. ESLint here only covers the custom Superset plugins that
+ * oxlint cannot express. It is consumed by
+ * `scripts/oxlint-metrics-uploader.js` (`npm run lint-stats`).
+ *
+ * Migrated from the legacy `.eslintrc.minimal.js` (eslintrc) format to flat
+ * config for ESLint v9+/v10, where eslintrc is no longer supported.
+ *
+ * Only covers:
+ * - Custom Superset plugins (theme-colors, icons, i18n-strings)
+ */
+
+import { defineConfig } from 'oxlint';
+
+export default defineConfig({
+ // Files this config applies to. Flat config has no `--ext`; globs live here.
+ // Only check src/ files where the theme/icon/i18n rules matter.
+ ignorePatterns: [
+ 'node_modules/**',
+ 'dist/**',
+ 'build/**',
+ '.next/**',
+ 'coverage/**',
+ '**/*.min.js',
+ 'vendor/**',
+ // Skip packages/plugins since they have different theming rules
+ 'packages/**',
+ 'plugins/**',
+ // Skip generated/external/config files
+ '**/*.generated.*',
+ '**/*.config.js',
+ '**/webpack.*',
+ '*.json',
+ ],
+ plugins: [],
+ jsPlugins: [
+ "./custom-lint-rules/i18n-strings/index.js",
+ "./custom-lint-rules/icons/index.js",
+ "./custom-lint-rules/theme-colors/index.js"
+ ],
+ options: {
+ reportUnusedDisableDirectives: 'off',
+ respectEslintDisableDirectives: false
+ },
+ rules: {
+ "no-unused-vars": "off"
+ },
+ overrides: [
+ {
+ files: ['**/*.{js,jsx,ts,tsx}'],
+ // Don't report on eslint-disable comments for rules we don't have.
+ rules: {
+ // Custom Superset plugins
+ 'theme-colors/no-literal-colors': 'error',
+ 'icons/no-fa-icons-usage': 'error',
+ 'i18n-strings/no-template-vars': 'error',
+ // Enabled only for controlPanel files via the override below.
+ 'i18n-strings/no-eager-t-in-config': 'off',
+ },
+ },
+ {
+ // Eager t()/tn() in `label`/`description` config props is captured at
+ // module-load time, before i18n initializes — labels stay in the fallback
+ // language even after the user switches. Surfaced as a warning (with
+ // autofix to `() => t(...)`) wherever this is a real foot-gun:
+ // controlPanel files. Promote to `'error'` once the codebase is clean.
+ files: ['**/controlPanel.{ts,tsx,js,jsx}'],
+ rules: {
+ 'i18n-strings/no-eager-t-in-config': 'warn',
+ },
+ },
+ {
+ // Disable custom rules in test/story files
+ files: [
+ '**/*.test.*',
+ '**/*.spec.*',
+ '**/*.stories.*',
+ '**/test/**',
+ '**/tests/**',
+ '**/spec/**',
+ '**/__tests__/**',
+ '**/__mocks__/**',
+ 'cypress-base/**',
+ ],
+ rules: {
+ 'theme-colors/no-literal-colors': 'off',
+ 'icons/no-fa-icons-usage': 'off',
+ 'i18n-strings/no-template-vars': 'off',
+ },
+ },
+ ],
+});
diff --git a/superset-frontend/oxlint.json b/superset-frontend/oxlint.json
index 368ae345a27..9e43b4d424d 100644
--- a/superset-frontend/oxlint.json
+++ b/superset-frontend/oxlint.json
@@ -222,15 +222,15 @@
"jsx-a11y/tabindex-no-positive": "error",
// === TypeScript rules ===
- "@typescript-eslint/ban-ts-comment": "off",
- "@typescript-eslint/ban-types": "off",
- "@typescript-eslint/no-empty-function": "off",
- "@typescript-eslint/no-explicit-any": "off",
- "@typescript-eslint/no-use-before-define": "error",
- "@typescript-eslint/no-non-null-assertion": "off",
- "@typescript-eslint/explicit-function-return-type": "off",
- "@typescript-eslint/explicit-module-boundary-types": "off",
- "@typescript-eslint/no-unused-vars": [
+ "typescript/ban-ts-comment": "off",
+ "typescript/ban-types": "off",
+ "typescript/no-empty-function": "off",
+ "typescript/no-explicit-any": "off",
+ "typescript/no-use-before-define": "error",
+ "typescript/no-non-null-assertion": "off",
+ "typescript/explicit-function-return-type": "off",
+ "typescript/explicit-module-boundary-types": "off",
+ "typescript/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
@@ -238,7 +238,7 @@
"caughtErrors": "none"
}
],
- "@typescript-eslint/prefer-optional-chain": "error",
+ "typescript/prefer-optional-chain": "error",
// === Unicorn rules (bonus coverage) ===
"unicorn/no-new-array": "error",
diff --git a/superset-frontend/scripts/oxlint-metrics-uploader.js b/superset-frontend/scripts/oxlint-metrics-uploader.js
index 5b8008009cc..9c80f3ebbfd 100644
--- a/superset-frontend/scripts/oxlint-metrics-uploader.js
+++ b/superset-frontend/scripts/oxlint-metrics-uploader.js
@@ -72,6 +72,39 @@ function parseRuleId(code) {
return `${plugin}/${rule}`;
}
+function parseOxlintResult(results) {
+ // Process OXC JSON output
+ const metricsByRule = {};
+ const occurrencesData = [];
+
+ // OXC JSON format has diagnostics array
+ if (results.diagnostics && Array.isArray(results.diagnostics)) {
+ results.diagnostics.forEach(diagnostic => {
+ const ruleId = parseRuleId(diagnostic.code);
+
+ const file = diagnostic.filename || 'unknown';
+ const line = diagnostic.labels?.[0]?.span?.line || 0;
+ const column = diagnostic.labels?.[0]?.span?.column || 0;
+ const message = diagnostic.message || '';
+
+ const ruleData = metricsByRule[ruleId] || { count: 0 };
+ ruleData.count += 1;
+ metricsByRule[ruleId] = ruleData;
+
+ occurrencesData.push({
+ rule: ruleId,
+ message,
+ file,
+ line,
+ column,
+ ts: DATETIME,
+ });
+ });
+ }
+
+ return { metricsByRule, occurrencesData };
+}
+
async function writeToGoogleSheet(data, range, headers, append = false) {
if (!sheets) {
console.log('No Google Sheets credentials, skipping upload');
@@ -130,94 +163,44 @@ async function runOxlintAndProcess() {
);
const results = JSON.parse(oxlintOutput);
-
- // Process OXC JSON output
- const metricsByRule = {};
- let occurrencesData = [];
-
- // OXC JSON format has diagnostics array
- if (results.diagnostics && Array.isArray(results.diagnostics)) {
- results.diagnostics.forEach(diagnostic => {
- const ruleId = parseRuleId(diagnostic.code);
-
- const file = diagnostic.filename || 'unknown';
- const line = diagnostic.labels?.[0]?.span?.line || 0;
- const column = diagnostic.labels?.[0]?.span?.column || 0;
- const message = diagnostic.message || '';
-
- const ruleData = metricsByRule[ruleId] || { count: 0 };
- ruleData.count += 1;
- metricsByRule[ruleId] = ruleData;
-
- occurrencesData.push({
- rule: ruleId,
- message,
- file,
- line,
- column,
- ts: DATETIME,
- });
- });
- }
-
console.log(
`OXC found ${results.diagnostics?.length || 0} issues across ${results.number_of_files} files`,
);
+ const { metricsByRule, occurrencesData } = parseOxlintResult(results);
+
+ // Also run Oxlint for custom rules and merge results
+ console.log('Running Oxlint for custom rules...');
+ // Run ESLint and capture output directly.
+ // Flat config (oxlint.custom-lint-rules.mts) is explicitly selected via --config
+ const oxlintCustomRuleOutput = execSync(
+ 'npx oxlint --config oxlint.custom-lint-rules.mts --format json src',
+ {
+ encoding: 'utf8',
+ maxBuffer: 50 * 1024 * 1024, // 50MB buffer for large outputs
+ stdio: ['pipe', 'pipe', 'ignore'], // Ignore stderr
+ },
+ );
- // Also run minimal ESLint for custom rules and merge results
- console.log('Running minimal ESLint for custom rules...');
- let eslintOutput = '[]';
- try {
- // Run ESLint and capture output directly.
- // Flat config (eslint.config.minimal.js) is explicitly selected via
- // --config; ESLint v9+/v10 no longer support eslintrc or --no-eslintrc.
- eslintOutput = execSync(
- 'npx eslint --config eslint.config.minimal.js --no-inline-config --format json src',
- {
- encoding: 'utf8',
- maxBuffer: 50 * 1024 * 1024,
- stdio: ['pipe', 'pipe', 'ignore'], // Ignore stderr
- },
- );
- } catch (e) {
- // ESLint exits with non-zero when it finds issues, capture the stdout
- if (e.stdout) {
- eslintOutput = e.stdout.toString();
- }
- }
-
- // Parse minimal ESLint output
- try {
- const eslintResults = JSON.parse(eslintOutput);
-
- eslintResults.forEach(result => {
- result.messages.forEach(({ ruleId, line, column, message }) => {
- const ruleData = metricsByRule[ruleId] || { count: 0 };
- ruleData.count += 1;
- metricsByRule[ruleId] = ruleData;
-
- occurrencesData.push({
- rule: ruleId,
- message,
- file: result.filePath,
- line,
- column,
- ts: DATETIME,
- });
- });
- });
-
- console.log(
- `ESLint found ${eslintResults.reduce((sum, r) => sum + r.messages.length, 0)} custom rule violations`,
- );
- } catch (e) {
- console.log('No ESLint issues found or parsing error:', e.message);
- }
+ // Parse Oxlint output for custom rules
+ const oxlintCustomRuleResults = JSON.parse(oxlintCustomRuleOutput);
+ console.log(
+ `OXC found ${oxlintCustomRuleResults.diagnostics?.length || 0} issues across ${oxlintCustomRuleResults.number_of_files} files for custom rules`,
+ );
+ const {
+ metricsByRule: metricsByCustomRule,
+ occurrencesData: customRuleOccurrencesData,
+ } = parseOxlintResult(results);
+
+ const mergedMetricsByRule = { ...metricsByRule, ...metricsByCustomRule };
+ const mergedOccurrencesData = [
+ ...occurrencesData,
+ ...customRuleOccurrencesData,
+ ];
// Transform data for Google Sheets
- const metricsData = Object.entries(metricsByRule).map(
+ const metricsData = Object.entries(mergedMetricsByRule).map(
([rule, { count }]) => [
- 'OXC+ESLint',
+ 'OXC',
rule,
enrichedRules[rule]?.description || 'N/A',
`${count}`,
@@ -225,7 +208,7 @@ async function runOxlintAndProcess() {
],
);
- occurrencesData = occurrencesData.map(
+ const finalizedConcurrencesData = mergedOccurrencesData.map(
({ rule, message, file, line, column }) => [
rule,
enrichedRules[rule]?.description || 'N/A',
@@ -255,7 +238,7 @@ async function runOxlintAndProcess() {
];
console.log(
- `Found ${Object.keys(metricsByRule).length} unique rules with ${occurrencesData.length} total occurrences`,
+ `Found ${Object.keys(metricsByRule).length} unique rules with ${finalizedConcurrencesData.length} total occurrences`,
);
await writeToGoogleSheet(
@@ -266,7 +249,7 @@ async function runOxlintAndProcess() {
);
await writeToGoogleSheet(
- occurrencesData,
+ finalizedConcurrencesData,
'ESLint Backlog!A:G',
eslintBacklogHeaders,
);