FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Imports/MultipleImports.ql at codeql-cli-2.11.3 · github/codeql · GitHub
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Issues
1k
Pull requests
471
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Imports
/
MultipleImports.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (42 loc) · 1.51 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Imports
/
MultipleImports.ql
Copy path
File metadata and controls
46 lines (42 loc) · 1.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @name Module is imported more than once
* @description Importing a module a second time has no effect and impairs readability
* @kind problem
* @tags maintainability
* useless-code
* @problem.severity recommendation
* @sub-severity high
* @precision very-high
* @id py/repeated-import
*/
import
python
predicate
is_simple_import
(
Import
imp
)
{
not
exists
(
Attribute
a
|
imp
.
contains
(
a
)
)
}
predicate
double_import
(
Import
original
,
Import
duplicate
,
Module
m
)
{
original
!=
duplicate
and
is_simple_import
(
original
)
and
is_simple_import
(
duplicate
)
and
/* Imports import the same thing */
exists
(
ImportExpr
e1
,
ImportExpr
e2
|
e1
.
getName
(
)
=
m
.
getName
(
)
and
e2
.
getName
(
)
=
m
.
getName
(
)
and
e1
=
original
.
getAName
(
)
.
getValue
(
)
and
e2
=
duplicate
.
getAName
(
)
.
getValue
(
)
)
and
original
.
getAName
(
)
.
getAsname
(
)
.
(
Name
)
.
getId
(
)
=
duplicate
.
getAName
(
)
.
getAsname
(
)
.
(
Name
)
.
getId
(
)
and
exists
(
Module
enclosing
|
original
.
getScope
(
)
=
enclosing
and
duplicate
.
getEnclosingModule
(
)
=
enclosing
and
(
/* Duplicate is not at top level scope */
duplicate
.
getScope
(
)
!=
enclosing
or
/* Original dominates duplicate */
original
.
getAnEntryNode
(
)
.
dominates
(
duplicate
.
getAnEntryNode
(
)
)
)
)
}
from
Import
original
,
Import
duplicate
,
Module
m
where
double_import
(
original
,
duplicate
,
m
)
select
duplicate
,
"This import of module "
+
m
.
getName
(
)
+
" is redundant, as it was previously imported $@."
,
original
,
"on line "
+
original
.
getLocation
(
)
.
getStartLine
(
)
.
toString
(
)
Back
|
FazBrowse Home
|
New Git URL