Skip to content
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

Add support for empty lines inside jsdoc comment blocks #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AndrewOCC
Copy link
Collaborator

@AndrewOCC AndrewOCC commented May 12, 2022

Adjusts normalisation logic so that empty lines in the middle of a comment aren't considered when calculating the indent.

Previously, the regex for SPACE_UNTIL_CONTENT would fail to include the '*' on an empty block comment line, as the * would meet the condition for the look-ahead (?=\S). This would give an inaccurate measure of the smallest indent.

For example, in this example:

     /**
       * comment
       * 
       * comment
       */

The matches on SPACE_UNTIL_CONTENT would be:
[" * "]
[" "]
[" * "]
The shortest indent value would be length 1, and the '*'s on each line wouldn't be stripped out, leading to the output:

* comment
* 
* comment

My current solution in this PR is to ignore empty lines when calculating the indent. Keen for feedback if there's a good way to adjust the SPACE_UNTIL_CONTENT regex to handle empty lines.

This was caught while debugging an issue in extract-react-types, where empty lines in JSDoc comments was breaking comment formatting.

@AndrewOCC
Copy link
Collaborator Author

Although this is technically a bug fix, I wonder if this should be a major release for the util, as this library has been stable for a long time and consumers may be making assumptions about how the library behaves in this edge case.

@AndrewOCC
Copy link
Collaborator Author

cc @Noviny, do you think this is a feasible fix for the library?

@AndrewOCC AndrewOCC self-assigned this Feb 20, 2023
@AndrewOCC AndrewOCC added the bug label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant