bito-code-review[bot] commented on code in PR #44201:
URL: https://github.com/apache/superset/pull/44201#discussion_r3995827226


##########
superset-frontend/scripts/oxlint-metrics-uploader.js:
##########
@@ -130,102 +163,52 @@ 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);

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Wrong variable in parse call</b></div>
   <div id="fix">
   
   `parseOxlintResult` is called with `results` (the first oxlint run) instead 
of `oxlintCustomRuleResults`. The custom-rules run is parsed and logged but 
never processed, so `metricsByCustomRule`/`customRuleOccurrencesData` duplicate 
the main run's data and the custom rules are double-counted in 
`mergedOccurrencesData`. Pass `oxlintCustomRuleResults`.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
         metricsByRule: metricsByCustomRule,
         occurrencesData: customRuleOccurrencesData,
       } = parseOxlintResult(oxlintCustomRuleResults);
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #75e601</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to