Skip to content

Commit 1602a61

Browse files
committed
Define the configuration for message reporting
1 parent 3e8d95a commit 1602a61

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

‎apps/api-extractor/src/api/IExtractorConfig.ts‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,94 @@ export interface IExtractorTsdocMetadataConfig {
267267
tsdocMetadataPath?: string;
268268
}
269269

270+
/**
271+
* Used with {@link IExtractorMessageRoutingConfig.logLevel}.
272+
*
273+
* @public
274+
*/
275+
export const enum ExtractorMessageLogLevel {
276+
/**
277+
* The message will be written to the output log as an error.
278+
*
279+
* @remarks
280+
* Errors cause the build to fail and return a nonzero exit code.
281+
*/
282+
Error = 'Error',
283+
284+
/**
285+
* The message will be written to the build output as an warning.
286+
* @remarks
287+
* Warnings cause a production build fail and return a nonzero exit code. For a non-production build
288+
* (e.g. using the `--local` option with `api-extractor run`), the warning is displayed but the build will not fail.
289+
*/
290+
Warning = 'Warning',
291+
292+
/**
293+
* The message will not be reported to the output log.
294+
*/
295+
None = 'None'
296+
}
297+
298+
/**
299+
* Configures how API Extractor messages are reported.
300+
*
301+
* @public
302+
*/
303+
export interface IExtractorMessageReportingRuleConfig {
304+
/**
305+
* Specifies whether the message should be written to the the tool's output log.
306+
*
307+
* @remarks
308+
* Note that the `addToApiReviewFile` property may supersede this option.
309+
*/
310+
logLevel: ExtractorMessageLogLevel;
311+
312+
/**
313+
* If API Extractor is configured to write an API review file (.api.ts), then the message will be written
314+
* inside that file. If the API review file is NOT being written, then the message is instead logged according
315+
* to the `logLevel` option.
316+
*/
317+
addToApiReviewFile: boolean;
318+
}
319+
320+
/**
321+
* Specifies a table of reporting rules for different message IDs, and also the default rule used for IDs that
322+
* do not appear in the table.
323+
*
324+
* @public
325+
*/
326+
export interface IExtractorMessageReportingTableConfig {
327+
/**
328+
* The key is a message ID for the associated type of message, or "default" to specify the default policy.
329+
* For example, the key might be `TS2551` (a compiler message), `tsdoc-link-tag-unescaped-text` (a TSDOc message),
330+
* or `ae-extra-release-tag` (a message related to the API Extractor analysis).
331+
*/
332+
[messageId: string]: IExtractorMessageReportingRuleConfig;
333+
}
334+
335+
/**
336+
* Configures how API Extractor reports issues that it encounters.
337+
*
338+
* @public
339+
*/
340+
export interface IExtractorMessagesConfig {
341+
/**
342+
* Configures handling of diagnostic messages generating the TypeScript compiler while analyzing the
343+
* input .d.ts files.
344+
*/
345+
compilerMessageReporting: IExtractorMessageReportingTableConfig;
346+
347+
/**
348+
* Configures handling of messages reported by the TSDoc parser when analyzing code comments.
349+
*/
350+
tsdocMessageReporting: IExtractorMessageReportingTableConfig;
351+
352+
/**
353+
* Configures handling of messages reported by API Extractor during its analysis.
354+
*/
355+
extractorMessageReporting: IExtractorMessageReportingTableConfig;
356+
}
357+
270358
/**
271359
* Configuration options for the API Extractor tool. These options can be loaded
272360
* from a JSON config file.
@@ -324,6 +412,11 @@ export interface IExtractorConfig {
324412
*/
325413
tsdocMetadata?: IExtractorTsdocMetadataConfig;
326414

415+
/**
416+
* {@inheritdoc IExtractorMessagesConfig}
417+
*/
418+
messages?: IExtractorMessagesConfig;
419+
327420
/**
328421
* This option causes the typechecker to be invoked with the --skipLibCheck option. This option is not
329422
* recommended and may cause API Extractor to produce incomplete or incorrect declarations, but it

‎apps/api-extractor/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export {
2525
IExtractorApiJsonFileConfig,
2626
IExtractorDtsRollupConfig,
2727
IExtractorTsdocMetadataConfig,
28+
ExtractorMessageLogLevel,
29+
IExtractorMessageReportingRuleConfig,
30+
IExtractorMessageReportingTableConfig,
31+
IExtractorMessagesConfig,
2832
IExtractorConfig
2933
} from './api/IExtractorConfig';
3034

‎common/reviews/api/api-extractor.api.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,13 @@ declare const enum ExtractorMessageId {
530530
MissingReleaseTag = "ae-missing-release-tag"
531531
}
532532

533+
// @public
534+
declare const enum ExtractorMessageLogLevel {
535+
Error = "Error",
536+
None = "None",
537+
Warning = "Warning"
538+
}
539+
533540
// @public
534541
declare const enum ExtractorValidationRulePolicy {
535542
allow = "allow",
@@ -730,6 +737,8 @@ interface IExtractorConfig {
730737
dtsRollup?: IExtractorDtsRollupConfig;
731738
extends?: string;
732739
// (undocumented)
740+
messages?: IExtractorMessagesConfig;
741+
// (undocumented)
733742
policies?: IExtractorPoliciesConfig;
734743
// (undocumented)
735744
project: IExtractorProjectConfig;
@@ -752,6 +761,24 @@ interface IExtractorDtsRollupConfig {
752761
trimming?: boolean;
753762
}
754763

764+
// @public
765+
interface IExtractorMessageReportingRuleConfig {
766+
addToApiReviewFile: boolean;
767+
logLevel: ExtractorMessageLogLevel;
768+
}
769+
770+
// @public
771+
interface IExtractorMessageReportingTableConfig {
772+
[messageId: string]: IExtractorMessageReportingRuleConfig;
773+
}
774+
775+
// @public
776+
interface IExtractorMessagesConfig {
777+
compilerMessageReporting: IExtractorMessageReportingTableConfig;
778+
extractorMessageReporting: IExtractorMessageReportingTableConfig;
779+
tsdocMessageReporting: IExtractorMessageReportingTableConfig;
780+
}
781+
755782
// @public
756783
interface IExtractorOptions {
757784
compilerProgram?: ts.Program;

0 commit comments

Comments
 (0)