Skip to content

QL: add ql/consistent-alert-message #10053

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 6 commits into from
Aug 19, 2022

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Aug 15, 2022

And drive-by remove some alerts on deprecated predicates/classes.

I got a WIP branch were I've fixed most of the alerts introduced by the new query.

@erik-krogh erik-krogh marked this pull request as ready for review August 15, 2022 19:58
@erik-krogh erik-krogh requested a review from a team as a code owner August 15, 2022 19:58
Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

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

A few comments and suggestions, but otherwise this looks good. 👍

any(TopLevel top | top.getLocation().getFile() = file).getQLDoc() = doc
|
result =
doc.getContents().regexpCapture("(?s).*@id (\\w+)/([\\w\\-]+)\\s.*", 2) // query ID (without lang)
Copy link
Contributor

Choose a reason for hiding this comment

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

The duplication of this regex here and on line 54 is a bit unfortunate. Perhaps it would be nicer to factor these out in a helper predicate on the QLDoc type?

string getMessage(Select sel) {
result =
strictconcat(String e, Location l |
// is child of an expression in the select (in an uneven position, that's where the message is)
Copy link
Contributor

Choose a reason for hiding this comment

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

... in an uneven position ...

That's an odd way to phrase that. 😉

(Though I'm not sure "odd position" is actually more intuitive. Maybe "odd-indexed position" would be better?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I'm not sure "odd position" is actually more intuitive.

That's not an odd position to have 😉

I'll go for odd-indexed position.

string getSelectFingerPrint(Select sel) {
exists(File file, QLDoc doc |
sel.getLocation().getFile() = file and
any(TopLevel top | top.getLocation().getFile() = file).getQLDoc() = doc
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this could be convenient to push into a getQLDoc predicate on File.

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've made a class QueryDoc, and it felt more appropriate to have an accessor for that on Select.

* The query-id (without language), the language, the message from the select, and a language agnostic fingerprint.
*/
Select parseSelect(string id, string lang, string msg, string fingerPrint) {
exists(File file, QLDoc doc | result.getLocation().getFile() = file |
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: why not create a subclass of QLDoc for the kind of QLDoc that applies to a whole file, and then expose the relevant tags as member predicates?
(I think it's fine to only implement the predicates you need for this query. We can always add more later, and some of them may be a bit fiddly to implement.)

// for a select with a fingerprint
sel = parseSelect(id, lang, msg, fingerPrint) and
// there exists other languages with the same fingerprint, but other message
badLangs =
Copy link
Contributor

Choose a reason for hiding this comment

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

The way the alert message is formulated, it sounds like lang is bad compared to everything in badLangs, but then wouldn't it make more sense to call this goodLangs?
Or perhaps just otherLangs to be more neutral.

(In the case where lang is the only outlier, it seems strange to classify the other languages as bad.)

* Gets a language agnostic fingerprint for a Select.
* The fingerPrint includes e.g. the query-id, the @kind of the query, and the number of expressions in the select.
*
* This fingerprint avoid false positives where two queries with the same ID behave differently (which is OK).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* This fingerprint avoid false positives where two queries with the same ID behave differently (which is OK).
* This fingerprint avoids false positives where two queries with the same ID behave differently (which is OK).

@erik-krogh erik-krogh requested a review from tausbn August 19, 2022 13:21
Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

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

Very nice! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants