Skip to content

Commit

Permalink
Completely disable JsDoc if ignoreDescription is active.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaster11 committed Dec 11, 2023
1 parent 9851f2b commit fb0996e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/__tests__/description/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ export interface ExampleLong {
another: string;
}
/**
* IgnoreDescription
*/
export interface IgnoreDescription {
/**
* thing
Expand All @@ -78,9 +75,6 @@ export interface IgnoreDescriptionObject {
* withoutDescription
*/
withoutDescription?: {
/**
* [x: string]
*/
[x: string]: Example;
};
}
Expand Down
14 changes: 10 additions & 4 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { filterMap, isDescribe, toStringLiteral } from './utils';
import { TypeContent, makeTypeContentRoot, makeTypeContentChild, Settings, JsDoc } from './types';
import { JsDoc, makeTypeContentChild, makeTypeContentRoot, Settings, TypeContent } from './types';
import {
AlternativesDescribe,
ArrayDescribe,
Expand Down Expand Up @@ -31,12 +31,12 @@ function getCommonDetails(
): { interfaceOrTypeName?: string; jsDoc: JsDoc; required: boolean; value?: unknown; isReadonly?: boolean } {
const interfaceOrTypeName = getInterfaceOrTypeName(settings, details);

const ignoreDescription = getIgnoreDescription(details);
const description = ignoreDescription ? undefined : details.flags?.description;
const description = details.flags?.description;
const presence = details.flags?.presence;
const value = details.flags?.default;
const example = details.examples?.[0];
const isReadonly = getIsReadonly(details);
const disableJsDoc = getIgnoreDescription(details);

let required;
if (
Expand All @@ -49,7 +49,13 @@ function getCommonDetails(
} else {
required = settings.defaultToRequired;
}
return { interfaceOrTypeName, jsDoc: { description, example }, required, value, isReadonly };
return {
interfaceOrTypeName,
jsDoc: { description, example, disable: disableJsDoc },
required,
value,
isReadonly
};
}

export function getAllCustomTypes(parsedSchema: TypeContent): string[] {
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,8 @@ export interface JsDoc {
* @example example value
*/
example?: string;
/**
* If true, completely disables printing JsDoc
*/
disable?: boolean;
}
14 changes: 10 additions & 4 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { writeFileSync } from 'fs';
import Path from 'path';

import { Settings, JsDoc } from './types';
import { JsDoc, Settings } from './types';

/**
* Write index.ts file
Expand All @@ -23,9 +23,11 @@ export function writeIndexFile(settings: Settings, fileNamesToExport: string[]):
}

export function getTypeFileNameFromSchema(schemaFileName: string, settings: Settings): string {
return (schemaFileName.endsWith(`${settings.schemaFileSuffix}.ts`)
? schemaFileName.substring(0, schemaFileName.length - `${settings.schemaFileSuffix}.ts`.length)
: schemaFileName.replace('.ts', '')) + settings.interfaceFileSuffix;
return (
(schemaFileName.endsWith(`${settings.schemaFileSuffix}.ts`)
? schemaFileName.substring(0, schemaFileName.length - `${settings.schemaFileSuffix}.ts`.length)
: schemaFileName.replace('.ts', '')) + settings.interfaceFileSuffix
);
}

/**
Expand All @@ -41,6 +43,10 @@ export function getIndentStr(settings: Settings, indentLevel: number): string {
* Get Interface jsDoc
*/
export function getJsDocString(settings: Settings, name: string, jsDoc?: JsDoc, indentLevel = 0): string {
if (jsDoc?.disable == true) {
return '';
}

if (!settings.commentEverything && !jsDoc?.description && !jsDoc?.example) {
return '';
}
Expand Down

0 comments on commit fb0996e

Please sign in to comment.