Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions lib/harAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '..');
Expand Down Expand Up @@ -91,8 +93,7 @@ export class HarAnalyzer {
let knowledgeData = {
'url': url,
'group': group,
'issues': [],
'resolved-rules': []
'issues': {}
};

if (analyzedData === undefined) {
Expand Down Expand Up @@ -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;
}
Expand Down
120 changes: 53 additions & 67 deletions pug/index.pug
Original file line number Diff line number Diff line change
@@ -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
Expand Down