Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 46ff9a5

Browse files
committed
chore: reformat with latest prettier
1 parent 0139bf8 commit 46ff9a5

13 files changed

+181
-179
lines changed

CHANGELOG.md

+17-21
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,36 @@ All notable changes to this project will be documented in this file. See [standa
44

55
### [3.0.1](https://github.com/KnisterPeter/react-to-typescript-definitions/compare/v3.0.0...v3.0.1) (2021-04-07)
66

7-
87
### Bug Fixes
98

10-
* handle nested string literal props ([46edf00](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/46edf00dc24c5e8dfd3dde44bf52fc2dd48950ff))
9+
- handle nested string literal props ([46edf00](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/46edf00dc24c5e8dfd3dde44bf52fc2dd48950ff))
1110

1211
## [3.0.0](https://github.com/KnisterPeter/react-to-typescript-definitions/compare/v2.0.0...v3.0.0) (2021-03-22)
1312

14-
1513
### ⚠ BREAKING CHANGES
1614

17-
* Drop support for node 8
15+
- Drop support for node 8
1816

1917
### Features
2018

21-
* parse files which uses optional chaining feature ([3432de8](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/3432de8a5d479572ff3fcd308e3e2ffb0bed0fce))
22-
19+
- parse files which uses optional chaining feature ([3432de8](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/3432de8a5d479572ff3fcd308e3e2ffb0bed0fce))
2320

2421
### Bug Fixes
2522

26-
* **deps:** update dependency dts-dom to v3.4.0 ([d87a65e](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/d87a65ecbe844ad78845abbf40afecd2d130a5b8))
27-
* **deps:** update dependency dts-dom to v3.5.0 ([1c87f5c](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/1c87f5ca6d1c1737db794818ac4802df248db534))
28-
* **deps:** update dependency dts-dom to v3.6.0 ([4aa8889](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/4aa8889383fa36d51f3e39e12f9e877fdb933f93))
29-
* **deps:** update dependency meow to v6.0.1 ([8967eb7](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/8967eb74d9e373204da2f5a668bb02f1150ead6b))
30-
* **deps:** update dependency meow to v6.1.0 ([8ce686d](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/8ce686d9ac95a710f912d8292fee2c437a7f6bcc))
31-
* correctly import pascalcase function ([686bd9f](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/686bd9fb328934cd65bca62eca003cb6592e180f))
32-
* **deps:** update dependency pascal-case to v3 ([ca6fecc](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/ca6fecc1fdfb09278aff0d12c0fa5c55e5ed8773))
33-
* correct usage of execa ([ccb4699](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/ccb469976184ee939d30641bd4d9817327785eeb))
34-
* **deps:** update dependency chalk to v3 ([963d6fc](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/963d6fc83bca1a05b2d76f2fa0fc05a2f09c5590))
35-
* **deps:** update dependency dts-dom to v3.3.0 ([49135b1](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/49135b1ac5b94b24446048f6acd1f3460a6debcd))
36-
* **deps:** update dependency meow to v6 ([435ae07](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/435ae078fdca10cac301335b0862a095959d7ac2))
37-
* **deps:** update dependency strip-ansi to v6 ([fd7e788](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/fd7e788361126a6945697e443e9309f1bec5e87c))
38-
39-
40-
* drop support for node 8 ([ca0a130](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/ca0a130d7814da3897118b57a301b81a271ccf9a))
23+
- **deps:** update dependency dts-dom to v3.4.0 ([d87a65e](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/d87a65ecbe844ad78845abbf40afecd2d130a5b8))
24+
- **deps:** update dependency dts-dom to v3.5.0 ([1c87f5c](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/1c87f5ca6d1c1737db794818ac4802df248db534))
25+
- **deps:** update dependency dts-dom to v3.6.0 ([4aa8889](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/4aa8889383fa36d51f3e39e12f9e877fdb933f93))
26+
- **deps:** update dependency meow to v6.0.1 ([8967eb7](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/8967eb74d9e373204da2f5a668bb02f1150ead6b))
27+
- **deps:** update dependency meow to v6.1.0 ([8ce686d](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/8ce686d9ac95a710f912d8292fee2c437a7f6bcc))
28+
- correctly import pascalcase function ([686bd9f](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/686bd9fb328934cd65bca62eca003cb6592e180f))
29+
- **deps:** update dependency pascal-case to v3 ([ca6fecc](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/ca6fecc1fdfb09278aff0d12c0fa5c55e5ed8773))
30+
- correct usage of execa ([ccb4699](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/ccb469976184ee939d30641bd4d9817327785eeb))
31+
- **deps:** update dependency chalk to v3 ([963d6fc](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/963d6fc83bca1a05b2d76f2fa0fc05a2f09c5590))
32+
- **deps:** update dependency dts-dom to v3.3.0 ([49135b1](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/49135b1ac5b94b24446048f6acd1f3460a6debcd))
33+
- **deps:** update dependency meow to v6 ([435ae07](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/435ae078fdca10cac301335b0862a095959d7ac2))
34+
- **deps:** update dependency strip-ansi to v6 ([fd7e788](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/fd7e788361126a6945697e443e9309f1bec5e87c))
35+
36+
- drop support for node 8 ([ca0a130](https://github.com/KnisterPeter/react-to-typescript-definitions/commit/ca0a130d7814da3897118b57a301b81a271ccf9a))
4137

4238
## [2.0.0](https://github.com/KnisterPeter/react-to-typescript-definitions/compare/v1.2.0...v2.0.0) (2019-05-17)
4339

src/analyzer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function parsePropTypes(
4040
function getOptionalDocumentation(propertyNode: any): string {
4141
return (
4242
((propertyNode.leadingComments || []) as any[]).filter(
43-
comment => comment.type === 'CommentBlock'
43+
(comment) => comment.type === 'CommentBlock'
4444
)[0] || {}
4545
).value;
4646
}
@@ -55,7 +55,7 @@ export function getTypeFromPropType(
5555
): IProp {
5656
const result: IProp = {
5757
type: 'any',
58-
optional: true
58+
optional: true,
5959
};
6060
if (isNode(node)) {
6161
const { isRequired, type } = isRequiredPropType(node, instanceOfResolver);
@@ -133,7 +133,7 @@ function getReactPropTypeFromExpression(
133133
return {
134134
name: 'instanceOf',
135135
type: node.arguments[0].name,
136-
importPath: instanceOfResolver(node.arguments[0].name)
136+
importPath: instanceOfResolver(node.arguments[0].name),
137137
};
138138
case 'arrayOf':
139139
const arrayType = getTypeFromPropType(
@@ -142,15 +142,15 @@ function getReactPropTypeFromExpression(
142142
);
143143
return {
144144
name: 'array',
145-
arrayType: arrayType.type
145+
arrayType: arrayType.type,
146146
};
147147
case 'oneOfType':
148148
const unionTypes = node.arguments[0].elements.map((element: IASTNode) =>
149149
getTypeFromPropType(element, instanceOfResolver)
150150
);
151151
return {
152152
name: 'union',
153-
types: unionTypes.map((type: any) => type.type)
153+
types: unionTypes.map((type: any) => type.type),
154154
};
155155
}
156156
}
@@ -168,6 +168,6 @@ function isRequiredPropType(
168168
type: getReactPropTypeFromExpression(
169169
isRequired ? node.object : node,
170170
instanceOfResolver
171-
)
171+
),
172172
};
173173
}

src/deprecated.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { InstanceOfResolver, IOptions } from './index';
55

66
export enum ExportType {
77
default,
8-
named
8+
named,
99
}
1010

1111
// tslint:disable:next-line interface-name
@@ -44,7 +44,7 @@ function deprecatedGenerator(
4444
const generateTypings = () => {
4545
generator.import('* as React', 'react');
4646
if (propTypes) {
47-
Object.keys(propTypes).forEach(propName => {
47+
Object.keys(propTypes).forEach((propName) => {
4848
const prop = propTypes[propName];
4949
if (prop.importPath) {
5050
generator.import(prop.type, prop.importPath);
@@ -146,7 +146,7 @@ function parseAst(
146146
exportType,
147147
classname,
148148
functionname,
149-
propTypes: propTypes || {}
149+
propTypes: propTypes || {},
150150
};
151151
}
152152

src/generator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Generator {
4343

4444
public props(name: string, props: IPropTypes, fn?: () => void): void {
4545
this.interface(`${name}Props`, () => {
46-
Object.keys(props).forEach(propName => {
46+
Object.keys(props).forEach((propName) => {
4747
const prop = props[propName];
4848
this.prop(propName, prop.type, prop.optional, prop.documentation);
4949
});

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ export function generateFromSource(
133133
'functionBind',
134134
'functionSent',
135135
'optionalChaining',
136-
...additionalBabylonPlugins
137-
]
136+
...additionalBabylonPlugins,
137+
],
138138
});
139139
if (!options.source) {
140140
options.source = code;

src/types.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IOptions } from './index';
55
import {
66
AstQuery,
77
ImportedPropTypes,
8-
propTypeQueryExpression
8+
propTypeQueryExpression,
99
} from './typings';
1010

1111
export interface TypeDeclaration {
@@ -16,7 +16,7 @@ export interface TypeDeclaration {
1616
function getTypeDeclaration(type: any, optional: boolean): TypeDeclaration {
1717
return {
1818
type,
19-
optional
19+
optional,
2020
};
2121
}
2222

@@ -50,7 +50,7 @@ export function get(
5050
}
5151
return {
5252
type: 'any',
53-
optional: true
53+
optional: true,
5454
};
5555
}
5656

@@ -80,7 +80,7 @@ function getSimpleType(
8080
'args',
8181
dom.create.array('any'),
8282
dom.ParameterFlags.Rest
83-
)
83+
),
8484
],
8585
'any'
8686
),
@@ -136,7 +136,7 @@ function getComplexType(
136136
get(ast, subtree, importedPropTypes, options)
137137
) as TypeDeclaration[];
138138
return getTypeDeclaration(
139-
dom.create.union(typeDecls.map(type => type.type)),
139+
dom.create.union(typeDecls.map((type) => type.type)),
140140
!required
141141
);
142142
case 'arrayOf':
@@ -160,7 +160,9 @@ function getComplexType(
160160
(entry: any) => {
161161
const typeDecl = get(ast, entry.value, importedPropTypes, options);
162162
return dom.create.property(
163-
entry.key.type === 'StringLiteral' ? `${entry.key.value}` : entry.key.name,
163+
entry.key.type === 'StringLiteral'
164+
? `${entry.key.value}`
165+
: entry.key.name,
164166
typeDecl.type,
165167
typeDecl.optional
166168
? dom.DeclarationFlags.Optional

src/typings.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ export function createTypings(
3737
},
3838
querySubtree(subtree: any, query: string): any[] {
3939
return astq.query(subtree, query);
40-
}
40+
},
4141
};
4242
const reactComponentName = getReactComponentName(ast);
4343
const importedPropTypes: ImportedPropTypes = {
4444
propTypesName: getPropTypesName(ast),
45-
propTypes: getImportedPropTypes(ast)
45+
propTypes: getImportedPropTypes(ast),
4646
};
4747
const importedTypes = getInstanceOfPropTypes(ast, importedPropTypes);
4848
const importStatements = getImportStatements(
@@ -53,15 +53,15 @@ export function createTypings(
5353
const componentNames = getUniqueNames([
5454
...getComponentNamesByPropTypeAssignment(ast),
5555
...getComponentNamesByStaticPropTypeAttribute(ast),
56-
...getComponentNamesByJsxInBody(ast)
56+
...getComponentNamesByJsxInBody(ast),
5757
]);
5858
const tripleSlashDirectives: dom.TripleSlashDirective[] = [];
5959
const m = dom.create.module(moduleName || 'moduleName');
6060

6161
m.members.push(dom.create.importAll('React', reactImport));
6262

6363
if (importStatements.length > 0) {
64-
importStatements.forEach(importStatement => {
64+
importStatements.forEach((importStatement) => {
6565
if (importStatement.name === undefined) {
6666
m.members.push(
6767
dom.create.importDefault(importStatement.local, importStatement.path)
@@ -71,7 +71,7 @@ export function createTypings(
7171
}
7272
});
7373
}
74-
componentNames.forEach(componentName => {
74+
componentNames.forEach((componentName) => {
7575
const exportType = getComponentExportType(ast, componentName);
7676
const propTypes = getPropTypes(ast, componentName);
7777
if (exportType) {
@@ -89,7 +89,7 @@ export function createTypings(
8989
});
9090

9191
if (moduleName === null) {
92-
return m.members.map(member => dom.emit(member)).join('');
92+
return m.members.map((member) => dom.emit(member)).join('');
9393
} else {
9494
return dom.emit(m, { tripleSlashDirectives });
9595
}
@@ -196,7 +196,7 @@ function createPropTypeTypings(
196196
/ ObjectProperty
197197
`
198198
);
199-
res.forEach(propertyAst => {
199+
res.forEach((propertyAst) => {
200200
const typeDecl = types.get(
201201
ast,
202202
propertyAst.value,
@@ -217,9 +217,9 @@ function createPropTypeTypings(
217217
};
218218
property.jsDocComment = (propertyAst.leadingComments[0].value as string)
219219
.split('\n')
220-
.map(line => line.trim())
221-
.map(line => line.replace(/^\*\*?/, ''))
222-
.map(line => line.trim())
220+
.map((line) => line.trim())
221+
.map((line) => line.replace(/^\*\*?/, ''))
222+
.map((line) => line.trim())
223223
.filter(trimLines())
224224
.reverse()
225225
.filter(trimLines())
@@ -235,7 +235,7 @@ function extractComplexTypes(
235235
interf: dom.InterfaceDeclaration,
236236
componentName: string
237237
): void {
238-
interf.members.forEach(member => {
238+
interf.members.forEach((member) => {
239239
if (member.kind === 'property' && isExtractableType(member.type)) {
240240
const name = `${componentName}${pascalCase(member.name)}`;
241241
const extractedMember = createModuleMember(name, member.type);
@@ -371,7 +371,7 @@ function getImportedPropTypes(ast: AstQuery): ImportedPropType[] {
371371
)
372372
.map(({ imported, local }) => ({
373373
importedName: imported.name,
374-
localName: local.name
374+
localName: local.name,
375375
}));
376376
}
377377

@@ -400,7 +400,7 @@ function getInstanceOfPropTypes(
400400
/:arguments *
401401
`);
402402

403-
return res.map(identifer => identifer.name);
403+
return res.map((identifer) => identifer.name);
404404
}
405405

406406
interface ImportStatement {
@@ -414,7 +414,7 @@ function getImportStatements(
414414
instanceOfResolver: InstanceOfResolver | undefined
415415
): ImportStatement[] {
416416
return typeNames
417-
.map(name => {
417+
.map((name) => {
418418
const res = ast.query(`
419419
// ImportDeclaration[
420420
/:specifiers * /:local Identifier[@name == '${name}']
@@ -426,10 +426,10 @@ function getImportStatements(
426426
? res[0].specifiers[0].imported.name
427427
: undefined,
428428
local: name,
429-
path: res.length > 0 ? res[0].source.value : undefined
429+
path: res.length > 0 ? res[0].source.value : undefined,
430430
};
431431
})
432-
.map(importStatement => {
432+
.map((importStatement) => {
433433
if (importStatement && instanceOfResolver) {
434434
const resolvedPath = importStatement.name
435435
? instanceOfResolver(importStatement.name)
@@ -440,7 +440,7 @@ function getImportStatements(
440440
}
441441
return importStatement;
442442
})
443-
.filter(importStatement => Boolean(importStatement.path));
443+
.filter((importStatement) => Boolean(importStatement.path));
444444
}
445445

446446
function getComponentNamesByPropTypeAssignment(ast: AstQuery): string[] {
@@ -452,7 +452,7 @@ function getComponentNamesByPropTypeAssignment(ast: AstQuery): string[] {
452452
]
453453
`);
454454
if (res.length > 0) {
455-
return res.map(match => match.object.name);
455+
return res.map((match) => match.object.name);
456456
}
457457
return [];
458458
}
@@ -464,7 +464,7 @@ function getComponentNamesByStaticPropTypeAttribute(ast: AstQuery): string[] {
464464
]
465465
`);
466466
if (res.length > 0) {
467-
return res.map(match => (match.id ? match.id.name : ''));
467+
return res.map((match) => (match.id ? match.id.name : ''));
468468
}
469469
return [];
470470
}
@@ -483,7 +483,7 @@ function getComponentNamesByJsxInBody(ast: AstQuery): string[] {
483483
]
484484
`);
485485
if (res.length > 0) {
486-
return res.map(match => (match.id ? match.id.name : ''));
486+
return res.map((match) => (match.id ? match.id.name : ''));
487487
}
488488
return [];
489489
}

tests/cli-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function normalize(input: string): string {
77
return input.replace(/\s+/g, ' ').replace(/ => /g, '=>');
88
}
99

10-
test('cli should read from stdin', async t => {
10+
test('cli should read from stdin', async (t) => {
1111
const expected = fs
1212
.readFileSync('./tests/import-react-component.d.ts')
1313
.toString();
@@ -20,7 +20,7 @@ test('cli should read from stdin', async t => {
2020
t.is(normalize(result.stdout), normalize(expected));
2121
});
2222

23-
test('cli should read from file', async t => {
23+
test('cli should read from file', async (t) => {
2424
const expected = fs
2525
.readFileSync('./tests/import-react-component.d.ts')
2626
.toString();

tests/error-reporting-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Args = { args: any[] };
77
const originalConsoleError = console.error;
88

99
test.beforeEach((t: ExecutionContext<Args>) => {
10-
console.error = function(...args: any[]): void {
10+
console.error = function (...args: any[]): void {
1111
if (!t.context.args) {
1212
t.context.args = [];
1313
}

0 commit comments

Comments
 (0)