-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: tslint rule to enforce html tags escaping in comments #5825
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
Conversation
Not sure whether look for unescaped html tags is better than look for "opening" backticks without the corresponding "closing" backticks. Not even sure the backtick is the right escaping character in code comments 😃. |
Definitely this is not the way of escaping html tags in comment (based on the unsuccessful #7756 that didn't fix the issue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should reopen this per #7756 (comment)!
@@ -28,6 +28,7 @@ | |||
"no-unused-expression": true, | |||
"no-var-keyword": true, | |||
"no-exposed-todo": true, | |||
"no-unescaped-html-tag": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unindent
} | ||
} | ||
|
||
exports.Rule = Rule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline at end of file
|
||
const ERROR_MESSAGE = | ||
'A HTML tag may only appear if it is escaped. ' + | ||
'This is meant to prevent failures in docs generation caused by a misinterpreted tag.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe,
An HTML tag may only appear in a JSDoc comment if it is escaped. This prevents failures in document generation caused by a misinterpreted tag.
utils.forEachComment(sourceFile, (fullText, commentRange) => { | ||
|
||
let isEscapedHtmlTag = true; | ||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be much easier with a regex. A simple one like this would be effective for when either character is unescaped,
/[^`][<>]/g
You could certainly extend it to look for unmatched pairs, but I'm not sure that's even necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I closed this I was just thinking it could be better to just look for unmatched `
pairs. In fact it was my initial thought. Than I think I forgot about it and started looking for the `<
and >`
matching pairs. I'll review and reopen it, probably tomorow.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The rule was built suposing that using backticks is enough to escape HTML tags in multiline code comments. It should emit warnings when there is:
1 - Any HTML open tag (
<
) without a backtick (`)2 - Any HTML close tag (
>
) without a backtick (`):3 - Any HTML open or close tag without it's matching:
4 - Any HTML open following an open tag and before a closing tag: