Skip to content

Commit

Permalink
Update prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Apr 29, 2024
1 parent 9946b92 commit 96b4ae8
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 288 deletions.
3 changes: 0 additions & 3 deletions .config/.prettierignore
Expand Up @@ -12,6 +12,3 @@
../example/docs/
**/tmp
**/.vs

# Remove once Prettier has support
../src/test/converter2/behavior/resolutionMode.ts
14 changes: 7 additions & 7 deletions internal-docs/third-party-symbols.md
Expand Up @@ -23,13 +23,13 @@ detected as belonging to the `typescript` package rather than the `global` packa
// For these you should probably install typedoc-plugin-mdn-links instead
"global": {
// Handle {@link !Promise}
"Promise": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"
"Promise": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",
},
"typescript": {
// Handle type X = Promise<number>
"Promise": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"
}
}
"Promise": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",
},
},
}
```

Expand All @@ -41,9 +41,9 @@ A wildcard can be used to provide a fallback link to any unmapped type.
"externalSymbolLinkMappings": {
"external-lib": {
"SomeObject": "https://external-lib.site/docs/SomeObject",
"*": "https://external-lib.site/docs"
}
}
"*": "https://external-lib.site/docs",
},
},
}
```

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,7 +44,7 @@
"esbuild": "^0.20.2",
"eslint": "^8.57.0",
"mocha": "^10.4.0",
"prettier": "3.0.3",
"prettier": "3.2.5",
"puppeteer": "^13.5.2",
"ts-node": "^10.9.2",
"typescript": "5.4.5"
Expand Down
25 changes: 10 additions & 15 deletions src/lib/converter/converter.ts
Expand Up @@ -544,11 +544,8 @@ function getSymbolForModuleLike(
const sourceFile = node.getSourceFile();
const globalSymbols = context.checker
.getSymbolsInScope(node, ts.SymbolFlags.ModuleMember)
.filter(
(s) =>
s
.getDeclarations()
?.some((d) => d.getSourceFile() === sourceFile),
.filter((s) =>
s.getDeclarations()?.some((d) => d.getSourceFile() === sourceFile),
);

// Detect declaration files with declare module "foo" as their only export
Expand Down Expand Up @@ -609,11 +606,10 @@ function getExports(
if (globalSymbol) {
result = context.checker
.getExportsOfModule(globalSymbol)
.filter(
(exp) =>
exp.declarations?.some(
(d) => d.getSourceFile() === node,
),
.filter((exp) =>
exp.declarations?.some(
(d) => d.getSourceFile() === node,
),
);
}
}
Expand All @@ -623,11 +619,10 @@ function getExports(
const sourceFile = node.getSourceFile();
result = context.checker
.getSymbolsInScope(node, ts.SymbolFlags.ModuleMember)
.filter(
(s) =>
s
.getDeclarations()
?.some((d) => d.getSourceFile() === sourceFile),
.filter((s) =>
s
.getDeclarations()
?.some((d) => d.getSourceFile() === sourceFile),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -652,8 +652,8 @@ function moveNestedParamTags(
for (const param of parameters) {
const visitor: Partial<TypeVisitor> = {
reflection(target) {
const tags = paramTags.filter(
(t) => t.name?.startsWith(`${param.name}.`),
const tags = paramTags.filter((t) =>
t.name?.startsWith(`${param.name}.`),
);

for (const tag of tags) {
Expand Down
7 changes: 3 additions & 4 deletions src/lib/converter/plugins/ImplementsPlugin.ts
Expand Up @@ -316,10 +316,9 @@ export class ImplementsPlugin extends ConverterComponent {
context.logger.warn(
`Failed to retrieve${
reflection.flags.isStatic ? " static" : ""
} member "${
reflection.escapedName ?? reflection.name
}" of "${reflection.parent
?.name}" for inheritance analysis. Please report a bug.` as TranslatedString,
} member "${reflection.escapedName ?? reflection.name}" of "${
reflection.parent?.name
}" for inheritance analysis. Please report a bug.` as TranslatedString,
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/symbols.ts
Expand Up @@ -1241,8 +1241,8 @@ function isInherited(context: Context, symbol: ts.Symbol) {
parents.push(...constructorDecls);

return (
parents.some(
(d) => symbol.getDeclarations()?.some((d2) => d2.parent === d),
parents.some((d) =>
symbol.getDeclarations()?.some((d2) => d2.parent === d),
) === false
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/internationalization/translatable.ts
Expand Up @@ -469,8 +469,8 @@ type BuildConstraint<
> = [T] extends [never]
? `${Acc}${string}`
: T extends T
? BuildConstraint<Exclude<U, T>, `${Acc}${string}{${T}}`>
: never;
? BuildConstraint<Exclude<U, T>, `${Acc}${string}{${T}}`>
: never;

// Combinatorially explosive, but shouldn't matter for us, since we only need a few iterations.
type TranslationConstraint = [
Expand All @@ -496,7 +496,7 @@ const _validatePlaceholdersPresent: {
[K in keyof typeof translatable]: K extends `${string}_1${string}`
? TranslationConstraint[2]
: K extends `${string}_0${string}`
? TranslationConstraint[1]
: TranslationConstraint[0];
? TranslationConstraint[1]
: TranslationConstraint[0];
} = translatable;
_validatePlaceholdersPresent;
4 changes: 2 additions & 2 deletions src/lib/models/reflections/abstract.ts
Expand Up @@ -476,8 +476,8 @@ export abstract class Reflection {
declaration(decl) {
if (
decl.signatures?.length &&
decl.signatures.every(
(sig) => sig.comment?.getTag("@deprecated"),
decl.signatures.every((sig) =>
sig.comment?.getTag("@deprecated"),
)
) {
signaturesDeprecated = true;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/output/themes/default/partials/member.tsx
Expand Up @@ -25,10 +25,10 @@ export function member(context: DefaultThemeRenderContext, props: DeclarationRef
{props.signatures
? context.memberSignatures(props)
: props.hasGetterOrSetter()
? context.memberGetterSetter(props)
: props instanceof ReferenceReflection
? context.memberReference(props)
: context.memberDeclaration(props)}
? context.memberGetterSetter(props)
: props instanceof ReferenceReflection
? context.memberReference(props)
: context.memberDeclaration(props)}

{props.groups?.map((item) => item.children.map((item) => !item.hasOwnDocument && context.member(item)))}
</section>
Expand Down
77 changes: 38 additions & 39 deletions src/lib/serialization/schema.ts
Expand Up @@ -33,59 +33,58 @@ import type * as M from "../models";
/**
* Describes the mapping from Model types to the corresponding JSON output type.
*/
export type ModelToObject<T> = T extends Array<infer U>
? _ModelToObject<U>[]
: _ModelToObject<T>;
export type ModelToObject<T> =
T extends Array<infer U> ? _ModelToObject<U>[] : _ModelToObject<T>;

// Order matters here. Some types are subtypes of other types.
type _ModelToObject<T> =
// Reflections
T extends Primitive
? T
: Required<T> extends Required<M.ReflectionGroup>
? ReflectionGroup
: Required<T> extends Required<M.ReflectionCategory>
? ReflectionCategory
: T extends M.SignatureReflection
? SignatureReflection
: T extends M.ParameterReflection
? ParameterReflection
: T extends M.DeclarationReflection
? DeclarationReflection
: T extends M.TypeParameterReflection
? TypeParameterReflection
: T extends M.ProjectReflection
? ProjectReflection
: T extends M.ContainerReflection
? ContainerReflection
: T extends M.ReferenceReflection
? ReferenceReflection
: T extends M.Reflection
? Reflection
: // Types
T extends M.SomeType
? TypeKindMap[T["type"]]
: T extends M.Type
? SomeType
: // Miscellaneous
T extends M.Comment
? Comment
: T extends M.CommentTag
? CommentTag
: T extends M.CommentDisplayPart
? CommentDisplayPart
: T extends M.SourceReference
? SourceReference
: never;
? ReflectionGroup
: Required<T> extends Required<M.ReflectionCategory>
? ReflectionCategory
: T extends M.SignatureReflection
? SignatureReflection
: T extends M.ParameterReflection
? ParameterReflection
: T extends M.DeclarationReflection
? DeclarationReflection
: T extends M.TypeParameterReflection
? TypeParameterReflection
: T extends M.ProjectReflection
? ProjectReflection
: T extends M.ContainerReflection
? ContainerReflection
: T extends M.ReferenceReflection
? ReferenceReflection
: T extends M.Reflection
? Reflection
: // Types
T extends M.SomeType
? TypeKindMap[T["type"]]
: T extends M.Type
? SomeType
: // Miscellaneous
T extends M.Comment
? Comment
: T extends M.CommentTag
? CommentTag
: T extends M.CommentDisplayPart
? CommentDisplayPart
: T extends M.SourceReference
? SourceReference
: never;

type Primitive = string | number | undefined | null | boolean;

// Separate helper so that we can trigger distribution.
type ToSerialized<T> = T extends Primitive
? T
: T extends bigint
? { value: string; negative: boolean }
: ModelToObject<T>;
? { value: string; negative: boolean }
: ModelToObject<T>;

/**
* Helper to describe a set of serialized properties. Primitive types are returned
Expand Down
13 changes: 7 additions & 6 deletions src/lib/utils/highlighter.tsx
@@ -1,5 +1,10 @@
import { ok as assert, ok } from "assert";
import type { BundledLanguage, BundledTheme, Highlighter, TokenStyles } from "shiki" with { "resolution-mode": "import" };
import type {
BundledLanguage,
BundledTheme,
Highlighter,
TokenStyles,
} from "shiki" with { "resolution-mode": "import" };
import * as JSX from "./jsx";
import { unique } from "./array";

Expand Down Expand Up @@ -45,11 +50,7 @@ class DoubleHighlighter {

for (const line of tokens) {
for (const token of line) {
docEls.push(
<span class={this.getClass(token.variants)}>
{token.content}
</span>,
);
docEls.push(<span class={this.getClass(token.variants)}>{token.content}</span>);
}

docEls.push(<br />);
Expand Down

0 comments on commit 96b4ae8

Please sign in to comment.