Skip to content

Commit

Permalink
Provide a way to suppress the error
Browse files Browse the repository at this point in the history
  • Loading branch information
octogonz committed May 13, 2022
1 parent 933b463 commit f4d5519
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
11 changes: 9 additions & 2 deletions apps/api-extractor/src/api/ExtractorMessageId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ export const enum ExtractorMessageId {
/**
* "The property ___ has a setter but no getter."
*/
MissingGetter = 'ae-missing-getter'
MissingGetter = 'ae-missing-getter',

/**
* "Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension.
* Troubleshooting tips: `https://api-extractor.com/link/dts-error`"
*/
NotDtsFileExtension = 'ae-wrong-input-file-type'
}

export const allExtractorMessageIds: Set<string> = new Set<string>([
Expand All @@ -114,5 +120,6 @@ export const allExtractorMessageIds: Set<string> = new Set<string>([
'ae-cyclic-inherit-doc',
'ae-unresolved-link',
'ae-setter-with-docs',
'ae-missing-getter'
'ae-missing-getter',
'ae-wrong-input-file-type'
]);
13 changes: 8 additions & 5 deletions apps/api-extractor/src/collector/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,17 @@ export class Collector {

// We can throw this error earlier in CompilerState.ts, but intentionally wait until after we've logged the
// associated diagnostic message above to make debugging easier for developers.
const badSourceFile: boolean = sourceFiles.some(
// Typically there will be many such files -- to avoid too much noise, only report the first one.
const badSourceFile: ts.SourceFile | undefined = sourceFiles.find(
({ fileName }) => !ExtractorConfig.hasDtsFileExtension(fileName)
);
if (badSourceFile) {
throw new Error(
'API Extractor expects to only process .d.ts files, but encountered non-.d.ts file(s).\n' +
'Run with the "--diagnostics" flag and inspect the "Files analyzed by compiler" to find the unexpected ' +
'file(s).'
this.messageRouter.addAnalyzerIssueForPosition(
ExtractorMessageId.NotDtsFileExtension,
'Incorrect file type; API Extractor expects to analyze compiler outputs with the .d.ts file extension. ' +
'Troubleshooting tips: https://api-extractor.com/link/dts-error',
badSourceFile,
0
);
}

Expand Down
3 changes: 3 additions & 0 deletions apps/api-extractor/src/schemas/api-extractor-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"ae-unresolved-inheritdoc-base": {
"logLevel": "warning",
"addToApiReportFile": true
},
"ae-wrong-input-file-type": {
"logLevel": "error"
}
},
"tsdocMessageReporting": {
Expand Down
2 changes: 1 addition & 1 deletion common/reviews/api/api-extractor.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const enum ExtractorMessageId {
MisplacedPackageTag = "ae-misplaced-package-tag",
MissingGetter = "ae-missing-getter",
MissingReleaseTag = "ae-missing-release-tag",
NotDtsFileExtension = "ae-wrong-input-file-type",
PreapprovedBadReleaseTag = "ae-preapproved-bad-release-tag",
PreapprovedUnsupportedType = "ae-preapproved-unsupported-type",
SetterWithDocs = "ae-setter-with-docs",
Expand Down Expand Up @@ -265,5 +266,4 @@ export interface IExtractorMessagesConfig {
tsdocMessageReporting?: IConfigMessageReportingTable;
}


```

0 comments on commit f4d5519

Please sign in to comment.