Skip to content

Commit 11aaa63

Browse files
committed
style: format files following linter rules
1 parent 88945bf commit 11aaa63

39 files changed

+1421
-1653
lines changed

.github/workflows/greetings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ jobs:
1010
continue-on-error: true
1111
with:
1212
repo-token: ${{ secrets.GITHUB_TOKEN }}
13-
issue-message: "Thank you for collaborating with the project by giving us feedback!"
14-
pr-message: "Thank you for collaborating with the project to help us improve! We hope this CLI is useful to you. Cheers!"
13+
issue-message: 'Thank you for collaborating with the project by giving us feedback!'
14+
pr-message: 'Thank you for collaborating with the project to help us improve! We hope this CLI is useful to you. Cheers!'

jest.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
preset: "ts-jest",
3-
testEnvironment: "node",
4-
rootDir: "./",
5-
roots: ["<rootDir>/src/"],
6-
coverageReporters: ["clover", "json", "lcov", "text", "text-summary"],
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
rootDir: './',
5+
roots: ['<rootDir>/src/'],
6+
coverageReporters: ['clover', 'json', 'lcov', 'text', 'text-summary'],
77
};

src/client/index.ts

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,28 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
6-
import { writeOutputFile, log } from "../helpers";
7-
import { cleanComponents, getUsedComponents } from "../helpers/usedComponents";
8-
import { DataObject } from "../types";
6+
import { writeOutputFile, log } from '../helpers';
7+
import { cleanComponents, getUsedComponents } from '../helpers/usedComponents';
8+
import { DataObject } from '../types';
99

1010
export const generateClientCode = (
11-
data: DataObject,
12-
angular: boolean = false,
13-
javascript: boolean = false,
14-
outputDir: string = "output",
15-
tagname: string = "custom",
16-
fileComments: string = ""
11+
data: DataObject,
12+
angular = false,
13+
javascript = false,
14+
outputDir = 'output',
15+
tagname = 'custom',
16+
fileComments = ''
1717
) => {
18-
log("Generating client code", "client");
18+
log('Generating client code', 'client');
1919

20-
const usedComponents = getUsedComponents(data).map((component: string) =>
21-
component.replace(/([^a-zA-Z]+)/g, "")
22-
);
23-
data.components = cleanComponents(data.components, usedComponents);
20+
const usedComponents = getUsedComponents(data).map((component: string) => component.replace(/([^a-zA-Z]+)/g, ''));
21+
data.components = cleanComponents(data.components, usedComponents);
2422

25-
if (javascript) {
26-
writeOutputFile(
27-
data,
28-
"javascriptClient",
29-
`${outputDir}/client`,
30-
tagname,
31-
tagname,
32-
fileComments,
33-
"js"
34-
);
35-
} else if (angular) {
36-
writeOutputFile(
37-
data,
38-
"angularClient",
39-
`${outputDir}/client`,
40-
`${tagname}.service`,
41-
tagname,
42-
fileComments,
43-
"ts"
44-
);
45-
} else {
46-
writeOutputFile(
47-
data,
48-
"client",
49-
`${outputDir}/client`,
50-
tagname,
51-
tagname,
52-
fileComments,
53-
"ts"
54-
);
55-
}
23+
if (javascript) {
24+
writeOutputFile(data, 'javascriptClient', `${outputDir}/client`, tagname, tagname, fileComments, 'js');
25+
} else if (angular) {
26+
writeOutputFile(data, 'angularClient', `${outputDir}/client`, `${tagname}.service`, tagname, fileComments, 'ts');
27+
} else {
28+
writeOutputFile(data, 'client', `${outputDir}/client`, tagname, tagname, fileComments, 'ts');
29+
}
5630
};

src/helpers/capitalize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
66
export const capitalize = (str: string): string => {
7-
const lowercase = str.toLowerCase();
8-
return str.charAt(0).toUpperCase() + lowercase.slice(1);
7+
const lowercase = str.toLowerCase();
8+
return str.charAt(0).toUpperCase() + lowercase.slice(1);
99
};

src/helpers/divideIntoDocumentsByTag.ts

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,64 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
*/
6-
import { EMPTY_TAG } from "../const";
7-
import { DataObject, FileObject, Method, Path } from "../types";
8-
import { parseDocument } from "./documentParser";
6+
import { EMPTY_TAG } from '../const';
7+
import { DataObject, FileObject, Method, Path } from '../types';
8+
import { parseDocument } from './documentParser';
99

