Skip to content

Commit 48180b8

Browse files
feat: correct few eslint warnings and disable some rules (for now) (#55)
* feat: correct few eslint warnings and disable some rules (for now) * 🤖 Documentation auto-update --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b05b153 commit 48180b8

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Parameters:
149149
- `params.inputFiles`: The list of files to scan and for which the documentation should be build.
150150
- `params.options`: Optional compiler options to generate the docs
151151

152-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/docs.ts#L482)
152+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/docs.ts#L477)
153153

154154
### :gear: documentationToMarkdown
155155

@@ -164,7 +164,7 @@ Parameters:
164164
- `params.entries`: The entries of the documentation (functions, constants and classes).
165165
- `params.options`: Optional configuration to render the Markdown content. See `types.ts` for details.
166166

167-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/markdown.ts#L293)
167+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/markdown.ts#L296)
168168

169169
### :gear: generateDocumentation
170170

eslint.config.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ export default [
2929

3030
{
3131
rules: {
32+
complexity: 'off',
3233
'@typescript-eslint/naming-convention': 'off',
33-
complexity: 'off'
34+
'@typescript-eslint/no-magic-numbers': 'off',
35+
'@typescript-eslint/no-unsafe-type-assertion': 'off',
36+
'@typescript-eslint/strict-boolean-expressions': 'off',
37+
'@typescript-eslint/no-unnecessary-condition': 'off',
38+
'@typescript-eslint/no-non-null-assertion': 'off'
3439
}
3540
}
3641
];

src/lib/docs.ts

+23-28
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import type {
44
CompilerOptions,
55
Declaration,
66
EnumDeclaration,
7-
FunctionDeclaration,
87
Node,
9-
PropertyName,
108
Signature,
119
SourceFile,
1210
TypeChecker,
1311
Symbol as TypeScriptSymbol,
14-
VariableDeclaration,
15-
VariableStatement
12+
VariableDeclaration
1613
} from 'typescript';
1714
import {
1815
ModifierFlags,
@@ -49,15 +46,13 @@ const serializeSymbol = ({
4946
checker: TypeChecker;
5047
symbol: TypeScriptSymbol;
5148
doc_type?: DocEntryType;
52-
}): DocEntry => {
53-
return {
54-
name: symbol.getName(),
55-
documentation: displayPartsToString(symbol.getDocumentationComment(checker)),
56-
type: checker.typeToString(checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration!)),
57-
jsDocs: symbol.getJsDocTags(),
58-
...(doc_type && {doc_type})
59-
};
60-
};
49+
}): DocEntry => ({
50+
name: symbol.getName(),
51+
documentation: displayPartsToString(symbol.getDocumentationComment(checker)),
52+
type: checker.typeToString(checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration!)),
53+
jsDocs: symbol.getJsDocTags(),
54+
...(doc_type !== undefined && {doc_type})
55+
});
6156

6257
const serializeEnum = ({
6358
checker,
@@ -80,7 +75,7 @@ const serializeEnum = ({
8075
return {
8176
name: member.name.getText(),
8277
...(type !== undefined && {type}),
83-
...(documentation !== undefined && documentation !== '' && {documentation})
78+
...(documentation !== '' && {documentation})
8479
};
8580
});
8681

@@ -149,7 +144,7 @@ const serializeSignature = ({
149144
documentation: displayPartsToString(signature.getDocumentationComment(checker))
150145
};
151146

152-
if (!!signature.declaration && 'modifiers' in signature.declaration) {
147+
if (!(signature.declaration == null) && 'modifiers' in signature.declaration) {
153148
return {
154149
...result,
155150
visibility:
@@ -219,7 +214,7 @@ const getRootParentName = (node: Node): string | undefined => {
219214
};
220215

221216
const isRootOrClassLevelArrowFunction = (node: Node): boolean => {
222-
const parent = node.parent;
217+
const {parent} = node;
223218

224219
if (!parent) {
225220
return false;
@@ -266,7 +261,7 @@ const visit = ({
266261

267262
const entries: DocEntry[] = [];
268263

269-
const pushEntry = ({details, node}: {details: DocEntry; node: Node}) => {
264+
const pushEntry = ({details, node}: {details: DocEntry; node: Node}): void => {
270265
entries.push({
271266
...details,
272267
...buildSource({
@@ -284,7 +279,7 @@ const visit = ({
284279
symbol: TypeScriptSymbol | undefined;
285280
doc_type: DocEntryType;
286281
node: Node;
287-
}) => {
282+
}): void => {
288283
if (!symbol) {
289284
return;
290285
}
@@ -308,11 +303,11 @@ const visit = ({
308303
})
309304
};
310305

311-
const visitChild = (node: Node) => {
306+
const visitChild = (node: Node): void => {
312307
const docEntries: DocEntry[] = visit({node, checker, types, ...rest});
313308

314309
// We do not need to repeat the file name for class members
315-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
310+
316311
const omitFilename = ({fileName: _, ...rest}: DocEntry): Omit<DocEntry, 'fileName'> => rest;
317312

318313
classEntry.methods?.push(
@@ -331,7 +326,7 @@ const visit = ({
331326
entries.push(classEntry);
332327
}
333328
} else if (isModuleDeclaration(node)) {
334-
const visitChild = (node: Node) => {
329+
const visitChild = (node: Node): void => {
335330
const docEntries: DocEntry[] = visit({node, checker, types, ...rest});
336331
entries.push(...docEntries);
337332
};
@@ -342,7 +337,7 @@ const visit = ({
342337
const symbol = checker.getSymbolAtLocation(node.name);
343338
addDocEntry({symbol, doc_type: 'method', node});
344339
} else if (isFunctionDeclaration(node)) {
345-
const symbol = checker.getSymbolAtLocation((node as FunctionDeclaration).name ?? node);
340+
const symbol = checker.getSymbolAtLocation(node.name ?? node);
346341
addDocEntry({symbol, doc_type: 'function', node});
347342
} else {
348343
const arrowFunc: Node | undefined = findDescendantArrowFunction(node);
@@ -374,14 +369,14 @@ const visit = ({
374369
} else if (isVariableStatement(node)) {
375370
const {
376371
declarationList: {declarations, flags}
377-
} = node as VariableStatement;
372+
} = node;
378373

379374
// https://stackoverflow.com/a/69801125/5404186
380375
const isConst = (flags & NodeFlags.Const) !== 0;
381376

382377
if (isConst) {
383378
// TODO: not sure what's the proper casting, VariableDeclaration does not contain Symbol but the test entity effectively does
384-
const symbol = (declarations[0] as unknown as {symbol: TypeScriptSymbol}).symbol;
379+
const {symbol} = declarations[0] as unknown as {symbol: TypeScriptSymbol};
385380
addDocEntry({symbol, doc_type: 'const', node});
386381
}
387382
} else if (types && isInterfaceDeclaration(node)) {
@@ -393,9 +388,9 @@ const visit = ({
393388
(member) =>
394389
isPropertySignature(member) && member.name !== undefined && isIdentifier(member.name)
395390
)
396-
.map((member) => checker.getSymbolAtLocation(member.name as PropertyName))
391+
.map((member) => checker.getSymbolAtLocation(member.name!))
397392
.filter((symbol) => symbol !== undefined)
398-
.map((symbol) => serializeSymbol({checker, symbol: symbol as TypeScriptSymbol}));
393+
.map((symbol) => serializeSymbol({checker, symbol: symbol!}));
399394

400395
const interfaceEntry: DocEntry = {
401396
...serializeSymbol({checker, doc_type: 'interface', symbol}),
@@ -426,7 +421,7 @@ const visit = ({
426421
entries.push(typeEntry);
427422
}
428423
} else if (isEnumDeclaration(node)) {
429-
const symbol = checker.getSymbolAtLocation((node as EnumDeclaration).name)!;
424+
const symbol = checker.getSymbolAtLocation(node.name)!;
430425
const details = serializeEnum({checker, symbol});
431426
pushEntry({node, details});
432427
}
@@ -448,7 +443,7 @@ const buildSource = ({
448443
node,
449444
sourceFile
450445
}: Source & {node: Node}): Pick<DocEntry, 'url' | 'fileName'> => {
451-
const fileName = sourceFile.fileName;
446+
const {fileName} = sourceFile;
452447

453448
if (repo === undefined) {
454449
return {fileName};

src/lib/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const generateDocumentation = ({
3333
outputFile: string;
3434
markdownOptions?: MarkdownOptions;
3535
buildOptions?: BuildOptions;
36-
}) => {
36+
}): void => {
3737
const entries: DocEntry[] = buildDocumentation({
38-
inputFiles: inputFiles,
38+
inputFiles,
3939
options: buildOptions
4040
});
4141

@@ -46,7 +46,7 @@ export const generateDocumentation = ({
4646

4747
const regex = /(<!-- TSDOC_START -->)[\s\S]*?(<!-- TSDOC_END -->)$/gm;
4848

49-
if (!fileContent.match(regex)) {
49+
if (fileContent.match(regex) === null) {
5050
writeFileSync(outputFile, markdown, 'utf-8');
5151
return;
5252
}

src/lib/markdown.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import type {
77
MarkdownOptions
88
} from './types';
99

10-
type Params = {name: string; documentation: string};
10+
interface Params {
11+
name: string;
12+
documentation: string;
13+
}
1114

1215
type Row = Required<Pick<DocEntry, 'name' | 'type' | 'documentation'>> &
1316
Pick<DocEntry, 'url'> & {
@@ -51,14 +54,14 @@ const classesToMarkdown = ({
5154
({visibility}) => visibility === 'public'
5255
);
5356

54-
if (publicConstructors?.length) {
57+
if (publicConstructors.length > 0) {
5558
markdown.push(`${headingLevel}# Constructors\n`);
5659

5760
markdown.push(
5861
...publicConstructors.map(({parameters, documentation, visibility}) => {
5962
const docs: string[] = [`\`${visibility}\`${inlineDocParam(documentation)}\n`];
6063

61-
if (parameters?.length) {
64+
if ((parameters?.length ?? 0) > 0) {
6265
docs.push(`Parameters:\n`);
6366
docs.push(...inlineParams(toParams(parameters)));
6467
}
@@ -76,12 +79,12 @@ const classesToMarkdown = ({
7679

7780
// Explicitly do not pass repo to generate the source code link afterwards for the all block
7881
markdown.push(
79-
`${toMarkdown({
82+
toMarkdown({
8083
entries: methods ?? [],
8184
headingLevel: `${headingLevel}#`,
8285
docType: 'Method',
8386
emoji
84-
})}`
87+
})
8588
);
8689
}
8790

@@ -91,12 +94,12 @@ const classesToMarkdown = ({
9194

9295
// Explicitly do not pass repo to generate the source code link afterwards for the all block
9396
markdown.push(
94-
`${toMarkdown({
97+
toMarkdown({
9598
entries: properties ?? [],
9699
headingLevel: `${headingLevel}#`,
97100
docType: 'Property',
98101
emoji
99-
})}`
102+
})
100103
);
101104
}
102105

@@ -132,7 +135,7 @@ const interfacesToMarkdown = ({
132135
);
133136

134137
markdown.push(
135-
`| \`${name}\` | \`${parseType(type ?? '')}\` | ${documentation !== undefined && documentation !== '' ? `${parseType(documentation).replace(/\r?\n|\r/g, '')}` : ''}${jsDocsDescription.length > 0 ? ` ${parseType(jsDocsDescription.join(''))}` : ''} |`
138+
`| \`${name}\` | \`${parseType(type ?? '')}\` | ${documentation !== undefined && documentation !== '' ? parseType(documentation).replace(/\r?\n|\r/g, '') : ''}${jsDocsDescription.length > 0 ? ` ${parseType(jsDocsDescription.join(''))}` : ''} |`
136139
);
137140
});
138141

@@ -168,7 +171,7 @@ const toMarkdown = ({
168171
} & Pick<MarkdownOptions, 'emoji'>): string => {
169172
const jsDocsToParams = (jsDocs: JSDocTagInfo[]): Params[] => {
170173
const params: JSDocTagInfo[] = jsDocs.filter(({name}: JSDocTagInfo) => name === 'param');
171-
const texts: (SymbolDisplayPart[] | undefined)[] = params.map(({text}) => text);
174+
const texts: Array<SymbolDisplayPart[] | undefined> = params.map(({text}) => text);
172175

173176
const parts: SymbolDisplayPart[][] = texts.reduce(
174177
(acc: SymbolDisplayPart[][], values: SymbolDisplayPart[] | undefined) => {

0 commit comments

Comments
 (0)