suppressions: Allow a suppression comment to match multiple diagnostics on the subsequent line instead of just one
MODIFY
packages/@romejs/diagnostics/DiagnosticsProcessor.ts
packages/@romejs/diagnostics/DiagnosticsProcessor.ts
@@ -48,6 +48,7 @@ export default class DiagnosticsProcessor {
constructor(options: CollectorOptions) {
this.diagnostics = [];
this.filters = [];
+ this.usedSuppressions = new Set();
this.suppressions = new Set();
this.options = options;
this.includedKeys = new Set();
@@ -72,6 +73,7 @@ export default class DiagnosticsProcessor {
includedKeys: Set<string>;
diagnostics: PartialDiagnostics;
filters: Array<DiagnosticFilterWithTest>;
+ usedSuppressions: Set<DiagnosticSuppression>;
suppressions: Set<DiagnosticSuppression>;
options: CollectorOptions;
throwAfter: undefined | number;
@@ -116,7 +118,7 @@ export default class DiagnosticsProcessor {
diag.filename === suppression.loc.filename &&
diag.start.line === targetLine
) {
- this.suppressions.delete(suppression);
+ this.usedSuppressions.add(suppression);
return true;
}
}
@@ -266,12 +268,14 @@ export default class DiagnosticsProcessor {
// Add errors for remaining suppressions
for (const suppression of this.suppressions) {
+ if (!this.usedSuppressions.has(suppression)) {
diagnostics.push({
...suppression.loc,
message: 'Did not hide any error',
category: 'suppressions/unused',
});
}
+ }
return diagnostics;
}

MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -69,6 +69,7 @@ export type DiagnosticCategory =
| 'resolver/fetchFailed'
| 'suppressions/unused'
| 'suppressions/incorrectPrefix'
+ | 'suppressions/duplicate'
| 'tests/noneDeclared'
| 'tests/timeout'
| 'tests/snapshots/missing'

MODIFY
packages/@romejs/js-compiler/suppressions.test.md
packages/@romejs/js-compiler/suppressions.test.md
**DO NOT MODIFY**. This file has been autogenerated. Run `rome test packages/@romejs/js-compiler/suppressions.test.ts --update-snapshots` to update.
+## `duplicates`
+
+```javascript
+Object {
+ diagnostics: Array [
+ Object {
+ category: 'suppressions/duplicate'
+ filename: 'unknown'
+ message: 'Duplicate suppression category <emphasis>foo</emphasis>'
+ end: Object {
+ column: 0
+ index: 0
+ line: 1
+ }
+ start: Object {
+ column: 0
+ index: 0
+ line: 1
+ }
+ }
+ ]
+ suppressions: Array [
+ Object {
+ category: 'foo'
+ loc: Object {
+ filename: 'unknown'
+ end: Object {
+ column: 0
+ index: 0
+ line: 1
+ }
+ start: Object {
+ column: 0
+ index: 0
+ line: 1
+ }
+ }
+ }
+ ]
+}
+```
+
## `multiple categories`
```javascript

MODIFY
packages/@romejs/js-compiler/suppressions.test.ts
packages/@romejs/js-compiler/suppressions.test.ts
@@ -29,17 +29,19 @@ function generateComment(value: string, line: number): CommentBlock {
}
test('single category', t => {
- const suppressions = extractSuppressionsFromComments([
+ t.snapshot(
+ extractSuppressionsFromComments([
generateComment('rome-suppress foo', 1),
generateComment('* rome-suppress foo', 2),
generateComment(' * rome-suppress foo', 3),
generateComment('* wow\n * rome-suppress foo', 4),
- ]);
- t.snapshot(suppressions);
+ ]),
+ );
});
test('multiple categories', t => {
- const suppressions = extractSuppressionsFromComments([
+ t.snapshot(
+ extractSuppressionsFromComments([
generateComment('rome-suppress foo bar', 1),
generateComment('* rome-suppress foo bar', 2),
generateComment(' * rome-suppress foo bar', 3),
@@ -47,13 +49,22 @@ test('multiple categories', t => {
'* wow\n * rome-suppress foo bar\n* rome-suppress cat dog',
4,
),
- ]);
- t.snapshot(suppressions);
+ ]),
+ );
});
test('typos', t => {
- const suppressions = extractSuppressionsFromComments([
+ t.snapshot(
+ extractSuppressionsFromComments([
generateComment('rome-ignore foo bar', 1),
- ]);
- t.snapshot(suppressions);
+ ]),
+ );
+});
+
+test('duplicates', t => {
+ t.snapshot(
+ extractSuppressionsFromComments([
+ generateComment('rome-suppress foo foo', 1),
+ ]),
+ );
});

MODIFY
packages/@romejs/js-compiler/suppressions.ts
packages/@romejs/js-compiler/suppressions.ts
import {Program, AnyComment} from '@romejs/js-ast';
import {DiagnosticSuppressions, PartialDiagnostics} from '@romejs/diagnostics';
+import {markup} from '@romejs/string-markup';
const SUPPRESSION_START = 'rome-suppress';
const PREFIX_MISTAKES = ['@rome-suppress', 'rome-ignore', '@rome-ignore'];
@@ -24,6 +25,7 @@ function extractSuppressionsFromComment(
return undefined;
}
+ const suppressedCategories: Set<string> = new Set();
const diagnostics: PartialDiagnostics = [];
const suppressions: DiagnosticSuppressions = [];
@@ -72,10 +74,20 @@ function extractSuppressionsFromComment(
category = category.slice(-1);
}
+ if (suppressedCategories.has(category)) {
+ diagnostics.push({
+ category: 'suppressions/duplicate',
+ message: markup`Duplicate suppression category <emphasis>${category}</emphasis>`,
+ ...loc,
+ });
+ } else {
+ suppressedCategories.add(category);
+
suppressions.push({
category,
loc,
});
+ }
if (shouldBreak) {
break;

suppressions: Allow a suppression comment to match multiple diagnostics on the subsequent line instead of just one