Skip to content

Commit 0923771

Browse files
authored
Merge pull request microsoft#26029 from tschaub/fix-25916
Remove trailing whitespace from JSDoc comments
2 parents 25fb541 + 960800d commit 0923771

20 files changed

+71
-64
lines changed

src/compiler/parser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6400,7 +6400,7 @@ namespace ts {
64006400
switch (token()) {
64016401
case SyntaxKind.AtToken:
64026402
if (state === JSDocState.BeginningOfLine || state === JSDocState.SawAsterisk) {
6403-
removeTrailingNewlines(comments);
6403+
removeTrailingWhitespace(comments);
64046404
addTag(parseTag(indent));
64056405
// NOTE: According to usejsdoc.org, a tag goes to end of line, except the last tag.
64066406
// Real-world comments may break this rule, so "BeginningOfLine" will not be a real line beginning
@@ -6460,7 +6460,7 @@ namespace ts {
64606460
nextJSDocToken();
64616461
}
64626462
removeLeadingNewlines(comments);
6463-
removeTrailingNewlines(comments);
6463+
removeTrailingWhitespace(comments);
64646464
return createJSDocComment();
64656465
});
64666466

@@ -6470,8 +6470,8 @@ namespace ts {
64706470
}
64716471
}
64726472

6473-
function removeTrailingNewlines(comments: string[]) {
6474-
while (comments.length && (comments[comments.length - 1] === "\n" || comments[comments.length - 1] === "\r")) {
6473+
function removeTrailingWhitespace(comments: string[]) {
6474+
while (comments.length && comments[comments.length - 1].trim() === "") {
64756475
comments.pop();
64766476
}
64776477
}
@@ -6632,7 +6632,7 @@ namespace ts {
66326632
}
66336633

66346634
removeLeadingNewlines(comments);
6635-
removeTrailingNewlines(comments);
6635+
removeTrailingWhitespace(comments);
66366636
return comments.length === 0 ? undefined : comments.join("");
66376637
}
66386638

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.asteriskAfterPreamble.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"kind": "JSDocComment",
33
"pos": 0,
44
"end": 23,
5-
"comment": "* @type {number} "
5+
"comment": "* @type {number}"
66
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.threeAsterisks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"kind": "JSDocComment",
33
"pos": 0,
44
"end": 7,
5-
"comment": "* "
5+
"comment": "*"
66
}

tests/cases/fourslash/commentsCommentParsing.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,32 +208,32 @@ verify.quickInfoAt("1q", "function simple(): void");
208208
verify.signatureHelp({ marker: "2", docComment: "" });
209209
verify.quickInfoAt("2q", "function multiLine(): void");
210210

211-
verify.signatureHelp({ marker: "3", docComment: "this is eg of single line jsdoc style comment " });
212-
verify.quickInfoAt("3q", "function jsDocSingleLine(): void", "this is eg of single line jsdoc style comment ");
211+
verify.signatureHelp({ marker: "3", docComment: "this is eg of single line jsdoc style comment" });
212+
verify.quickInfoAt("3q", "function jsDocSingleLine(): void", "this is eg of single line jsdoc style comment");
213213

214214
verify.signatureHelp({ marker: "4", docComment: "this is multiple line jsdoc stule comment\nNew line1\nNew Line2" });
215215
verify.quickInfoAt("4q", "function jsDocMultiLine(): void", "this is multiple line jsdoc stule comment\nNew line1\nNew Line2");
216216

217217
verify.signatureHelp({ marker: "5", docComment: "this is multiple line jsdoc stule comment\nNew line1\nNew Line2\nShoul mege this line as well\nand this too\nAnother this one too" });
218218
verify.quickInfoAt("5q", "function jsDocMultiLineMerge(): void", "this is multiple line jsdoc stule comment\nNew line1\nNew Line2\nShoul mege this line as well\nand this too\nAnother this one too");
219219

