From dc3180860278babf5f4016735f1fc5ab729809c0 Mon Sep 17 00:00:00 2001 From: 7h3Rabbit <62792609+7h3Rabbit@users.noreply.github.com> Date: Thu, 10 Apr 2025 10:25:39 +0200 Subject: [PATCH] Introduce subIssues as concept --- lib/harAnalyzer.js | 39 +++++++++++++-- pug/index.pug | 120 ++++++++++++++++++++------------------------- 2 files changed, 89 insertions(+), 70 deletions(-) diff --git a/lib/harAnalyzer.js b/lib/harAnalyzer.js index 6ae60da..ec89251 100644 --- a/lib/harAnalyzer.js +++ b/lib/harAnalyzer.js @@ -14,10 +14,12 @@ export class HarAnalyzer { overrideConfigFile: true, overrideConfig: securityConfig }); + this.securityRules = securityConfig[0].rules; this.eslintStandard = new ESLint({ overrideConfigFile: true, overrideConfig: standardConfig }); + this.standardRules = standardConfig[0].rules; const libFolder = fileURLToPath(new URL('..', import.meta.url)); this.pluginFolder = path.resolve(libFolder, '..'); @@ -91,8 +93,7 @@ export class HarAnalyzer { let knowledgeData = { 'url': url, 'group': group, - 'issues': [], - 'resolved-rules': [] + 'issues': {} }; if (analyzedData === undefined) { @@ -139,8 +140,40 @@ export class HarAnalyzer { // Wait for all linting promises to resolve and flatten the results const lintResults = await Promise.all(lintPromises); - knowledgeData.issues = lintResults.flat(); + const flatResults = lintResults.flat(); + + // Convert issues to a set grouped by rule + const issuesByRule = {}; + for (const issue of flatResults) { + if (!issuesByRule[issue.rule]) { + issuesByRule[issue.rule] = { + rule: issue.rule, + category: issue.category, + severity: issue.severity, + subIssues: [] + }; + } + issuesByRule[issue.rule].subIssues.push(issue); + } + + // Add missing rules from securityConfig and standardConfig + const allRules = [ + ...Object.keys(this.securityRules || {}).filter(rule => this.securityRules[rule] !== "off"), + ...Object.keys(this.standardRules || {}).filter(rule => this.standardRules[rule] !== "off") + ]; + + for (const rule of allRules) { + if (!issuesByRule[rule]) { + issuesByRule[rule] = { + rule: rule, + category: rule in this.securityRules ? 'security' : 'standard', + severity: 'resolved', // Default severity for missing issues + subIssues: [] + }; + } + } + knowledgeData.issues = issuesByRule; return knowledgeData; } diff --git a/pug/index.pug b/pug/index.pug index 4569d53..f4c4b53 100644 --- a/pug/index.pug +++ b/pug/index.pug @@ -1,84 +1,70 @@ - let pluginData = pageInfo.data['webperf-plugin-javascript'].run ? pageInfo.data['webperf-plugin-javascript'].run : pageInfo.data['webperf-plugin-javascript'].pageSummary -if pluginData.knowledgeData && pluginData.knowledgeData.issues && pluginData.knowledgeData.issues.length > 0 - - if (pluginData.knowledgeData.issues.length > 15) - h1 Grouped Issues - - let groupedIssues = {}; - - pluginData.knowledgeData.issues.forEach(issue => { - - let key = `${issue.rule}-${issue.category}-${issue.severity}`; - - if (!groupedIssues[key]) { - - groupedIssues[key] = { rule: issue.rule, category: issue.category, severity: issue.severity, count: 0 }; - - } - - groupedIssues[key].count++; - - }); - - const severityOrder = { critical: 4, error: 3, warning: 2, info: 1 }; - - let sortedGroupedIssues = Object.values(groupedIssues).sort((a, b) => { - - if (severityOrder[b.severity] !== severityOrder[a.severity]) { - - return severityOrder[b.severity] - severityOrder[a.severity]; - - } - - return b.count - a.count; - - }); - table - thead +if pluginData.knowledgeData && pluginData.knowledgeData.issues && Object.keys(pluginData.knowledgeData.issues).length > 0 + - let issueSets = pluginData.knowledgeData.issues; + - let issues = Object.values(issueSets); + - const severityOrder = { critical: 4, error: 3, warning: 2, info: 1, none: 0 }; + - let sortedIssues = issues.sort((a, b) => { + - if (severityOrder[b.severity] !== severityOrder[a.severity]) { + - return severityOrder[b.severity] - severityOrder[a.severity]; + - } + - return b.subIssues.length - a.subIssues.length; + - }); + + h1 Issues + table + thead + tr + th Rule + th Category + th Sub Issue Count + th Severity + tbody + each value in sortedIssues tr - th Rule - th Category - th Severity - th Count - tbody - each value in sortedGroupedIssues - tr - td - a(href=`#rule-${value.rule}`)= value.rule - td= value.category - td= value.severity - td= value.count + td + a(href=`#rule-${value.rule}`)= value.rule + td= value.category + td= value.subIssues.length + td + if value.severity === 'resolved' + span.label.ok Resolved + else if value.severity === 'warning' + span.label.warning Warning + else if value.severity === 'error' + span.label.error Error + else if value.severity === 'info' + span.label.info Info + else + = value.severity - // Add tables for each rule - each value in sortedGroupedIssues - h2(id=`rule-${value.rule}`)= `Rule: ${value.rule}` - p - strong Category: - = value.category - br - strong Severity: - = value.severity - - if (pluginData.knowledgeData.issues.filter(issue => issue.rule === value.rule).length > 100) - p Note: Only the first 100 issues are displayed. - table - thead - tr - th URL - th Text - th Line - th Column - tbody - - let limitedIssues = pluginData.knowledgeData.issues.filter(issue => issue.rule === value.rule).slice(0, 100); - each issue in limitedIssues - tr - td= issue.url - td= issue.text - td= issue.line - td= issue.column - - else - h1 Issues + // Add tables for each rule + each value in sortedIssues + h2(id=`rule-${value.rule}`)= `${value.rule}` + p + strong Category: + = value.category + br + strong Severity: + = value.severity + br + strong More info link: + a(href=`https://eslint.org/docs/latest/rules/${value.rule}` target="_blank")= "ESLint Docs" + + - if (value.subIssues.length > 100) + p Note: Only the first 100 issues are displayed. table thead tr th URL - th Rule - th Category - th Severity th Text th Line th Column tbody - each issue in pluginData.knowledgeData.issues + - let limitedIssues = value.subIssues.slice(0, 100); + each issue in limitedIssues tr td= issue.url - td= issue.rule - td= issue.category - td= issue.severity td= issue.text td= issue.line td= issue.column