File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
ql/src/queries/performance Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 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"
You can’t perform that action at this time.
0 commit comments