Skip to content

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

Closed
wants to merge 1 commit into from
Closed

build: tslint rule to enforce html tags escaping in comments #5825

wants to merge 1 commit into from

Conversation

julianobrasil
Copy link
Contributor

@julianobrasil julianobrasil commented Jul 17, 2017

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 (`)

/** 
 * The using of <svg>` is very good because...
 */

2 - Any HTML close tag (>) without a backtick (`):

/** 
 * The using of `<svg> is very good because...
 */

3 - Any HTML open or close tag without it's matching:

/** 
 * The using of `<svg is very good because...
 */

4 - Any HTML open following an open tag and before a closing tag:

/** 
 * The using of `<svg attr1="value1" < >` is very good because...
 */

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 17, 2017
@julianobrasil
Copy link
Contributor Author

julianobrasil commented Jul 20, 2017

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 😃.

@julianobrasil
Copy link
Contributor Author

Definitely this is not the way of escaping html tags in comment (based on the unsuccessful #7756 that didn't fix the issue)

Copy link
Contributor

@willshowell willshowell left a 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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Unindent

}
}

exports.Rule = Rule;
Copy link
Contributor

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.';
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

@julianobrasil julianobrasil Oct 31, 2017

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.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants