Skip to content

Fix syntax errors in QL comments #8952

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

Merged
merged 1 commit into from
May 3, 2022

Conversation

cklin
Copy link
Contributor

@cklin cklin commented Apr 28, 2022

This PR fixes QL comments used to generate QL documentation. They are mostly about back-quoting angle brackets so that they are property escaped in the HTML output.

@cklin cklin requested review from a team as code owners April 28, 2022 18:58
@cklin cklin added the no-change-note-required This PR does not need a change note label Apr 28, 2022
@@ -53,7 +53,7 @@ import javascript
*
* /**
* * @param {!Object} obj
* * @return {!Array<string>}
* * @return {!Array&lt;string&gt;}
Copy link
Contributor

Choose a reason for hiding this comment

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

These are wrapped in <pre>...</pre>, so are these changes necessary? Changing < to &lt; hurts readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reserved characters such as < and > still needs to be escaped using their HTML entity. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre

You can see that @return {!Array<string>} currently shows up as @return {!Array} because the browser treats <string> as an unknown element.
https://codeql.github.com/codeql-standard-libraries/javascript/semmle/javascript/Externs.qll/type.Externs$ExternalDecl.html

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we replace the <pre> with triple backquotes instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could, but the *&#47; in the next line would stop working.

Copy link
Contributor

Choose a reason for hiding this comment

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

See - I have no idea what entity number 47 is - I had to look that up, that's pretty poor readability. Luckily the obvious answer is just to replace &#47; with /.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, right, I see why the entity is used for /. But the <pre> isn't really a good solution - it doesn't appear to render correctly in VSCode (on predicate mouse-over).

@aschackmull
Copy link
Contributor

Most of the changes look fine, so mostly no objections from me. Except for the <-to-&lt;-rewrite, which I think hurts readability. I also wonder why these changes are even necessary - our qldoc is mostly markdown, so would it instead make sense to simply remove html support in our qldoc? (I know that's likely a much larger change, but still worth a thought.) Then a translation into html could simply do whatever escaping was needed without qldoc writers having to worry about accidental html interpretations of angle brackets.

* - Line 16: There is no static target (delegate call) but the delegate `i => { }` (line
* 20) is a run-time target.
* - Line 16: There is no static target (delegate call) but the delegate `i => { }`
* (line 20) is a run-time target.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind this change, but hopefully it is not needed to generete proper QL doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually is needed. Here is what the rendered documentation currently looks like, without this fix:

https://codeql.github.com/codeql-standard-libraries/csharp/semmle/code/csharp/exprs/Call.qll/predicate.Call$Call$getARuntimeTarget.0.html
line-20

Copy link
Contributor

Choose a reason for hiding this comment

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

Any explanation why it renders that way? Is it a rendering bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that is because 20) is interpreted as a numbered list item starting at number 20.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that makes a bit more sense then. A markdown gotcha.

@@ -1,6 +1,6 @@
/**
* @name Incorrect type parameter name in documentation
* @description The type parameter name given in a '<typeparam>' tag does not exist. Rename the parameter or
* @description The type parameter name given in a `<typeparam>` tag does not exist. Rename the parameter or
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the new way of doing things, we should update the comment Any code elements included in the description should be enclosed in single quotes (https://github.com/github/codeql/blob/main/docs/query-metadata-style-guide.md?plain=1#L63), as well as the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should clarify that this is not a style change but a rendering fix. Here is what the documentation currently looks like:

https://codeql.github.com/codeql-standard-libraries/csharp/Documentation/XmldocExtraTypeParam.ql/module.XmldocExtraTypeParam.html
typeparam

QL comments can include Markdown and HTML, so the < and > characters need to be escaped, either by putting them in Markdown code format (the approach I took here) or by replacing them with &lt; and &gt;. I can switch it to the second approach if that is more style-compliant.

I agree that using Markdown backquotes for code elements seems sensible, but that should probably be a separate discussion.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is not a style change but a rendering fix

No, it's both a style change and a rendering fix.

Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

C/C++ 👍

@aschackmull
Copy link
Contributor

I think it is a problem that we allow html in our qldoc, we should restrict ourselves to markdown and then we wouldn't need such readability-impeding changes like writing &lt;. Could we just get rid of html in our qldoc? Then any html rendering could just be plain markdown-to-html.

@cklin
Copy link
Contributor Author

cklin commented May 2, 2022

I intended this PR to be a quick low-effort fix for QL documentation that is already broken. Unfortunately, I really do not have more time to devote to this PR or the issue of broken documentation, so I will just have to leave this PR as-is.

I am sure that you all as the owners of the documentation will be able to resolve the open questions and find the best way to address both the immediate and the long-term issues. Thank you! 🙏

Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

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

JS 👍

The change in Externs.qll makes it slightly harder to read the source code.
But it seems like the best solution, because the rendered documentation should definitely render correctly.

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

As commented above.

Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

The change in javascript/ql/lib/semmle/javascript/Externs.qll is unfortunate and makes me want to abolish html entirely from our qldoc, but currently I can't think of a way to render */ inside a triple-backtick code block. Note that the <pre> block doesn't render correctly in VSCode, so going for a markdown solution would be preferable, but I'll revert my position on whether just to merge this PR for now.

@aschackmull aschackmull merged commit 249f771 into github:main May 3, 2022
@cklin cklin deleted the fix-ql-comments-syntax branch August 16, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# C++ Java JS no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants