Add ability for DiagnosticsProcessor to ignore the unused suppressions of certain category prefixes
MODIFY
packages/@romejs/core/master/bundler/BundleRequest.ts
packages/@romejs/core/master/bundler/BundleRequest.ts
@@ -61,6 +61,8 @@ export default class BundleRequest {
},
],
});
+ this.diagnostics.addAllowedUnusedSuppressionPrefix('lint');
+
this.compiles = new Map();
this.assets = new Map();
@@ -182,6 +184,7 @@ export default class BundleRequest {
this.cached = false;
}
+ this.diagnostics.addSuppressions(res.suppressions);
this.diagnostics.addDiagnostics(res.diagnostics);
this.compiles.set(source, res);

MODIFY
packages/@romejs/core/master/linter/Linter.ts
packages/@romejs/core/master/linter/Linter.ts
@@ -28,6 +28,8 @@ export default class Linter {
message: 'Dispatched',
});
+ printer.processor.addAllowedUnusedSuppressionPrefix('bundler');
+
const paths: AbsoluteFilePathSet = await request.getFilesFromArgs({
getProjectIgnore: project => ({
patterns: project.config.lint.ignore,

MODIFY
packages/@romejs/diagnostics/DiagnosticsProcessor.ts
packages/@romejs/diagnostics/DiagnosticsProcessor.ts
@@ -20,6 +20,7 @@ import {naturalCompare} from '@romejs/string-utils';
import {DiagnosticsError} from './errors';
import {normalizeDiagnostics} from './normalize';
import {add} from '@romejs/ob1';
+import {DiagnosticCategoryPrefix} from './categories';
type UniquePart =
| 'filename'
@@ -48,6 +49,7 @@ export default class DiagnosticsProcessor {
constructor(options: CollectorOptions) {
this.diagnostics = [];
this.filters = [];
+ this.allowedUnusedSuppressionPrefixes = new Set();
this.usedSuppressions = new Set();
this.suppressions = new Set();
this.options = options;
@@ -73,6 +75,7 @@ export default class DiagnosticsProcessor {
includedKeys: Set<string>;
diagnostics: PartialDiagnostics;
filters: Array<DiagnosticFilterWithTest>;
+ allowedUnusedSuppressionPrefixes: Set<string>;
usedSuppressions: Set<DiagnosticSuppression>;
suppressions: Set<DiagnosticSuppression>;
options: CollectorOptions;
@@ -95,6 +98,10 @@ export default class DiagnosticsProcessor {
return this.diagnostics.length > 0;
}
+ addAllowedUnusedSuppressionPrefix(prefix: DiagnosticCategoryPrefix) {
+ this.allowedUnusedSuppressionPrefixes.add(prefix);
+ }
+
addSuppressions(suppressions: DiagnosticSuppressions) {
for (const suppression of suppressions) {
this.suppressions.add(suppression);
@@ -268,14 +275,21 @@ export default class DiagnosticsProcessor {
// Add errors for remaining suppressions
for (const suppression of this.suppressions) {
- if (!this.usedSuppressions.has(suppression)) {
+ if (this.usedSuppressions.has(suppression)) {
+ continue;
+ }
+
+ const [categoryPrefix] = suppression.category.split('/');
+ if (this.allowedUnusedSuppressionPrefixes.has(categoryPrefix)) {
+ continue;
+ }
+
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
@@ -86,3 +86,17 @@ export type DiagnosticCategory =
| 'typeCheck/notExhaustive'
| 'typeCheck/missingCondition'
| 'v8/syntaxError';
+
+export type DiagnosticCategoryPrefix =
+ | 'analyzeDependencies'
+ | 'args'
+ | 'bundler'
+ | 'compiler'
+ | 'flags'
+ | 'internalError'
+ | 'lint'
+ | 'parse'
+ | 'projectManager'
+ | 'tests'
+ | 'typeCheck'
+ | 'v8';

Add ability for DiagnosticsProcessor to ignore the unused suppressions of certain category prefixes