220-
verify.signatureHelp({ marker: "6", docComment: "jsdoc comment " });
221-
verify.quickInfoAt("6q", "function jsDocMixedComments1(): void", "jsdoc comment ");
220+
verify.signatureHelp({ marker: "6", docComment: "jsdoc comment" });
221+
verify.quickInfoAt("6q", "function jsDocMixedComments1(): void", "jsdoc comment");
222222

223-
verify.signatureHelp({ marker: "7", docComment: "jsdoc comment \nanother jsDocComment" });
224-
verify.quickInfoAt("7q", "function jsDocMixedComments2(): void", "jsdoc comment \nanother jsDocComment");
223+
verify.signatureHelp({ marker: "7", docComment: "jsdoc comment\nanother jsDocComment" });
224+
verify.quickInfoAt("7q", "function jsDocMixedComments2(): void", "jsdoc comment\nanother jsDocComment");
225225

226-
verify.signatureHelp({ marker: "8", docComment: "jsdoc comment \n* triplestar jsDocComment" });
227-
verify.quickInfoAt("8q", "function jsDocMixedComments3(): void", "jsdoc comment \n* triplestar jsDocComment");
226+
verify.signatureHelp({ marker: "8", docComment: "jsdoc comment\n* triplestar jsDocComment" });
227+
verify.quickInfoAt("8q", "function jsDocMixedComments3(): void", "jsdoc comment\n* triplestar jsDocComment");
228228

229-
verify.signatureHelp({ marker: "9", docComment: "jsdoc comment \nanother jsDocComment" });
230-
verify.quickInfoAt("9q", "function jsDocMixedComments4(): void", "jsdoc comment \nanother jsDocComment");
229+
verify.signatureHelp({ marker: "9", docComment: "jsdoc comment\nanother jsDocComment" });
230+
verify.quickInfoAt("9q", "function jsDocMixedComments4(): void", "jsdoc comment\nanother jsDocComment");
231231

232-
verify.signatureHelp({ marker: "10", docComment: "jsdoc comment \nanother jsDocComment" });
233-
verify.quickInfoAt("10q", "function jsDocMixedComments5(): void", "jsdoc comment \nanother jsDocComment");
232+
verify.signatureHelp({ marker: "10", docComment: "jsdoc comment\nanother jsDocComment" });
233+
verify.quickInfoAt("10q", "function jsDocMixedComments5(): void", "jsdoc comment\nanother jsDocComment");
234234

235-
verify.signatureHelp({ marker: "11", docComment: "another jsDocComment\njsdoc comment " });
236-
verify.quickInfoAt("11q", "function jsDocMixedComments6(): void", "another jsDocComment\njsdoc comment ");
235+
verify.signatureHelp({ marker: "11", docComment: "another jsDocComment\njsdoc comment" });
236+
verify.quickInfoAt("11q", "function jsDocMixedComments6(): void", "another jsDocComment\njsdoc comment");
237237

238238
verify.signatureHelp({ marker: "12", docComment: "" });
239239
verify.quickInfoAt("12q", "function noHelpComment1(): void");
@@ -282,7 +282,7 @@ const multiplyTags: ReadonlyArray<FourSlashInterface.JSDocTagInfo> = [
282282
{ name: "param", text: "c" },
283283
{ name: "param", text: "d" },
284284
{ name: "anotherTag", text: undefined },
285-
{ name: "param", text: "e LastParam " },
285+
{ name: "param", text: "e LastParam" },
286286
{ name: "anotherTag", text: undefined },
287287
];
288288
verify.signatureHelp({ marker: "19", docComment: "This is multiplication function", parameterDocComment: "first number", tags: multiplyTags });
@@ -303,8 +303,8 @@ verify.quickInfoAt("21aq", "(parameter) c: number");
303303
verify.signatureHelp({ marker: "22", docComment: "This is multiplication function", tags: multiplyTags });
304304
verify.quickInfoAt("22aq", "(parameter) d: any");
305305

306-
verify.signatureHelp({ marker: "23", docComment: "This is multiplication function", parameterDocComment: "LastParam ", tags: multiplyTags });
307-
verify.quickInfoAt("23aq", "(parameter) e: any", "LastParam ");
306+
verify.signatureHelp({ marker: "23", docComment: "This is multiplication function", parameterDocComment: "LastParam", tags: multiplyTags });
307+
verify.quickInfoAt("23aq", "(parameter) e: any", "LastParam");
308308

309309
goTo.marker('24');
310310
verify.completionListContains("aOrb", "(parameter) aOrb: any", "");
@@ -420,7 +420,7 @@ verify.signatureHelp({ marker: "38", docComment: concatDoc, parameterDocComment:
420420
verify.quickInfoAt("38aq", "(parameter) bar: string", "is second string");
421421

422422
goTo.marker('39');
423-
verify.completionListContains("a", "(parameter) a: number", "this is inline comment for a \nit is first parameter");
423+
verify.completionListContains("a", "(parameter) a: number", "this is inline comment for a\nit is first parameter");
424424
verify.completionListContains("b", "(parameter) b: number", "this is inline comment for b");
425425
verify.completionListContains("c", "(parameter) c: number", "it is third parameter");
426426
verify.completionListContains("d", "(parameter) d: number", "");
@@ -430,15 +430,15 @@ const jsdocTestTags: ReadonlyArray<FourSlashInterface.JSDocTagInfo> = [
430430
{ name: "param", text: "a it is first parameter" },
431431
{ name: "param", text: "c it is third parameter" },
432432
];
433-
verify.signatureHelp({ marker: "40", docComment: jsdocTestDocComment, parameterDocComment: "this is inline comment for a \nit is first parameter", tags: jsdocTestTags });
433+
verify.signatureHelp({ marker: "40", docComment: jsdocTestDocComment, parameterDocComment: "this is inline comment for a\nit is first parameter", tags: jsdocTestTags });
434434
verify.quickInfos({
435435
"40q": [
436436
"function jsDocParamTest(a: number, b: number, c: number, d: number): number",
437437
jsdocTestDocComment
438438
],
439439
"40aq": [
440440
"(parameter) a: number",
441-
"this is inline comment for a \nit is first parameter"
441+
"this is inline comment for a\nit is first parameter"
442442
]
443443
});
444444

@@ -453,7 +453,7 @@ verify.quickInfoAt("43aq", "(parameter) d: number");
453453

454454
goTo.marker('44');
455455
verify.completionListContains("jsDocParamTest", "function jsDocParamTest(a: number, b: number, c: number, d: number): number", jsdocTestDocComment);
456-
verify.completionListContains("x", "var x: any", "This is a comment ");
456+
verify.completionListContains("x", "var x: any", "This is a comment");
457457
verify.completionListContains("y", "var y: any", "This is a comment");
458458

459459
verify.signatureHelp({ marker: "45", docComment: "This is function comment\nAnd properly aligned comment" });

tests/cases/fourslash/commentsFunctionExpression.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@ verify.signatureHelp(
6161
// no documentation from nested lambda
6262
verify.quickInfos({
6363
7: "function anotherFunc(a: number): string",
64-
8: ["(local var) lambdaVar: (b: string) => string", "inner docs \ndocumentation"],
65-
9: ["(parameter) b: string", "inner parameter "],
64+
8: ["(local var) lambdaVar: (b: string) => string", "inner docs\ndocumentation"],
65+
9: ["(parameter) b: string", "inner parameter"],
6666
10: "(local var) localVar: string",
6767
11: "(local var) localVar: string",
68-
12: ["(parameter) b: string", "inner parameter "],
69-
13: ["(local var) lambdaVar: (b: string) => string", "inner docs \ndocumentation"],
68+
12: ["(parameter) b: string", "inner parameter"],
69+
13: ["(local var) lambdaVar: (b: string) => string", "inner docs\ndocumentation"],
7070
14: [
7171
"var assigned: (s: string) => number",
7272
"Summary on expression\nOn variable"
7373
]
7474
});
7575

7676
goTo.marker('15');
77-
verify.completionListContains('s', '(parameter) s: string', "On parameter \nparam on expression\nthe first parameter!");
77+
verify.completionListContains('s', '(parameter) s: string', "On parameter\nparam on expression\nthe first parameter!");
7878
verify.quickInfoAt("16", "var assigned: (s: string) => number", "Summary on expression\nOn variable");
7979
goTo.marker('17');
8080
verify.completionListContains("assigned", "var assigned: (s: string) => number", "Summary on expression\nOn variable");
8181
verify.signatureHelp({
8282
marker: "18",
8383
docComment: "Summary on expression\nOn variable",
84-
parameterDocComment: "On parameter \nparam on expression\nthe first parameter!",
84+
parameterDocComment: "On parameter\nparam on expression\nthe first parameter!",
8585
tags: [
8686
{ name: "param", text: "s param on expression" },
8787
{ name: "returns", text: "return on expression" },

tests/cases/fourslash/commentsLinePreservation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ verify.quickInfos({
141141
7: ["(parameter) param1: string", "param information first line\n\nparam information third line"],
142142

143143
k: ["function k(param1: string): void", "This is firstLine\nThis is second Line"],
144-
8: ["(parameter) param1: string", "hello "],
144+
8: ["(parameter) param1: string", "hello"],
145145

146146
l: ["function l(param1: string): void", "This is firstLine\nThis is second Line"],
147147
9: ["(parameter) param1: string", "first Line text\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"],

tests/cases/fourslash/completionForStringLiteral_details.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ goTo.marker("type");
2424
verify.completionListContains("a", "a", "", "string");
2525

2626
goTo.marker("prop");
27-
verify.completionListContains("x", "(property) I.x: number", "Prop doc ", "property");
28-
verify.completionListContains("m", "(method) I.m(): void", "Method doc ", "method");
27+
verify.completionListContains("x", "(property) I.x: number", "Prop doc", "property");
28+
verify.completionListContains("m", "(method) I.m(): void", "Method doc", "method");

tests/cases/fourslash/completionInJsDocQualifiedNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
////const x = 0;
1313

1414
goTo.marker();
15-
verify.completionListContains("T", "type T = number", "tee ", "type");
15+
verify.completionListContains("T", "type T = number", "tee", "type");

tests/cases/fourslash/completionsInJsxTag.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
//// foo: string
1212
//// }
1313
//// }
14-
////}
15-
////class Foo {
16-
//// render() {
17-
//// <div /*1*/ ></div>;
18-
//// <div /*2*/ />
19-
//// }
14+
////}
15+
////class Foo {
16+
//// render() {
17+
//// <div /*1*/ ></div>;
18+
//// <div /*2*/ />
19+
//// }
2020
////}
2121

2222
goTo.marker("1");
2323
verify.completionListCount(1);
24-
verify.completionListContains("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute");
24+
verify.completionListContains("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute");
2525
goTo.marker("2");
2626
verify.completionListCount(1);
27-
verify.completionListContains("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute");
27+
verify.completionListContains("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute");

tests/cases/fourslash/completionsJsxAttribute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
////<div /**/></div>;
1717

1818
goTo.marker();
19-
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute", []);
19+
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute", []);
2020
edit.insert("f");
21-
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc ", "JSX attribute", []);
21+
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute", []);
2222

tests/cases/fourslash/jsDocForTypeAlias.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
////type /**/T = number
55

66
goTo.marker();
7-
verify.quickInfoIs("type T = number", "DOC ");
7+
verify.quickInfoIs("type T = number", "DOC");

tests/cases/fourslash/jsDocFunctionSignatures9.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ verify.verifyQuickInfoDisplayParts('function',
1919
{"text": " ", "kind": "space"},
2020
{"text": "void", "kind": "keyword"}
2121
],
22-
[{"text": "first line of the comment\n\nthird line ", "kind": "text"}],
22+
[{"text": "first line of the comment\n\nthird line", "kind": "text"}],
2323
[]);

tests/cases/fourslash/quickInfoFromContextualType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
////}
88
////const i: I = { /**/x: 0 };
99

10-
verify.quickInfoAt("", "(property) I.x: number", "Documentation ");
10+
verify.quickInfoAt("", "(property) I.x: number", "Documentation");

tests/cases/fourslash/quickInfoImportedTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
verify.quickInfoAt("1", [
2222
"(alias) interface Foo",
2323
"import Foo",
24-
].join("\n"), "This is an interface ");
24+
].join("\n"), "This is an interface");
2525

2626
verify.quickInfoAt("2", [
2727
"(alias) type Bar = 1 | 2",
2828
"import Bar",
29-
].join("\n"), "One or two ");
29+
].join("\n"), "One or two");
3030

3131
verify.quickInfoAt("3", [
3232
"(alias) class Baz<T extends {}>",
3333
"import Baz",
34-
].join("\n"), "This is a class ");
34+
].join("\n"), "This is a class");

tests/cases/fourslash/quickInfoImportedTypesWithMergedMeanings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ verify.quickInfoAt("1", [
1818
"(alias) type Original<T> = () => T",
1919
"(alias) namespace Original",
2020
"export Original",
21-
].join("\n"), "some docs ");
21+
].join("\n"), "some docs");
2222

2323
verify.quickInfoAt("2", [
2424
"(alias) function Alias(): void",
2525
"(alias) type Alias<T> = () => T",
2626
"(alias) namespace Alias",
2727
"import Alias",
28-
].join("\n"), "some docs ");
28+
].join("\n"), "some docs");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @Filename: quickInfoJsDocTags1.ts
4+
/////** Doc */
5+
////const /**/x = 0;
6+
7+
verify.quickInfoAt("", "const x: 0", "Doc");

tests/cases/fourslash/quickInfoMappedSpreadTypes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
////f4./*f4*/bar;
1919

2020
goTo.marker("f");
21-
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");
21+
verify.quickInfoIs("(property) Foo.bar: number", "Doc");
2222

2323
goTo.marker("f2");
24-
verify.quickInfoIs("(property) bar: string", "Doc ");
24+
verify.quickInfoIs("(property) bar: string", "Doc");
2525

2626
goTo.marker("f3");
27-
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");
27+
verify.quickInfoIs("(property) Foo.bar: number", "Doc");
2828

2929
goTo.marker("f4");
30-
verify.quickInfoIs("(property) bar: string", "Doc ");
30+
verify.quickInfoIs("(property) bar: string", "Doc");

tests/cases/fourslash/quickInfoSpecialPropertyAssignment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
//// }
88
////}
99

10-
verify.quickInfoAt("", "(property) C.x: number", "Doc ");
10+
verify.quickInfoAt("", "(property) C.x: number", "Doc");

tests/cases/fourslash/quickInfoUnion_discriminated.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
////};
2828

2929
verify.quickInfos({
30-
uKind: ['(property) A.kind: "a"', "Kind A "],
31-
uProp: ["(property) A.prop: number", "Prop A "],
30+
uKind: ['(property) A.kind: "a"', "Kind A"],
31+
uProp: ["(property) A.prop: number", "Prop A"],
3232
u2Kind: '(property) kind: "bogus"',
3333
u2Prop: "(property) prop: number",
3434
});

tests/cases/fourslash/regexDetection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ verify.not.quickInfoExists();
77

88
goTo.marker("2");
99
verify.quickInfoIs("const Math: Math",
10-
"An intrinsic object that provides basic mathematics functionality and constants. ");
10+
"An intrinsic object that provides basic mathematics functionality and constants.");
1111

1212
goTo.marker("3");
1313
verify.not.quickInfoExists();

0 commit comments

Comments
 (0)