add diagnostics and tests when incorrect prefix for suppresion
MODIFY
packages/@romefrontend/compiler/suppressions.test.md
packages/@romefrontend/compiler/suppressions.test.md
@@ -110,6 +110,156 @@ Object {
}
```
+## `incorrect suppression comment`
+
+```javascript
+Object {
+ suppressions: Array []
+ diagnostics: Array [
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 19
+ index: 19
+ line: 1
+ }
+ start: Object {
+ column: 0
+ index: 0
+ line: 1
+ }
+ }
+ }
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 19
+ index: 46
+ line: 4
+ }
+ start: Object {
+ column: 0
+ index: 27
+ line: 4
+ }
+ }
+ }
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 20
+ index: 74
+ line: 7
+ }
+ start: Object {
+ column: 0
+ index: 54
+ line: 7
+ }
+ }
+ }
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 27
+ index: 109
+ line: 10
+ }
+ start: Object {
+ column: 0
+ index: 82
+ line: 10
+ }
+ }
+ }
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 26
+ index: 143
+ line: 13
+ }
+ start: Object {
+ column: 0
+ index: 117
+ line: 13
+ }
+ }
+ }
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 28
+ index: 179
+ line: 16
+ }
+ start: Object {
+ column: 0
+ index: 151
+ line: 16
+ }
+ }
+ }
+ Object {
+ description: Object {
+ advice: Array []
+ category: "suppressions/incorrectSuppressionStart"
+ message: PARTIAL_BLESSED_DIAGNOSTIC_MESSAGE {value: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?"}
+ }
+ location: Object {
+ filename: "unknown"
+ end: Object {
+ column: 27
+ index: 214
+ line: 19
+ }
+ start: Object {
+ column: 0
+ index: 187
+ line: 19
+ }
+ }
+ }
+ ]
+}
+```
+
## `multiple categories`
```javascript

MODIFY
packages/@romefrontend/compiler/suppressions.test.ts
packages/@romefrontend/compiler/suppressions.test.ts
@@ -206,3 +206,44 @@ test(
t.snapshot(suppressions);
},
);
+
+test(
+ "incorrect suppression comment",
+ async (t) => {
+ const suppressions = extractSuppressionsFromSource(
+ dedent`
+ // @rome-ignore foo
+ boo()
+
+ // rome-disable foo
+ boo()
+
+ // @rome-disable foo
+ boo()
+
+ // @romefrontend-ignore foo
+ boo()
+
+ // romefrontend-ignore foo
+ boo()
+
+ // @romefrontend-disable foo
+ boo()
+
+ // romefrontend-disable foo
+ boo()
+ `,
+ );
+
+ t.is(suppressions.suppressions.length, 0);
+ t.is(suppressions.diagnostics.length, 7);
+ for (const diagnostic of suppressions.diagnostics) {
+ t.is(
+ diagnostic.description.category,
+ "suppressions/incorrectSuppressionStart",
+ );
+ }
+
+ t.snapshot(suppressions);
+ },
+);

MODIFY
packages/@romefrontend/compiler/suppressions.ts
packages/@romefrontend/compiler/suppressions.ts
@@ -17,6 +17,15 @@ import CompilerContext from "./lib/CompilerContext";
import Path from "./lib/Path";
export const SUPPRESSION_START = "rome-ignore";
+export const INCORRECT_SUPPRESSION_START = [
+ "rome-disable",
+ "@rome-ignore",
+ "@rome-disable",
+ "romefrontend-ignore",
+ "romefrontend-disable",
+ "@romefrontend-ignore",
+ "@romefrontend-disable",
+];
type ExtractedSuppressions = {
suppressions: DiagnosticSuppressions;
@@ -46,6 +55,17 @@ function extractSuppressionsFromComment(
});
for (const line of cleanLines) {
+ if (
+ INCORRECT_SUPPRESSION_START.some((incorrectStart) =>
+ line.startsWith(incorrectStart)
+ )
+ ) {
+ diagnostics.push({
+ description: descriptions.SUPPRESSIONS.INCORRECT_SUPPRESSION_START,
+ location: commentLocation,
+ });
+ }
+
if (!line.startsWith(SUPPRESSION_START)) {
continue;
}

MODIFY
packages/@romefrontend/diagnostics/categories.ts
packages/@romefrontend/diagnostics/categories.ts
@@ -52,6 +52,7 @@ export type DiagnosticCategory =
| "resolver/unsupported"
| "suppressions/duplicate"
| "suppressions/overlap"
+ | "suppressions/incorrectSuppressionStart"
| "suppressions/incorrectPrefix"
| "suppressions/missingSpace"
| "suppressions/missingTarget"

MODIFY
packages/@romefrontend/diagnostics/descriptions/suppressions.ts
packages/@romefrontend/diagnostics/descriptions/suppressions.ts
@@ -39,4 +39,8 @@ export const suppressions = createDiagnosticsCategory({
category: "suppressions/overlap",
message: markup`overlap suppression category <emphasis>${category}</emphasis>`,
}),
+ INCORRECT_SUPPRESSION_START: {
+ category: "suppressions/incorrectSuppressionStart",
+ message: "This looks like a suppression comment typo. Did you mean <emphasis>rome-ignore</emphasis> instead?",
+ },
});

add diagnostics and tests when incorrect prefix for suppresion (#785)