FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/ql/src/Classes/UselessClass.ql at codeql-cli/v2.15.5 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
998
Pull requests
459
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
/
Classes
/
UselessClass.ql
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (76 loc) · 2.26 KB
Breadcrumbs
codeql
/
python
/
ql
/
src
/
Classes
/
UselessClass.ql
Copy path
File metadata and controls
84 lines (76 loc) · 2.26 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @name Useless class
* @description Class only defines one public method (apart from `__init__` or `__new__`) and should be replaced by a function
* @kind problem
* @tags maintainability
* useless-code
* @problem.severity recommendation
* @sub-severity low
* @precision medium
* @id py/useless-class
*/
import
python
predicate
fewer_than_two_public_methods
(
Class
cls
,
int
methods
)
{
(
methods
=
0
or
methods
=
1
)
and
methods
=
count
(
Function
f
|
f
=
cls
.
getAMethod
(
)
and
not
f
=
cls
.
getInitMethod
(
)
)
}
predicate
does_not_define_special_method
(
Class
cls
)
{
not
exists
(
Function
f
|
f
=
cls
.
getAMethod
(
)
and
f
.
isSpecialMethod
(
)
)
}
predicate
no_inheritance
(
Class
c
)
{
not
exists
(
ClassValue
cls
,
ClassValue
other
|
cls
.
getScope
(
)
=
c
and
other
!=
ClassValue
::
object
(
)
|
other
.
getABaseType
(
)
=
cls
or
cls
.
getABaseType
(
)
=
other
)
and
not
exists
(
Expr
base
|
base
=
c
.
getABase
(
)
|
not
base
instanceof
Name
or
base
.
(
Name
)
.
getId
(
)
!=
"object"
)
}
predicate
is_decorated
(
Class
c
)
{
exists
(
c
.
getADecorator
(
)
)
}
predicate
is_stateful
(
Class
c
)
{
exists
(
Function
method
,
ExprContext
ctx
|
method
.
getScope
(
)
=
c
and
(
ctx
instanceof
Store
or
ctx
instanceof
AugStore
)
|
exists
(
Subscript
s
|
s
.
getScope
(
)
=
method
and
s
.
getCtx
(
)
=
ctx
)
or
exists
(
Attribute
a
|
a
.
getScope
(
)
=
method
and
a
.
getCtx
(
)
=
ctx
)
)
or
exists
(
Function
method
,
Call
call
,
Attribute
a
,
string
name
|
method
.
getScope
(
)
=
c
and
call
.
getScope
(
)
=
method
and
call
.
getFunc
(
)
=
a
and
a
.
getName
(
)
=
name
|
name
in
[
"pop"
,
"remove"
,
"discard"
,
"extend"
,
"append"
]
)
}
predicate
useless_class
(
Class
c
,
int
methods
)
{
c
.
isTopLevel
(
)
and
c
.
isPublic
(
)
and
no_inheritance
(
c
)
and
fewer_than_two_public_methods
(
c
,
methods
)
and
does_not_define_special_method
(
c
)
and
not
c
.
isProbableMixin
(
)
and
not
is_decorated
(
c
)
and
not
is_stateful
(
c
)
}
from
Class
c
,
int
methods
,
string
msg
where
useless_class
(
c
,
methods
)
and
(
methods
=
1
and
msg
=
"Class "
+
c
.
getName
(
)
+
" defines only one public method, which should be replaced by a function."
or
methods
=
0
and
msg
=
"Class "
+
c
.
getName
(
)
+
" defines no public methods and could be replaced with a namedtuple or dictionary."
)
select
c
,
msg
Back
|
FazBrowse Home
|
New Git URL