Skip to content

Fix some bad jsdoc comment indent #30838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2019
Merged

Fix some bad jsdoc comment indent #30838

merged 5 commits into from
Apr 10, 2019

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Apr 9, 2019

Fixes #15749 plus a few other cases I discovered.

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

sandersn added 5 commits April 9, 2019 11:12
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
Member Author

sandersn commented Apr 9, 2019

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

Copy link
Member Author

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Some explanatory comments

@@ -6441,7 +6441,6 @@ namespace ts {
// for malformed examples like `/** @param {string} x @returns {number} the length */`
state = JSDocState.BeginningOfLine;
margin = undefined;
indent++;
Copy link
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
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.

}

function parseTag(indent: number) {
function parseTag(margin: number) {
Copy link
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.

@@ -6646,7 +6659,7 @@ namespace 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
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
Member

@andrewbranch andrewbranch left a comment

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 sandersn merged commit ff95909 into master Apr 10, 2019
@sandersn sandersn deleted the fix-jsdoc-comment-indent branch August 26, 2019 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants