Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: prettier #1925

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .autorc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{
"plugins": [
"npm",
"conventional-commits",
"first-time-contributor",
"released"
],
"baseBranch": "stable",
"prereleaseBranches": [
"next"
],
"author": "GitHub Actions Bot <[email protected]>"
"plugins": ["npm", "conventional-commits", "first-time-contributor", "released"],
"baseBranch": "stable",
"prereleaseBranches": ["next"],
"author": "GitHub Actions Bot <[email protected]>"
}
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
azure-pipelines.yml
package.json
test/valid-data/**/*.json
babel.config.cjs
jest.config.cjs
2 changes: 0 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"trailingComma": "es5",
"printWidth": 120,
"tabWidth": 4,
"endOfLine": "lf",
"overrides": [
{
"files": "*.json",
Expand Down
69 changes: 29 additions & 40 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
//
// Helps with debugging parsing.
// - Set break points in the code
// - Open the file you want to parse: test/**/main.ts
// - F5 to run the debugger.
"name": "Debug Test Case",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register"
],
"args": [
"ts-json-schema-generator.ts",
"-p",
"${file}"
],
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": [
"<node_internals>/**",
"node_modules/**"
]
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"protocol": "inspector"
}
]
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
//
// Helps with debugging parsing.
// - Set break points in the code
// - Open the file you want to parse: test/**/main.ts
// - F5 to run the debugger.
"name": "Debug Test Case",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"args": ["ts-json-schema-generator.ts", "-p", "${file}"],
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"protocol": "inspector"
}
]
}
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ export default tseslint.config(
},
},
},
eslintPluginPrettierRecommended
eslintPluginPrettierRecommended,
);
2 changes: 1 addition & 1 deletion factory/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { VoidTypeFormatter } from "../src/TypeFormatter/VoidTypeFormatter.js";

export type FormatterAugmentor = (
formatter: MutableTypeFormatter,
circularReferenceTypeFormatter: CircularReferenceTypeFormatter
circularReferenceTypeFormatter: CircularReferenceTypeFormatter,
) => void;

export function createFormatter(config: CompletedConfig, augmentor?: FormatterAugmentor): TypeFormatter {
Expand Down
20 changes: 10 additions & 10 deletions factory/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function createParser(program: ts.Program, config: CompletedConfig, augme
if (config.jsDoc === "extended") {
return new AnnotatedNodeParser(
nodeParser,
new ExtendedAnnotationsReader(typeChecker, extraTags, config.markdownDescription)
new ExtendedAnnotationsReader(typeChecker, extraTags, config.markdownDescription),
);
} else if (config.jsDoc === "basic") {
return new AnnotatedNodeParser(nodeParser, new BasicAnnotationsReader(extraTags));
Expand Down Expand Up @@ -149,20 +149,20 @@ export function createParser(program: ts.Program, config: CompletedConfig, augme
new InterfaceAndClassNodeParser(
typeChecker,
withJsDoc(chainNodeParser),
config.additionalProperties
)
)
)
)
config.additionalProperties,
),
),
),
),
)
.addNodeParser(
withCircular(
withExpose(
withJsDoc(
new TypeLiteralNodeParser(typeChecker, withJsDoc(chainNodeParser), config.additionalProperties)
)
)
)
new TypeLiteralNodeParser(typeChecker, withJsDoc(chainNodeParser), config.additionalProperties),
),
),
),
)

.addNodeParser(new ArrayNodeParser(chainNodeParser));
Expand Down
2 changes: 1 addition & 1 deletion factory/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function loadTsConfigFile(configFile: string) {
ts.sys,
path.resolve(path.dirname(configFile)),
{},
configFile
configFile,
);
parseResult.options.noEmit = true;
delete parseResult.options.out;
Expand Down
2 changes: 1 addition & 1 deletion src/AnnotationsReader/ExtendedAnnotationsReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ExtendedAnnotationsReader extends BasicAnnotationsReader {
public constructor(
private typeChecker: ts.TypeChecker,
extraTags?: Set<string>,
private markdownDescription?: boolean
private markdownDescription?: boolean,
) {
super(extraTags);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChainNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ChainNodeParser implements SubNodeParser, MutableParser {

public constructor(
protected typeChecker: ts.TypeChecker,
protected nodeParsers: SubNodeParser[]
protected nodeParsers: SubNodeParser[],
) {}

public addNodeParser(nodeParser: SubNodeParser): this {
Expand Down
2 changes: 1 addition & 1 deletion src/Error/DiagnosticError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BaseError } from "./BaseError.js";
export class DiagnosticError extends BaseError {
public constructor(private diagnostics: readonly ts.Diagnostic[]) {
super(
diagnostics.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")).join("\n\n")
diagnostics.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")).join("\n\n"),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Error/UnknownNodeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { BaseError } from "./BaseError.js";
export class UnknownNodeError extends BaseError {
public constructor(
private node: ts.Node,
private reference?: ts.Node
private reference?: ts.Node,
) {
super(
`Unknown node "${node.getSourceFile() ? node.getFullText() : "<unknown>"}" of kind "${
ts.SyntaxKind[node.kind]
}"`
}"`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ExposeNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
protected typeChecker: ts.TypeChecker,
protected subNodeParser: SubNodeParser,
protected expose: "all" | "none" | "export",
protected jsDoc: "none" | "extended" | "basic"
protected jsDoc: "none" | "extended" | "basic",
) {}

public supportsNode(node: ts.Node): boolean {
Expand All @@ -38,7 +38,7 @@
return false;
}

const localSymbol: ts.Symbol = (node as any).localSymbol;

Check warning on line 41 in src/ExposeNodeParser.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 41 in src/ExposeNodeParser.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unsafe member access .localSymbol on an `any` value

Check warning on line 41 in src/ExposeNodeParser.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unsafe assignment of an `any` value

Check warning on line 41 in src/ExposeNodeParser.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unsafe member access .localSymbol on an `any` value
return localSymbol ? "exportSymbol" in localSymbol : false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/NodeParser/AnnotatedNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AnyType } from "../Type/AnyType.js";
export class AnnotatedNodeParser implements SubNodeParser {
public constructor(
protected childNodeParser: SubNodeParser,
protected annotationsReader: AnnotationsReader
protected annotationsReader: AnnotationsReader,
) {}

public supportsNode(node: ts.Node): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/NodeParser/CallExpressionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export class CallExpressionParser implements SubNodeParser {
public constructor(
protected typeChecker: ts.TypeChecker,
protected childNodeParser: NodeParser
protected childNodeParser: NodeParser,
) {}

public supportsNode(node: ts.CallExpression): boolean {
Expand All @@ -20,9 +20,9 @@
const type = this.typeChecker.getTypeAtLocation(node);

// FIXME: remove special case
if ((type as any)?.typeArguments) {

Check warning on line 23 in src/NodeParser/CallExpressionParser.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unsafe member access .typeArguments on an `any` value

Check warning on line 23 in src/NodeParser/CallExpressionParser.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unsafe member access .typeArguments on an `any` value
return new TupleType([
new UnionType((type as any).typeArguments[0].types.map((t: any) => new LiteralType(t.value))),

Check warning on line 25 in src/NodeParser/CallExpressionParser.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unsafe argument of type `any` assigned to a parameter of type `readonly BaseType[]`

Check warning on line 25 in src/NodeParser/CallExpressionParser.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unsafe call of an `any` typed value

Check warning on line 25 in src/NodeParser/CallExpressionParser.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unsafe argument of type `any` assigned to a parameter of type `readonly BaseType[]`

Check warning on line 25 in src/NodeParser/CallExpressionParser.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unsafe call of an `any` typed value
]);
}

Expand Down
12 changes: 6 additions & 6 deletions src/NodeParser/ConditionalTypeNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { NeverType } from "../Type/NeverType.js";
class CheckType {
constructor(
public parameterName: string,
public type: BaseType
public type: BaseType,
) {}
}

export class ConditionalTypeNodeParser implements SubNodeParser {
public constructor(
protected typeChecker: ts.TypeChecker,
protected childNodeParser: NodeParser
protected childNodeParser: NodeParser,
) {}

public supportsNode(node: ts.ConditionalTypeNode): boolean {
Expand All @@ -36,7 +36,7 @@ export class ConditionalTypeNodeParser implements SubNodeParser {
const result = isAssignableTo(extendsType, checkType, inferMap);
return this.childNodeParser.createType(
result ? node.trueType : node.falseType,
this.createSubContext(node, context, undefined, result ? inferMap : new Map())
this.createSubContext(node, context, undefined, result ? inferMap : new Map()),
);
}

Expand All @@ -49,7 +49,7 @@ export class ConditionalTypeNodeParser implements SubNodeParser {
if (!(trueCheckType instanceof NeverType)) {
const result = this.childNodeParser.createType(
node.trueType,
this.createSubContext(node, context, new CheckType(checkTypeParameterName, trueCheckType), inferMap)
this.createSubContext(node, context, new CheckType(checkTypeParameterName, trueCheckType), inferMap),
);
if (result) {
results.push(result);
Expand All @@ -58,7 +58,7 @@ export class ConditionalTypeNodeParser implements SubNodeParser {
if (!(falseCheckType instanceof NeverType)) {
const result = this.childNodeParser.createType(
node.falseType,
this.createSubContext(node, context, new CheckType(checkTypeParameterName, falseCheckType))
this.createSubContext(node, context, new CheckType(checkTypeParameterName, falseCheckType)),
);
if (result) {
results.push(result);
Expand Down Expand Up @@ -97,7 +97,7 @@ export class ConditionalTypeNodeParser implements SubNodeParser {
node: ts.ConditionalTypeNode,
parentContext: Context,
checkType?: CheckType,
inferMap: Map<string, BaseType> = new Map()
inferMap: Map<string, BaseType> = new Map(),
): Context {
const subContext = new Context(node);

Expand Down
2 changes: 1 addition & 1 deletion src/NodeParser/ConstructorNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getNamedArguments, getTypeName } from "./FunctionNodeParser.js";
export class ConstructorNodeParser implements SubNodeParser {
constructor(
protected childNodeParser: NodeParser,
protected functions: FunctionOptions
protected functions: FunctionOptions,
) {}

public supportsNode(node: ts.TypeNode): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/NodeParser/EnumNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class EnumNodeParser implements SubNodeParser {
`enum-${getKey(node, context)}`,
members
.filter((member: ts.EnumMember) => !isNodeHidden(member))
.map((member, index) => this.getMemberValue(member, index))
.map((member, index) => this.getMemberValue(member, index)),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/NodeParser/ExpressionWithTypeArgumentsNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BaseType } from "../Type/BaseType.js";
export class ExpressionWithTypeArgumentsNodeParser implements SubNodeParser {
public constructor(
protected typeChecker: ts.TypeChecker,
protected childNodeParser: NodeParser
protected childNodeParser: NodeParser,
) {}

public supportsNode(node: ts.ExpressionWithTypeArguments): boolean {
Expand All @@ -18,7 +18,7 @@ export class ExpressionWithTypeArgumentsNodeParser implements SubNodeParser {
const aliasedSymbol = this.typeChecker.getAliasedSymbol(typeSymbol);
return this.childNodeParser.createType(
aliasedSymbol.declarations![0],
this.createSubContext(node, context)
this.createSubContext(node, context),
);
} else if (typeSymbol.flags & ts.SymbolFlags.TypeParameter) {
return context.getArgument(typeSymbol.name);
Expand Down
10 changes: 5 additions & 5 deletions src/NodeParser/FunctionNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getKey } from "../Utils/nodeKey.js";
export class FunctionNodeParser implements SubNodeParser {
constructor(
protected childNodeParser: NodeParser,
protected functions: FunctionOptions
protected functions: FunctionOptions,
) {}

public supportsNode(node: ts.TypeNode): boolean {
Expand All @@ -26,7 +26,7 @@ export class FunctionNodeParser implements SubNodeParser {

public createType(
node: ts.FunctionTypeNode | ts.FunctionExpression | ts.FunctionDeclaration | ts.ArrowFunction,
context: Context
context: Context,
): BaseType {
if (this.functions === "hide") {
return new NeverType();
Expand All @@ -47,7 +47,7 @@ export function getNamedArguments(
| ts.FunctionDeclaration
| ts.ArrowFunction
| ts.ConstructorTypeNode,
context: Context
context: Context,
) {
if (node.parameters.length === 0) {
return undefined;
Expand All @@ -66,7 +66,7 @@ export function getNamedArguments(

return new ObjectProperty(node.parameters[index].name.getText(), parameterType, required);
}),
false
false,
);
}

Expand All @@ -76,7 +76,7 @@ export function getTypeName(
| ts.FunctionExpression
| ts.FunctionDeclaration
| ts.ArrowFunction
| ts.ConstructorTypeNode
| ts.ConstructorTypeNode,
): string | undefined {
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node) || ts.isFunctionTypeNode(node)) {
const parent = node.parent;
Expand Down
6 changes: 3 additions & 3 deletions src/NodeParser/IndexedAccessTypeNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getTypeByKey } from "../Utils/typeKeys.js";
export class IndexedAccessTypeNodeParser implements SubNodeParser {
public constructor(
protected typeChecker: ts.TypeChecker,
protected childNodeParser: NodeParser
protected childNodeParser: NodeParser,
) {}

public supportsNode(node: ts.TypeNode): boolean {
Expand All @@ -36,7 +36,7 @@ export class IndexedAccessTypeNodeParser implements SubNodeParser {
ts.isPropertySignature(m) &&
Boolean(m.type) &&
ts.isIdentifier(m.name) &&
m.name.text === indexType.getValue()
m.name.text === indexType.getValue(),
);

return member && this.childNodeParser.createType(member.type, context);
Expand All @@ -62,7 +62,7 @@ export class IndexedAccessTypeNodeParser implements SubNodeParser {
const propertyTypes = indexTypes.map((type) => {
if (!(type instanceof LiteralType || type instanceof StringType || type instanceof NumberType)) {
throw new LogicError(
`Unexpected type "${type.getId()}" (expected "LiteralType.js" or "StringType.js" or "NumberType.js")`
`Unexpected type "${type.getId()}" (expected "LiteralType.js" or "StringType.js" or "NumberType.js")`,
);
}

Expand Down
Loading
Loading