Clean up DiagnosticFilter types
MODIFY
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
@@ -129,6 +129,7 @@ export default class DiagnosticsPrinter extends Error {
opts.readFile === undefined ? readDiagnosticsFileLocal : opts.readFile;
this.cwd = cwd === undefined ? createAbsoluteFilePath(process.cwd()) : cwd;
this.processor = new DiagnosticsProcessor({
+ filters: opts.filters,
origins: opts.origins,
});

MODIFY
packages/@romejs/cli-diagnostics/types.ts
packages/@romejs/cli-diagnostics/types.ts
import {Reporter} from '@romejs/cli-reporter';
import {AbsoluteFilePath} from '@romejs/path';
-import {DiagnosticOrigin, DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {DiagnosticOrigin, DiagnosticFilters} from '@romejs/diagnostics';
export type DiagnosticsPrinterFlags = {
grep: string;
@@ -31,5 +31,5 @@ export type DiagnosticsPrinterOptions = {
cwd?: AbsoluteFilePath;
flags?: DiagnosticsPrinterFlags;
readFile?: DiagnosticsFileReader;
- filters?: Array<DiagnosticFilterJSON>;
+ filters?: DiagnosticFilters;
};

MODIFY
packages/@romejs/core/common/bridges/WorkerBridge.ts
packages/@romejs/core/common/bridges/WorkerBridge.ts
@@ -12,7 +12,7 @@ import {Program, ConstSourceType} from '@romejs/js-ast';
import {CompileResult, TransformStageName} from '@romejs/js-compiler';
import {Profile} from '@romejs/v8';
import {ProfilingStartData} from './MasterBridge';
-import {PartialDiagnostics, DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import {ProjectConfigJSON} from '@romejs/project';
import {DiagnosticsError} from '@romejs/diagnostics';
import {Bridge} from '@romejs/events';
@@ -97,7 +97,7 @@ export type WorkerFormatResult = {
export type WorkerLintResult = {
diagnostics: PartialDiagnostics;
- filters: Array<DiagnosticFilterJSON>;
+ filters: DiagnosticFilters;
};
export default class WorkerBridge extends Bridge {

MODIFY
packages/@romejs/core/common/fileHandlers.ts
packages/@romejs/core/common/fileHandlers.ts
@@ -9,7 +9,7 @@ import {ProjectConfig} from '@romejs/project';
import {FileReference} from '@romejs/core';
import {PrefetchedModuleSignatures} from '../common/bridges/WorkerBridge';
import Worker, {ParseResult} from '../worker/Worker';
-import {PartialDiagnostics, DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import * as compiler from '@romejs/js-compiler';
import {check as typeCheck} from '@romejs/js-analysis';
import {parseJSON, stringifyJSON, consumeJSONExtra} from '@romejs/codec-json';
@@ -86,7 +86,7 @@ export type ExtensionLintResult = {
sourceText: string;
diagnostics: PartialDiagnostics;
formatted: string;
- filters: Array<DiagnosticFilterJSON>;
+ filters: DiagnosticFilters;
};
export type ExtensionHandlerMethodInfo = {

MODIFY
packages/@romejs/diagnostics/DiagnosticsProcessor.ts
packages/@romejs/diagnostics/DiagnosticsProcessor.ts
@@ -9,7 +9,7 @@ import {
Diagnostics,
PartialDiagnostics,
PartialDiagnostic,
- DiagnosticFilter,
+ DiagnosticFilterWithTest,
DiagnosticOrigin,
} from './types';
import {MarkupFormatOptions} from '@romejs/string-markup';
@@ -30,7 +30,7 @@ type UniqueRule = Array<UniquePart>;
type UniqueRules = Array<UniqueRule>;
export type CollectorOptions = {
- filters?: Array<DiagnosticFilter>;
+ filters?: Array<DiagnosticFilterWithTest>;
unique?: UniqueRules;
max?: number;
onDiagnostics?: (diags: PartialDiagnostics) => void;
@@ -67,7 +67,7 @@ export default class DiagnosticsProcessor {
unique: UniqueRules;
includedKeys: Set<string>;
diagnostics: PartialDiagnostics;
- filters: Array<DiagnosticFilter>;
+ filters: Array<DiagnosticFilterWithTest>;
options: CollectorOptions;
throwAfter: undefined | number;
@@ -88,11 +88,11 @@ export default class DiagnosticsProcessor {
return this.diagnostics.length > 0;
}
- addFilters(filters: Array<DiagnosticFilter>) {
+ addFilters(filters: Array<DiagnosticFilterWithTest>) {
this.filters = this.filters.concat(filters);
}
- addFilter(filter: DiagnosticFilter) {
+ addFilter(filter: DiagnosticFilterWithTest) {
this.filters.push(filter);
}

MODIFY
packages/@romejs/diagnostics/errors.ts
packages/@romejs/diagnostics/errors.ts
@@ -9,13 +9,13 @@ import {PartialDiagnostics, DiagnosticsProcessor} from '@romejs/diagnostics';
import {escapeMarkup} from '@romejs/string-markup';
import {stripAnsi} from '@romejs/string-ansi';
import {printDiagnosticsToString} from '@romejs/cli-diagnostics';
-import {PartialDiagnostic, DiagnosticFilterJSON} from './types';
+import {PartialDiagnostic, DiagnosticFilters} from './types';
export class DiagnosticsError extends Error {
constructor(
message: string,
diagnostics: PartialDiagnostics,
- filters: Array<DiagnosticFilterJSON> = [],
+ filters: DiagnosticFilters = [],
) {
if (diagnostics.length === 0) {
throw new Error('No diagnostics');
@@ -38,12 +38,12 @@ export class DiagnosticsError extends Error {
}
diagnostics: PartialDiagnostics;
- filters: Array<DiagnosticFilterJSON>;
+ filters: DiagnosticFilters;
}
export function createSingleDiagnosticError(
diag: PartialDiagnostic,
- filters?: Array<DiagnosticFilterJSON>,
+ filters?: DiagnosticFilters,
): DiagnosticsError {
return new DiagnosticsError(diag.message, [diag], filters);
}

MODIFY
packages/@romejs/diagnostics/types.ts
packages/@romejs/diagnostics/types.ts
@@ -11,7 +11,7 @@ import {ConstSourceType} from '@romejs/js-ast';
import {Number0, Number1} from '@romejs/ob1';
import {JSONPropertyValue} from '@romejs/codec-json';
-export type DiagnosticFilterJSON = {
+export type DiagnosticFilter = {
category?: string;
message?: string;
filename?: string;
@@ -19,7 +19,9 @@ export type DiagnosticFilterJSON = {
line?: Number1;
};
-export type DiagnosticFilter = DiagnosticFilterJSON & {
+export type DiagnosticFilters = Array<DiagnosticFilter>;
+
+export type DiagnosticFilterWithTest = DiagnosticFilter & {
test?: (diagnostic: PartialDiagnostic) => boolean;
};

MODIFY
packages/@romejs/js-compiler/api/compile.ts
packages/@romejs/js-compiler/api/compile.ts
*/
import {Mappings} from '@romejs/codec-source-map';
-import {PartialDiagnostics, DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import {CompileRequest} from '../types';
import {Cache} from '@romejs/js-compiler';
import {generateJS} from '@romejs/js-generator';
@@ -18,7 +18,7 @@ export type CompileResult = {
src: string;
mappings: Mappings;
diagnostics: PartialDiagnostics;
- filters: Array<DiagnosticFilterJSON>;
+ filters: DiagnosticFilters;
cacheDependencies: Array<string>;
};

MODIFY
packages/@romejs/js-compiler/api/lint.ts
packages/@romejs/js-compiler/api/lint.ts
*/
import {Program} from '@romejs/js-ast';
-import {PartialDiagnostics, DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import {TransformRequest} from '../types';
import {lintTransforms} from '../transforms/lint/index';
import {program} from '@romejs/js-ast';
@@ -16,7 +16,7 @@ import {extractSuppressionsFromProgram} from '../suppressions';
export type LintResult = {
diagnostics: PartialDiagnostics;
- filters: Array<DiagnosticFilterJSON>;
+ filters: DiagnosticFilters;
src: string;
ast: Program;
};

MODIFY
packages/@romejs/js-compiler/methods/transform.ts
packages/@romejs/js-compiler/methods/transform.ts
*/
import {Program} from '@romejs/js-ast';
-import {PartialDiagnostics, DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import {TransformRequest, TransformVisitors} from '../types';
import {program} from '@romejs/js-ast';
import {stageTransforms, stageOrder, hookVisitors} from '../transforms/index';
@@ -16,7 +16,7 @@ import {extractSuppressionsFromProgram} from '../suppressions';
type TransformResult = {
ast: Program;
- filters: Array<DiagnosticFilterJSON>;
+ filters: DiagnosticFilters;
diagnostics: PartialDiagnostics;
cacheDependencies: Array<string>;
};

MODIFY
packages/@romejs/js-compiler/suppressions.ts
packages/@romejs/js-compiler/suppressions.ts
*/
import {Program, AnyComment} from '@romejs/js-ast';
-import {DiagnosticFilterJSON} from '@romejs/diagnostics';
+import {DiagnosticFilters} from '@romejs/diagnostics';
import {add} from '@romejs/ob1';
const SUPPRESSION_START = 'rome-suppress';
function extractFiltersFromComment(
comment: AnyComment,
-): undefined | Array<DiagnosticFilterJSON> {
+): undefined | DiagnosticFilters {
const {loc} = comment;
if (loc === undefined) {
return undefined;
}
const targetLine = add(loc.end.line, 1);
- const filters: Array<DiagnosticFilterJSON> = [];
+ const filters: DiagnosticFilters = [];
const lines = comment.value.split('\n');
const cleanLines = lines.map(line => {
@@ -61,8 +61,8 @@ function extractFiltersFromComment(
export function extractSuppressionsFromComments(
comments: Array<AnyComment>,
-): Array<DiagnosticFilterJSON> {
- let filters: Array<DiagnosticFilterJSON> = [];
+): DiagnosticFilters {
+ let filters: DiagnosticFilters = [];
for (const comment of comments) {
const commentFilters = extractFiltersFromComment(comment);
@@ -76,6 +76,6 @@ export function extractSuppressionsFromComments(
export function extractSuppressionsFromProgram(
ast: Program,
-): Array<DiagnosticFilterJSON> {
+): DiagnosticFilters {
return extractSuppressionsFromComments(ast.comments);
}

MODIFY
packages/@romejs/js-parser/tokenizer/state.ts
packages/@romejs/js-parser/tokenizer/state.ts
* LICENSE file in the root directory of this source tree.
*/
-import {PartialDiagnostics, DiagnosticFilter} from '@romejs/diagnostics';
+import {PartialDiagnostics, DiagnosticFilters} from '@romejs/diagnostics';
import {OpeningContext, ScopeType} from '../parser';
import {Position, SourceLocation} from '@romejs/parser-core';
import {types as ct, TokContext} from './context';
@@ -18,7 +18,7 @@ type Scopes = {[K in ScopeType]?: Array<unknown>};
export type State = {
diagnostics: PartialDiagnostics;
- diagnosticFilters: Array<DiagnosticFilter>;
+ diagnosticFilters: DiagnosticFilters;
isIterator: boolean;
tokens: Array<Token>;
hasHoistedVars: boolean;

Clean up DiagnosticFilter types