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

Git merge conflict markers in JSDoc comments are formatted and disabled #218

Open
tjcouch-sil opened this issue Nov 10, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@tjcouch-sil
Copy link

tjcouch-sil commented Nov 10, 2023

Hello prettier-plugin-jsdoc devs! Thank you very much for all the hard work on this great tool. Our team is beginning to use it, and we encountered an issue that is partially with prettier itself and potentially arguably partially with this plugin.

We are facing an issue with prettier not properly detecting git merge conflict markers in multi-line comments which leads to the document being formatted and prettier-plugin-jsdoc disabling merge conflict markers in JSDoc comments. It seems that, when a git merge conflict marker is in a file, prettier throws and logs Error formatting document. and Merge conflict marker encountered. instead of formatting the file. Example (Playground link):

<<<<<<< HEAD:file.txt
Things
=======
Stuff
>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt

As such, prettier-plugin-jsdoc doesn't format anything in the document. However, prettier does not detect git merge conflict markers within a multi-line comment and successfully formats the document (Playground link).

This means that, if a file has merge conflicts within a JSDoc, prettier-plugin-jsdoc formats that JSDoc and disables the merge conflict markers like so:

Input:

/**
 * This line doesn't need to be here, but it illustrates the issue
<<<<<<< HEAD:file.txt
 * Other things in comment
=======
 * Other stuff in comment
>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086:file.txt
 * This line also doesn't need to be here, but it illustrates the issue
 */

Output:

/**
 * # This line doesn't need to be here, but it illustrates the issue
 * <<<<<<< HEAD:file.txt
 * Other things in comment
 *
 * Other stuff in comment> > > > > > > 77976da35a11db4580b80ae27e8d65caf5208086:file.txt This line also doesn't need to be here, but it
 * > > > > > > > illustrates the issue
 */

Expected behavior:
In the first place, I expect that Prettier would detect git merge conflict markers anywhere in a document including within multi-line comments, throws and logs Error formatting document. and Merge conflict marker encountered., and does not format the document. (Issue filed with them at prettier/prettier#15613).

  • Update: Prettier closed the issue, saying these comments are valid JS comments. I think that makes enough sense. As such, I suppose this would be something you would want to make sure to preserve in this plugin since you're editing certain JS comments. I edited the following paragraph accordingly.

I expect that prettier-plugin-jsdoc would not format a JSDoc with merge conflicts in it because it disables the merge conflicts, meaning it would be easy to miss this and commit this messy JSDoc. Since Prettier ignores all JS comments but this plugin modifies certain comments, this plugin should detect when merge conflict markers are present in the JSDoc comments and preserve them accordingly.

Thank you again very much!

@hosseinmd hosseinmd added the bug Something isn't working label Nov 17, 2023
@hosseinmd
Copy link
Owner

hosseinmd commented Nov 17, 2023

I agree, I will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants