Skip to content

Commit

Permalink
Merge pull request #23 from ZashIn/feat/optional-empty-line
Browse files Browse the repository at this point in the history
Feature optional empty line
  • Loading branch information
Crystal-Spider authored Jul 16, 2024
2 parents 0775150 + 09f837a commit 0e87ba5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
"default": "",
"description": "Fill in with any valid MomentJs format (either explicit or locale) to include the date tag.\nFormats can include time as well.\nLeave empty to disable."
},
"jsdoc-generator.emptyLineAfterHeader": {
"type": "boolean",
"default": "true",
"description": "Add empty line after header (description, date, author)."
},
"jsdoc-generator.singleLineComments": {
"type": "boolean",
"default": "false",
"description": "Generate single line comments (/** ... */) instead of always multiple lines."
},
"jsdoc-generator.includeTypes": {
"type": "boolean",
"default": "true",
Expand Down
19 changes: 13 additions & 6 deletions src/JsdocBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ export class JsdocBuilder {
}
this.buildDate();
this.buildAuthor();
this.buildJsdocLine();
if (getConfig('emptyLineAfterHeader', true)) {
this.buildJsdocLine();
}
this.buildJsdocLine('constructor');
this.buildJsdocModifiers(node.modifiers);
await this.buildJsdocParameters(node.getFullText(), node.parameters);
Expand Down Expand Up @@ -455,7 +457,9 @@ export class JsdocBuilder {
}
this.buildDate();
this.buildAuthor();
this.buildJsdocLine();
if (getConfig('emptyLineAfterHeader', true)) {
this.buildJsdocLine();
}
}

/**
Expand All @@ -468,19 +472,19 @@ export class JsdocBuilder {
* @param {?NodeType} type
*/
private async buildDescription(nodeText?: string, description?: string, type?: NodeType) {
this.jsdoc.appendText(' * ');
const placeholder = getConfig('descriptionPlaceholder', '');
if (description) {
this.jsdoc.appendText(this.sanitize(description));
this.jsdoc.appendText(` * ${this.sanitize(description)}\n`);
} else if (placeholder) {
this.jsdoc.appendText(' * ');
this.jsdoc.appendPlaceholder(placeholder);
this.jsdoc.appendText('\n');
} else if (nodeText && type) {
const autoDescription = await GenerativeAPI.describeSnippet(nodeText, type);
if (autoDescription) {
this.jsdoc.appendText(this.sanitize(autoDescription));
this.jsdoc.appendText(` * ${this.sanitize(autoDescription)}\n`);
}
}
this.jsdoc.appendText('\n');
}

/**
Expand Down Expand Up @@ -538,6 +542,9 @@ export class JsdocBuilder {
if (this.jsdoc.value.startsWith('/**\n *\n') && (this.jsdoc.value.match(/\n/g) || []).length > 2) {
this.jsdoc.value = this.jsdoc.value.substring(0, 4) + this.jsdoc.value.substring(7);
}
if (getConfig("singleLineComments", false)) {
this.jsdoc.value = this.jsdoc.value.replace(/^\/\*\*\n \* ?(.*)\n$/, '/** $1');
}
this.jsdoc.appendText(' */\n');
}

Expand Down
12 changes: 12 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ interface Configuration {
* @type {string}
*/
dateFormat: string;
/**
* Empty line after header.
*
* @type {string}
*/
emptyLineAfterHeader: boolean;
/**
* Generate single line comments instead of always multiple lines.
*
* @type {boolean}
*/
singleLineComments: boolean;
/**
* Whether to include types in JSDocs.
*
Expand Down

0 comments on commit 0e87ba5

Please sign in to comment.