-
-
Notifications
You must be signed in to change notification settings - Fork 170
Description
It would be nice to be able to configure an expected escaped substitution of the character sequence */ when used in JSDoc descriptions, types, and examples.
Example:
{
"settings": {
"jsdoc": {
"escapedJSDocCommentTermination": "*\/"
}
}
}Then, when the jsdoc/check-examples rule gathers the example content, it first would find and replace all occurrences of the escapedJSDocCommentTermination string with */. This way the content is parsable JavaScript again, preventing parse errors like this:
Motivation
To be able to use the character sequence */ within JSDoc example content, it has to be escaped to prevent prematurely closing the JSDoc comment tag itself. There is debate about the best way to escape it (see microsoft/tsdoc#166), but the convention I came up with for jsdoc-md is to use *\/ in place of */, then whenever the content is used unescape it by replacing *\/ with */:
https://github.com/jaydenseric/jsdoc-md/blob/v9.1.1/private/unescapeJsdoc.js#L23
If the escape substitution is configurable, eslint-plugin-jsdoc doesn't have to force a particular pattern on users. Once day if a industry standard convention surfaces we can bake it it and remove the option.
Alternatives considered
I tried coming up with an exampleCodeRegex pattern that can also do substitutions of the desired escape sequence, but it appears to not be possible in a single regex pattern.
One alternative approach is to not have a global settings.jsdoc.escapedJSDocCommentTermination, and just add a new option to the jsdoc/check-examples rule. Either it could be a regex for substitution, or it could be a function to do any sort of unescaping of the content that might be more complex than a simple substitution. The downside of a function option is that it won't work when config is JSON vs JS.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
