Skip to content

Fix some bad jsdoc comment indent - #30838

Merged
Nathan Shively-Sanders (sandersn) merged 5 commits into
masterfrom
fix-jsdoc-comment-indent
Apr 10, 2019
Merged

Nathan Shively-Sanders (sandersn) merged 5 commits into
masterfrom
fix-jsdoc-comment-indent

Conversation

@sandersn

Copy link
Copy Markdown
Member

Fixes #15749 plus a few other cases I discovered.

Yes, I know the baseline format is horrible. Sorry.

Solves the initial problem but breaks commentCommentParsing. I also
found a couple more interesting cases.
I may try do a little more; `margin += tag.end - tag.pos` bothers me a
bit.
@sandersn

Copy link
Copy Markdown
Member Author

I added a few reviewers who might have parsed things in the past.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some explanatory comments

Comment thread src/compiler/parser.ts
// for malformed examples like `/** @param {string} x @returns {number} the length */`
state = JSDocState.BeginningOfLine;
margin = undefined;
indent++;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just wrong, as far as I can tell, but only was used for tags followed by a newline:

@ex
stuff

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, all our previous tests cases looked like this:

@param x   comment
           comment
              indent

Never like this:

@example
comment
comment
  indent

so this erroneous increment was hidden by the fact that indent had already passed margin.

Comment thread src/compiler/parser.ts
}

function parseTag(indent: number) {
function parseTag(margin: number) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

margin is the thing that's fixed, whereas indent goes up for each line. So this name was wrong before.

Comment thread src/compiler/parser.ts
const whitespace = scanner.getTokenText();
// if the whitespace crosses the margin, take only the whitespace that passes the margin
if (margin !== undefined && indent + whitespace.length > margin) {
comments.push(whitespace.slice(margin - indent - 1));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this math was also wrong before, for the same reason as the indent++

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me 👍🏽

@sandersn
Nathan Shively-Sanders (sandersn) deleted the fix-jsdoc-comment-indent branch August 26, 2019 17:32
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants