Skip to content

Commit

Permalink
Reapply Prettier following the steps in this comment:
Browse files Browse the repository at this point in the history
microsoft#1796 (comment)

# Conflicts:
#	apps/api-extractor/src/analyzer/AstSymbolTable.ts
#	apps/api-extractor/src/analyzer/ExportAnalyzer.ts
#	apps/api-extractor/src/collector/Collector.ts
#	apps/api-extractor/src/generators/ApiModelGenerator.ts
  • Loading branch information
octogonz committed Aug 28, 2020
2 parents 36250be + a55cd93 commit 8f65a6a
Show file tree
Hide file tree
Showing 47 changed files with 1,668 additions and 1,050 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require("@rushstack/eslint-config/patch-eslint6");
require('@rushstack/eslint-config/patch-eslint6');

module.exports = {
extends: [ "@rushstack/eslint-config" ],
parserOptions: { tsconfigRootDir: __dirname },
extends: ['@rushstack/eslint-config'],
parserOptions: { tsconfigRootDir: __dirname }
};
2 changes: 1 addition & 1 deletion config/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/rollup.d.ts",
"untrimmedFilePath": "<projectFolder>/dist/rollup.d.ts"
}
}
2 changes: 1 addition & 1 deletion config/jest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"isEnabled": true
}
}
15 changes: 8 additions & 7 deletions src/aedoc/PackageDocComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export class PackageDocComment {
/**
* For the given source file, see if it starts with a TSDoc comment containing the `@packageDocumentation` tag.
*/
public static tryFindInSourceFile(sourceFile: ts.SourceFile,
collector: Collector): ts.TextRange | undefined {

public static tryFindInSourceFile(
sourceFile: ts.SourceFile,
collector: Collector
): ts.TextRange | undefined {
// The @packageDocumentation comment is special because it is not attached to an AST
// definition. Instead, it is part of the "trivia" tokens that the compiler treats
// as irrelevant white space.
Expand Down Expand Up @@ -47,8 +48,8 @@ export class PackageDocComment {
// wrong place? This sanity check helps people to figure out why there comment isn't working.
for (const statement of sourceFile.statements) {
const ranges: ts.CommentRange[] = [];
ranges.push(...ts.getLeadingCommentRanges(sourceFile.text, statement.getFullStart()) || []);
ranges.push(...ts.getTrailingCommentRanges(sourceFile.text, statement.getEnd()) || []);
ranges.push(...(ts.getLeadingCommentRanges(sourceFile.text, statement.getFullStart()) || []));
ranges.push(...(ts.getTrailingCommentRanges(sourceFile.text, statement.getEnd()) || []));

for (const commentRange of ranges) {
const commentBody: string = sourceFile.text.substring(commentRange.pos, commentRange.end);
Expand All @@ -57,7 +58,8 @@ export class PackageDocComment {
collector.messageRouter.addAnalyzerIssueForPosition(
ExtractorMessageId.MisplacedPackageTag,
'The @packageDocumentation comment must appear at the top of entry point *.d.ts file',
sourceFile, commentRange.pos
sourceFile,
commentRange.pos
);
break;
}
Expand All @@ -67,5 +69,4 @@ export class PackageDocComment {

return packageCommentRange;
}

}
13 changes: 6 additions & 7 deletions src/analyzer/AstDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,21 @@ export class AstDeclaration {
switch (kind) {
case ts.SyntaxKind.CallSignature:
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.ConstructSignature: // Example: "new(x: number): IMyClass"
case ts.SyntaxKind.Constructor: // Example: "constructor(x: number)"
case ts.SyntaxKind.ConstructSignature: // Example: "new(x: number): IMyClass"
case ts.SyntaxKind.Constructor: // Example: "constructor(x: number)"
case ts.SyntaxKind.EnumDeclaration:
case ts.SyntaxKind.EnumMember:
case ts.SyntaxKind.FunctionDeclaration: // Example: "(x: number): number"
case ts.SyntaxKind.FunctionDeclaration: // Example: "(x: number): number"
case ts.SyntaxKind.GetAccessor:
case ts.SyntaxKind.SetAccessor:
case ts.SyntaxKind.IndexSignature: // Example: "[key: string]: string"
case ts.SyntaxKind.IndexSignature: // Example: "[key: string]: string"
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.MethodDeclaration:
case ts.SyntaxKind.MethodSignature:
case ts.SyntaxKind.ModuleDeclaration: // Used for both "module" and "namespace" declarations
case ts.SyntaxKind.ModuleDeclaration: // Used for both "module" and "namespace" declarations
case ts.SyntaxKind.PropertyDeclaration:
case ts.SyntaxKind.PropertySignature:
case ts.SyntaxKind.TypeAliasDeclaration: // Example: "type Shape = Circle | Square"
case ts.SyntaxKind.TypeAliasDeclaration: // Example: "type Shape = Circle | Square"
case ts.SyntaxKind.VariableDeclaration:
return true;

Expand All @@ -268,5 +268,4 @@ export class AstDeclaration {

return false;
}

}
3 changes: 1 addition & 2 deletions src/analyzer/AstEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ export abstract class AstEntity {
* - `AstImport`
* - `AstImportAsModule`
*/
export abstract class AstSyntheticEntity extends AstEntity {
}
export abstract class AstSyntheticEntity extends AstEntity {}
3 changes: 2 additions & 1 deletion src/analyzer/AstImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export class AstImport extends AstSyntheticEntity {
}

/** {@inheritdoc} */
public get localName(): string { // abstract
public get localName(): string {
// abstract
return this.exportName;
}

Expand Down
5 changes: 3 additions & 2 deletions src/analyzer/AstImportAsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class AstImportAsModule extends AstSyntheticEntity {
}

/** {@inheritdoc} */
public get localName(): string { // abstract
public get localName(): string {
// abstract
return this.exportName;
}
}
}
100 changes: 68 additions & 32 deletions src/analyzer/AstReferenceResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export class AstReferenceResolver {

public resolve(declarationReference: tsdoc.DocDeclarationReference): AstDeclaration | ResolverFailure {
// Is it referring to the working package?
if (declarationReference.packageName !== undefined
&& declarationReference.packageName !== this._workingPackage.name) {
if (
declarationReference.packageName !== undefined &&
declarationReference.packageName !== this._workingPackage.name
) {
return new ResolverFailure('External package references are not supported');
}

Expand All @@ -64,7 +66,8 @@ export class AstReferenceResolver {
}

const astModule: AstModule = this._astSymbolTable.fetchAstModuleFromWorkingPackage(
this._workingPackage.entryPointSourceFile);
this._workingPackage.entryPointSourceFile
);

if (declarationReference.memberReferences.length === 0) {
return new ResolverFailure('Package references are not supported');
Expand All @@ -78,18 +81,25 @@ export class AstReferenceResolver {
}

const rootAstEntity: AstEntity | undefined = this._astSymbolTable.tryGetExportOfAstModule(
exportName, astModule);
exportName,
astModule
);

if (rootAstEntity === undefined) {
return new ResolverFailure(`The package "${this._workingPackage.name}" does not have an export "${exportName}"`);
return new ResolverFailure(
`The package "${this._workingPackage.name}" does not have an export "${exportName}"`
);
}

if (!(rootAstEntity instanceof AstSymbol)) {
return new ResolverFailure('This type of declaration is not supported yet by the resolver');
}

let currentDeclaration: AstDeclaration | ResolverFailure = this._selectDeclaration(rootAstEntity.astDeclarations,
rootMemberReference, rootAstEntity.localName);
let currentDeclaration: AstDeclaration | ResolverFailure = this._selectDeclaration(
rootAstEntity.astDeclarations,
rootMemberReference,
rootAstEntity.localName
);

if (currentDeclaration instanceof ResolverFailure) {
return currentDeclaration;
Expand All @@ -103,13 +113,18 @@ export class AstReferenceResolver {
return memberName;
}

const matchingChildren: ReadonlyArray<AstDeclaration> = currentDeclaration.findChildrenWithName(memberName);
const matchingChildren: ReadonlyArray<AstDeclaration> = currentDeclaration.findChildrenWithName(
memberName
);
if (matchingChildren.length === 0) {
return new ResolverFailure(`No member was found with name "${memberName}"`);
}

const selectedDeclaration: AstDeclaration | ResolverFailure = this._selectDeclaration(matchingChildren,
memberReference, memberName);
const selectedDeclaration: AstDeclaration | ResolverFailure = this._selectDeclaration(
matchingChildren,
memberReference,
memberName
);

if (selectedDeclaration instanceof ResolverFailure) {
return selectedDeclaration;
Expand All @@ -131,9 +146,11 @@ export class AstReferenceResolver {
return memberReference.memberIdentifier.identifier;
}

private _selectDeclaration(astDeclarations: ReadonlyArray<AstDeclaration>,
memberReference: tsdoc.DocMemberReference, astSymbolName: string): AstDeclaration | ResolverFailure {

private _selectDeclaration(
astDeclarations: ReadonlyArray<AstDeclaration>,
memberReference: tsdoc.DocMemberReference,
astSymbolName: string
): AstDeclaration | ResolverFailure {
const memberSelector: tsdoc.DocMemberSelector | undefined = memberReference.selector;

if (memberSelector === undefined) {
Expand All @@ -142,13 +159,17 @@ export class AstReferenceResolver {
} else {
// If we found multiple matches, but the extra ones are all ancillary declarations,
// then return the main declaration.
const nonAncillaryMatch: AstDeclaration | undefined = this._tryDisambiguateAncillaryMatches(astDeclarations);
const nonAncillaryMatch: AstDeclaration | undefined = this._tryDisambiguateAncillaryMatches(
astDeclarations
);
if (nonAncillaryMatch) {
return nonAncillaryMatch;
}

return new ResolverFailure(`The reference is ambiguous because "${astSymbolName}"`
+ ` has more than one declaration; you need to add a TSDoc member reference selector`);
return new ResolverFailure(
`The reference is ambiguous because "${astSymbolName}"` +
` has more than one declaration; you need to add a TSDoc member reference selector`
);
}
}

Expand All @@ -162,9 +183,11 @@ export class AstReferenceResolver {
return new ResolverFailure(`The selector "${memberSelector.selector}" is not a supported selector type`);
}

private _selectUsingSystemSelector(astDeclarations: ReadonlyArray<AstDeclaration>,
memberSelector: tsdoc.DocMemberSelector, astSymbolName: string): AstDeclaration | ResolverFailure {

private _selectUsingSystemSelector(
astDeclarations: ReadonlyArray<AstDeclaration>,
memberSelector: tsdoc.DocMemberSelector,
astSymbolName: string
): AstDeclaration | ResolverFailure {
const selectorName: string = memberSelector.selector;

let selectorSyntaxKind: ts.SyntaxKind;
Expand Down Expand Up @@ -195,10 +218,14 @@ export class AstReferenceResolver {
return new ResolverFailure(`Unsupported system selector "${selectorName}"`);
}

const matches: AstDeclaration[] = astDeclarations.filter(x => x.declaration.kind === selectorSyntaxKind);
const matches: AstDeclaration[] = astDeclarations.filter(
(x) => x.declaration.kind === selectorSyntaxKind
);
if (matches.length === 0) {
return new ResolverFailure(`A declaration for "${astSymbolName}" was not found that matches the`
+ ` TSDoc selector "${selectorName}"`);
return new ResolverFailure(
`A declaration for "${astSymbolName}" was not found that matches the` +
` TSDoc selector "${selectorName}"`
);
}
if (matches.length > 1) {
// If we found multiple matches, but the extra ones are all ancillary declarations,
Expand All @@ -208,15 +235,18 @@ export class AstReferenceResolver {
return nonAncillaryMatch;
}

return new ResolverFailure(`More than one declaration "${astSymbolName}" matches the`
+ ` TSDoc selector "${selectorName}"`);
return new ResolverFailure(
`More than one declaration "${astSymbolName}" matches the TSDoc selector "${selectorName}"`
);
}
return matches[0];
}

private _selectUsingIndexSelector(astDeclarations: ReadonlyArray<AstDeclaration>,
memberSelector: tsdoc.DocMemberSelector, astSymbolName: string): AstDeclaration | ResolverFailure {

private _selectUsingIndexSelector(
astDeclarations: ReadonlyArray<AstDeclaration>,
memberSelector: tsdoc.DocMemberSelector,
astSymbolName: string
): AstDeclaration | ResolverFailure {
const selectorOverloadIndex: number = parseInt(memberSelector.selector);

const matches: AstDeclaration[] = [];
Expand All @@ -228,8 +258,10 @@ export class AstReferenceResolver {
}

if (matches.length === 0) {
return new ResolverFailure(`An overload for "${astSymbolName}" was not found that matches the`
+ ` TSDoc selector ":${selectorOverloadIndex}"`);
return new ResolverFailure(
`An overload for "${astSymbolName}" was not found that matches the` +
` TSDoc selector ":${selectorOverloadIndex}"`
);
}
if (matches.length > 1) {
// If we found multiple matches, but the extra ones are all ancillary declarations,
Expand All @@ -239,8 +271,10 @@ export class AstReferenceResolver {
return nonAncillaryMatch;
}

return new ResolverFailure(`More than one declaration for "${astSymbolName}" matches the`
+ ` TSDoc selector ":${selectorOverloadIndex}"`);
return new ResolverFailure(
`More than one declaration for "${astSymbolName}" matches the` +
` TSDoc selector ":${selectorOverloadIndex}"`
);
}
return matches[0];
}
Expand All @@ -249,7 +283,9 @@ export class AstReferenceResolver {
* This resolves an ambiguous match in the case where the extra matches are all ancillary declarations,
* except for one match that is the main declaration.
*/
private _tryDisambiguateAncillaryMatches(matches: ReadonlyArray<AstDeclaration>): AstDeclaration | undefined {
private _tryDisambiguateAncillaryMatches(
matches: ReadonlyArray<AstDeclaration>
): AstDeclaration | undefined {
let result: AstDeclaration | undefined = undefined;

for (const match of matches) {
Expand Down
Loading

0 comments on commit 8f65a6a

Please sign in to comment.