Skip to content

Commit 56fd9fe

Browse files
committed
update the query
1 parent e6872ca commit 56fd9fe

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

ql/ql/src/queries/style/ConsistentAlertMessage.ql

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,30 @@ string getMessage(Select sel) {
1919
).trim()
2020
}
2121

22-
Select getSelectForQuery(string id, string lang, string msg, string kind) {
22+
int parts(Select sel) { result = strictcount(String e | e.getParent*() = sel.getExpr(_)) }
23+
24+
Select getSelectForQuery(string id, string lang, string msg, string kind, int parts) {
2325
exists(File file, QLDoc doc | result.getLocation().getFile() = file |
2426
any(TopLevel top | top.getLocation().getFile() = file).getQLDoc() = doc and
2527
id = doc.getContents().regexpCapture("(?s).*@id (\\w+)/([\\w\\-]+)\\s.*", 2) and
2628
lang = doc.getContents().regexpCapture("(?s).*@id (\\w+)/([\\w\\-]+)\\s.*", 1) and
2729
kind = doc.getContents().regexpCapture("(?s).*@kind (\\w+)\\s.*", 1) and // enforcing the same kind.
28-
msg = getMessage(result)
30+
msg = getMessage(result) and
31+
parts = parts(result)
2932
) and
3033
// excluding experimetnal
3134
not result.getLocation().getFile().getRelativePath().matches("%/experimental/%")
3235
}
3336

34-
from
35-
string thisLang, string otherLang, string thisMsg, string otherMsg, Select thisSel,
36-
Select otherSel, string id, string kind
37+
from Select sel, string id, string lang, string msg, string kind, int parts, string badLangs
3738
where
38-
thisLang != otherLang and
39-
thisMsg != otherMsg and
40-
thisSel = getSelectForQuery(id, thisLang, thisMsg, kind) and
41-
otherSel = getSelectForQuery(id, otherLang, otherMsg, kind) and
42-
thisLang = "js"
43-
// TODO: summarize the langs in the msg.
44-
// TODO: Also select on the number of string constants in the select, to remove queries that contain more/less info.
45-
select thisSel, id + " $@", otherSel, otherLang // TODO: Tmp, makes bulk-fixing easier.
46-
/*
47-
* "The " + id + " query in " + thisLang + " does not have the same alert message as in $@.",
48-
* otherSel, otherLang
49-
*/
50-
39+
sel = getSelectForQuery(id, lang, msg, kind, parts) and
40+
badLangs =
41+
strictconcat(string bad |
42+
bad != lang and
43+
exists(getSelectForQuery(id, bad, any(string otherMsg | otherMsg != msg), kind, parts))
44+
|
45+
bad, ", "
46+
)
47+
select sel,
48+
"The " + lang + "/" + id + " query does not have the same alert message as " + badLangs + "."

0 commit comments

Comments
 (0)