Skip to content

Commit 0e87ba5

Browse files
Merge pull request #23 from ZashIn/feat/optional-empty-line
Feature optional empty line
2 parents 0775150 + 09f837a commit 0e87ba5

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@
7070
"default": "",
7171
"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."
7272
},
73+
"jsdoc-generator.emptyLineAfterHeader": {
74+
"type": "boolean",
75+
"default": "true",
76+
"description": "Add empty line after header (description, date, author)."
77+
},
78+
"jsdoc-generator.singleLineComments": {
79+
"type": "boolean",
80+
"default": "false",
81+
"description": "Generate single line comments (/** ... */) instead of always multiple lines."
82+
},
7383
"jsdoc-generator.includeTypes": {
7484
"type": "boolean",
7585
"default": "true",

src/JsdocBuilder.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ export class JsdocBuilder {
251251
}
252252
this.buildDate();
253253
this.buildAuthor();
254-
this.buildJsdocLine();
254+
if (getConfig('emptyLineAfterHeader', true)) {
255+
this.buildJsdocLine();
256+
}
255257
this.buildJsdocLine('constructor');
256258
this.buildJsdocModifiers(node.modifiers);
257259
await this.buildJsdocParameters(node.getFullText(), node.parameters);
@@ -455,7 +457,9 @@ export class JsdocBuilder {
455457
}
456458
this.buildDate();
457459
this.buildAuthor();
458-
this.buildJsdocLine();
460+
if (getConfig('emptyLineAfterHeader', true)) {
461+
this.buildJsdocLine();
462+
}
459463
}
460464

461465
/**
@@ -468,19 +472,19 @@ export class JsdocBuilder {
468472
* @param {?NodeType} type
469473
*/
470474
private async buildDescription(nodeText?: string, description?: string, type?: NodeType) {
471-
this.jsdoc.appendText(' * ');
472475
const placeholder = getConfig('descriptionPlaceholder', '');
473476
if (description) {
474-
this.jsdoc.appendText(this.sanitize(description));
477+
this.jsdoc.appendText(` * ${this.sanitize(description)}\n`);
475478
} else if (placeholder) {
479+
this.jsdoc.appendText(' * ');
476480
this.jsdoc.appendPlaceholder(placeholder);
481+
this.jsdoc.appendText('\n');
477482
} else if (nodeText && type) {
478483
const autoDescription = await GenerativeAPI.describeSnippet(nodeText, type);
479484
if (autoDescription) {
480-
this.jsdoc.appendText(this.sanitize(autoDescription));
485+
this.jsdoc.appendText(` * ${this.sanitize(autoDescription)}\n`);
481486
}
482487
}
483-
this.jsdoc.appendText('\n');
484488
}
485489

486490
/**
@@ -538,6 +542,9 @@ export class JsdocBuilder {
538542
if (this.jsdoc.value.startsWith('/**\n *\n') && (this.jsdoc.value.match(/\n/g) || []).length > 2) {
539543
this.jsdoc.value = this.jsdoc.value.substring(0, 4) + this.jsdoc.value.substring(7);
540544
}
545+
if (getConfig("singleLineComments", false)) {
546+
this.jsdoc.value = this.jsdoc.value.replace(/^\/\*\*\n \* ?(.*)\n$/, '/** $1');
547+
}
541548
this.jsdoc.appendText(' */\n');
542549
}
543550

src/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ interface Configuration {
100100
* @type {string}
101101
*/
102102
dateFormat: string;
103+
/**
104+
* Empty line after header.
105+
*
106+
* @type {string}
107+
*/
108+
emptyLineAfterHeader: boolean;
109+
/**
110+
* Generate single line comments instead of always multiple lines.
111+
*
112+
* @type {boolean}
113+
*/
114+
singleLineComments: boolean;
103115
/**
104116
* Whether to include types in JSDocs.
105117
*

0 commit comments

Comments
 (0)