1010
export function divideIntoDocumentsByTag(data: DataObject): FileObject[] {
11-
const tags: (string | undefined)[] = getAllTagsInDataObject(data);
11+
const tags: (string | undefined)[] = getAllTagsInDataObject(data);
1212

13-
const documentsByTag = tags.map((tag) => {
14-
const foundTagInfo = data.tags?.find(
15-
(item: { name: string; description: string }) => item.name === tag
16-
);
17-
return {
18-
tagName: tag,
19-
document: generatesDocumentByTag(data, tag),
20-
description: foundTagInfo?.description || undefined,
21-
};
22-
});
13+
const documentsByTag = tags.map((tag) => {
14+
const foundTagInfo = data.tags?.find((item: { name: string; description: string }) => item.name === tag);
15+
return {
16+
tagName: tag,
17+
document: generatesDocumentByTag(data, tag),
18+
description: foundTagInfo?.description || undefined,
19+
};
20+
});
2321

24-
return documentsByTag;
22+
return documentsByTag;
2523
}
2624

2725
function getAllTagsInDataObject(data: DataObject): (string | undefined)[] {
28-
const tags: (string | undefined)[] = [];
29-
Object.keys(data.paths)
30-
.map((path) => data.paths[path])
31-
.map((operations) => {
32-
return Object.keys(operations)
33-
.map((operationKey) => operations[operationKey])
34-
.forEach((method: Method) => {
35-
if (!method.tags) {
36-
if (!tags.includes(EMPTY_TAG)) {
37-
tags.push(EMPTY_TAG);
38-
}
39-
}
40-
method.tags &&
41-
method.tags.forEach((tag: string) => {
42-
if (!tags.includes(tag)) {
43-
tags.push(tag);
44-
}
45-
});
46-
});
47-
});
48-
return tags;
26+
const tags: (string | undefined)[] = [];
27+
Object.keys(data.paths)
28+
.map((path) => data.paths[path])
29+
.map((operations) => {
30+
return Object.keys(operations)
31+
.map((operationKey) => operations[operationKey])
32+
.forEach((method: Method) => {
33+
if (!method.tags) {
34+
if (!tags.includes(EMPTY_TAG)) {
35+
tags.push(EMPTY_TAG);
36+
}
37+
}
38+
method.tags &&
39+
method.tags.forEach((tag: string) => {
40+
if (!tags.includes(tag)) {
41+
tags.push(tag);
42+
}
43+
});
44+
});
45+
});
46+
return tags;
4947
}
5048

51-
function generatesDocumentByTag(
52-
data: DataObject,
53-
tag: string | undefined
54-
): DataObject {
55-
const document = parseDocument(JSON.parse(JSON.stringify(data)));
56-
document.paths = document.paths
57-
.filter((path: Path) => {
58-
if (tag === EMPTY_TAG) {
59-
return path.methods.filter((method: Method) => !method.tags).length > 0;
60-
}
61-
return (
62-
path.methods.filter(
63-
(method: Method) => method.tags && method.tags.includes(tag)
64-
).length > 0
65-
);
66-
})
67-
.map((path: Path) => ({
68-
...path,
69-
methods:
70-
tag === EMPTY_TAG
71-
? path.methods.filter((method: Method) => !method.tags)
72-
: path.methods.filter(
73-
(method: Method) => method.tags && method.tags.includes(tag)
74-
),
75-
}));
76-
return document;
49+
function generatesDocumentByTag(data: DataObject, tag: string | undefined): DataObject {
50+
const document = parseDocument(JSON.parse(JSON.stringify(data)));
51+
document.paths = document.paths
52+
.filter((path: Path) => {
53+
if (tag === EMPTY_TAG) {
54+
return path.methods.filter((method: Method) => !method.tags).length > 0;
55+
}
56+
return path.methods.filter((method: Method) => method.tags && method.tags.includes(tag)).length > 0;
57+
})
58+
.map((path: Path) => ({
59+
...path,
60+
methods:
61+
tag === EMPTY_TAG
62+
? path.methods.filter((method: Method) => !method.tags)
63+
: path.methods.filter((method: Method) => method.tags && method.tags.includes(tag)),
64+
}));
65+
return document;
7766
}

0 commit comments

Comments
 (0)