Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove duplicate messages #22

Merged
merged 1 commit into from
Mar 14, 2024
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
51 changes: 42 additions & 9 deletions src/detectors/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,52 @@ export default class Reporter implements BaseReporter {
let errorCount = 0;
let warningCount = 0;
let fatalErrorCount = 0;
for (const {severity, fatal} of this.#messages) {
if (severity === LintMessageSeverity.Error) {
errorCount++;
if (fatal) {
fatalErrorCount++;
}
} else {
warningCount++;
const lineColumnMessagesMap = new Map<string, LintMessage[]>();
const messages: LintMessage[] = [];
for (const message of this.#messages) {
// Group messages by line/column so that we can deduplicate them
if (!message.line || !message.column) {
// If there is no line or column, we cannot group/deduplicate
messages.push(message);
continue;
}
const lineColumnKey = `${message.line}:${message.column}`;
let lineColumnMessages = lineColumnMessagesMap.get(lineColumnKey);
if (!lineColumnMessages) {
lineColumnMessages = [];
lineColumnMessagesMap.set(lineColumnKey, lineColumnMessages);
}
lineColumnMessages.push(message);
}

// Add deduplicated messages to the result
for (const lineColumnMessages of lineColumnMessagesMap.values()) {
// If there are multiple messages for the same line/column,
// and at least one of them is NOT a "no-globals-js" message,
// we can deduplicate the "no-globals-js" messages.
const deduplicateGlobalMessages = lineColumnMessages.length > 1 &&
lineColumnMessages.some((message) => message.ruleId !== "ui5-linter-no-globals-js");

lineColumnMessages.forEach((message) => {
if (deduplicateGlobalMessages && message.ruleId === "ui5-linter-no-globals-js") {
// Skip global messages if there are other messages for the same line/column
return;
}
if (message.severity === LintMessageSeverity.Error) {
errorCount++;
if (message.fatal) {
fatalErrorCount++;
}
} else {
warningCount++;
}
messages.push(message);
});
}

return {
filePath: this.#getFileName(),
messages: this.#messages,
messages,
coverageInfo: this.#coverageInfo,
errorCount,
warningCount,
Expand Down
10 changes: 1 addition & 9 deletions test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 2,
errorCount: 1,
fatalErrorCount: 0,
filePath: 'sap.ui.jsview.js',
messages: [
Expand All @@ -809,14 +809,6 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 1,
fatal: undefined,
line: 1,
message: 'Access of global variable \'sap\' (sap.ui.jsview)',
ruleId: 'ui5-linter-no-globals-js',
severity: 2,
},
],
warningCount: 0,
},
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.
30 changes: 3 additions & 27 deletions test/lib/linter/snapshots/linter.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 3,
errorCount: 2,
fatalErrorCount: 0,
filePath: 'webapp/test/integration/opaTests.qunit.js',
messages: [
Expand All @@ -577,14 +577,6 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 1,
fatal: undefined,
line: 4,
message: 'Access of global variable \'sap\' (sap.ui.getCore)',
ruleId: 'ui5-linter-no-globals-js',
severity: 2,
},
],
warningCount: 0,
},
Expand Down Expand Up @@ -678,7 +670,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 3,
errorCount: 2,
fatalErrorCount: 0,
filePath: 'webapp/test/unit/unitTests.qunit.js',
messages: [
Expand All @@ -700,14 +692,6 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 1,
fatal: undefined,
line: 6,
message: 'Access of global variable \'sap\' (sap.ui.getCore)',
ruleId: 'ui5-linter-no-globals-js',
severity: 2,
},
],
warningCount: 0,
},
Expand Down Expand Up @@ -923,7 +907,7 @@ Generated by [AVA](https://avajs.dev).
},
{
coverageInfo: [],
errorCount: 3,
errorCount: 2,
fatalErrorCount: 0,
filePath: 'src/main/js/library.js',
messages: [
Expand All @@ -945,14 +929,6 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'ui5-linter-no-deprecated-api',
severity: 2,
},
{
column: 2,
fatal: undefined,
line: 15,
message: 'Access of global variable \'sap\' (sap.ui.getCore)',
ruleId: 'ui5-linter-no-globals-js',
severity: 2,
},
],
warningCount: 0,
},
Expand Down
Binary file modified test/lib/linter/snapshots/linter.ts.snap
Binary file not shown.