Skip to content

Commit 53e362c

Browse files
authored
QL: Merge pull request #112 from github/tausbn/import-language-first
Query: Noninitial imports of the standard library
2 parents 2f77b92 + 632d42f commit 53e362c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @name Standard library is not the first import
3+
* @description Importing other libraries before the standard library can cause a change in
4+
* evaluation order and may lead to performance errors.
5+
* @kind problem
6+
* @problem.severity error
7+
* @id ql/noninitial-stdlib-import
8+
* @tags performance
9+
* @precision high
10+
*/
11+
12+
import ql
13+
14+
predicate isStdLibImport(Import i, string name) {
15+
name = i.getQualifiedName(0) and
16+
i.getLocation().getFile().getRelativePath().matches(name + "%") and
17+
not exists(i.getQualifiedName(1))
18+
}
19+
20+
Import importBefore(Import i) {
21+
exists(Module m, int bi, int ii |
22+
result = m.getMember(bi) and
23+
i = m.getMember(ii) and
24+
bi < ii
25+
)
26+
}
27+
28+
from Import i
29+
where isStdLibImport(i, _) and exists(importBefore(i))
30+
select i, "This import may cause reevaluation to occur, as there are other imports preceding it"

0 commit comments

Comments
 (0)