@@ -410,6 +410,8 @@ export interface Service {
410
410
configFilePath : string | undefined ;
411
411
/** @internal */
412
412
moduleTypeClassifier : ModuleTypeClassifier ;
413
+ /** @internal */
414
+ addDiagnosticFilter ( filter : DiagnosticFilter ) : void ;
413
415
}
414
416
415
417
/**
@@ -419,6 +421,16 @@ export interface Service {
419
421
*/
420
422
export type Register = Service ;
421
423
424
+ /** @internal */
425
+ export interface DiagnosticFilter {
426
+ /** if true, filter applies to all files */
427
+ appliesToAllFiles : boolean ;
428
+ /** Filter applies onto to these filenames. Only used if appliesToAllFiles is false */
429
+ filenamesAbsolute : string [ ] ;
430
+ /** these diagnostic codes are ignored */
431
+ diagnosticsIgnored : number [ ] ;
432
+ }
433
+
422
434
/** @internal */
423
435
export function getExtensions ( config : _ts . ParsedCommandLine ) {
424
436
const tsExtensions = [ '.ts' ] ;
@@ -516,16 +528,22 @@ export function create(rawOptions: CreateOptions = {}): Service {
516
528
const transpileOnly =
517
529
options . transpileOnly === true && options . typeCheck !== true ;
518
530
const transformers = options . transformers || undefined ;
519
- const ignoreDiagnostics = [
520
- 6059 , // "'rootDir' is expected to contain all source files."
521
- 18002 , // "The 'files' list in config file is empty."
522
- 18003 , // "No inputs were found in config file."
523
- ...( options . ignoreDiagnostics || [ ] ) ,
524
- ] . map ( Number ) ;
531
+ const diagnosticFilters : Array < DiagnosticFilter > = [
532
+ {
533
+ appliesToAllFiles : true ,
534
+ filenamesAbsolute : [ ] ,
535
+ diagnosticsIgnored : [
536
+ 6059 , // "'rootDir' is expected to contain all source files."
537
+ 18002 , // "The 'files' list in config file is empty."
538
+ 18003 , // "No inputs were found in config file."
539
+ ...( options . ignoreDiagnostics || [ ] ) ,
540
+ ] . map ( Number ) ,
541
+ } ,
542
+ ] ;
525
543
526
544
const configDiagnosticList = filterDiagnostics (
527
545
config . errors ,
528
- ignoreDiagnostics
546
+ diagnosticFilters
529
547
) ;
530
548
const outputCache = new Map <
531
549
string ,
@@ -804,7 +822,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
804
822
805
823
const diagnosticList = filterDiagnostics (
806
824
diagnostics ,
807
- ignoreDiagnostics
825
+ diagnosticFilters
808
826
) ;
809
827
if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
810
828
@@ -963,7 +981,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
963
981
const diagnostics = ts . getPreEmitDiagnostics ( program , sourceFile ) ;
964
982
const diagnosticList = filterDiagnostics (
965
983
diagnostics ,
966
- ignoreDiagnostics
984
+ diagnosticFilters
967
985
) ;
968
986
if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
969
987
@@ -1079,7 +1097,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
1079
1097
1080
1098
const diagnosticList = filterDiagnostics (
1081
1099
result . diagnostics || [ ] ,
1082
- ignoreDiagnostics
1100
+ diagnosticFilters
1083
1101
) ;
1084
1102
if ( diagnosticList . length ) reportTSError ( diagnosticList ) ;
1085
1103
@@ -1141,6 +1159,10 @@ export function create(rawOptions: CreateOptions = {}): Service {
1141
1159
return true ;
1142
1160
} ;
1143
1161
1162
+ function addDiagnosticFilter ( filter : DiagnosticFilter ) {
1163
+ diagnosticFilters . push ( filter ) ;
1164
+ }
1165
+
1144
1166
return {
1145
1167
ts,
1146
1168
config,
@@ -1151,6 +1173,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
1151
1173
options,
1152
1174
configFilePath,
1153
1175
moduleTypeClassifier,
1176
+ addDiagnosticFilter,
1154
1177
} ;
1155
1178
}
1156
1179
@@ -1306,9 +1329,16 @@ function updateSourceMap(sourceMapText: string, fileName: string) {
1306
1329
*/
1307
1330
function filterDiagnostics (
1308
1331
diagnostics : readonly _ts . Diagnostic [ ] ,
1309
- ignore : number [ ]
1332
+ filters : DiagnosticFilter [ ]
1310
1333
) {
1311
- return diagnostics . filter ( ( x ) => ignore . indexOf ( x . code ) === - 1 ) ;
1334
+ return diagnostics . filter ( ( d ) =>
1335
+ filters . every (
1336
+ ( f ) =>
1337
+ ( ! f . appliesToAllFiles &&
1338
+ f . filenamesAbsolute . indexOf ( d . file ?. fileName ! ) === - 1 ) ||
1339
+ f . diagnosticsIgnored . indexOf ( d . code ) === - 1
1340
+ )
1341
+ ) ;
1312
1342
}
1313
1343
1314
1344
/**
0 commit comments