Skip to content

Commit 73ad3f5

Browse files
author
Max Schaefer
committed
JavaScript: Tweak JSLint library to avoid bad join order.
1 parent 47b9218 commit 73ad3f5

File tree

1 file changed

+11
-1
lines changed
  • javascript/ql/src/semmle/javascript/linters

1 file changed

+11
-1
lines changed

javascript/ql/src/semmle/javascript/linters/JSLint.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ private string getDirectiveName(SlashStarComment c) {
99
result = c.getText().regexpCapture("(?s)\\s*(\\w+)\\b.*", 1)
1010
}
1111

12+
/** Gets a function at the specified location. */
13+
private Function getFunctionAt(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
14+
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
15+
}
16+
1217
/** A JSLint directive. */
1318
abstract class JSLintDirective extends SlashStarComment {
1419
/**
@@ -36,7 +41,7 @@ abstract class JSLintDirective extends SlashStarComment {
3641
private Function getASurroundingFunction() {
3742
exists (string path, int fsl, int fsc, int fel, int fec,
3843
int dsl, int dsc, int del, int dec |
39-
result.getLocation().hasLocationInfo(path, fsl, fsc, fel, fec) and
44+
result = getFunctionAt(path, fsl, fsc, fel, fec) and
4045
this.getLocation().hasLocationInfo(path, dsl, dsc, del, dec) |
4146
// the function starts before this directive
4247
(fsl < dsl or (fsl = dsl and fsc <= dsc))
@@ -96,6 +101,11 @@ abstract class JSLintGlobal extends Linting::GlobalDeclaration, JSLintDirective
96101
override predicate appliesTo(ExprOrStmt s) {
97102
JSLintDirective.super.appliesTo(s)
98103
}
104+
105+
override predicate declaresGlobalForAccess(GlobalVarAccess gva) {
106+
declaresGlobal(gva.getName(), _) and
107+
getScope() = gva.getContainer().getEnclosingContainer*()
108+
}
99109
}
100110

101111
/** A JSLint `global` directive. */

0 commit comments

Comments
 (0)