Skip to content

Commit 1385b22

Browse files
author
Dilan
committed
pr fixes, typo in qhelp file and helper method for queries
1 parent 26b030f commit 1385b22

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

python/ql/src/experimental/Classes/NamingConventionsClasses.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Write the class name beginning with an uppercase letter. For example, <code>clas
2121
<references>
2222

2323
<li>
24-
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code<em>
24+
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code</em>
2525
<a href="https://www.python.org/dev/peps/pep-0008/#class-names">Python Class Names</a>
2626
</li>
2727

python/ql/src/experimental/Classes/NamingConventionsClasses.ql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99

1010
import python
1111

12-
from Class c, string first_char
12+
predicate lower_case_class(Class c) {
13+
exists(string first_char |
14+
first_char = c.getName().prefix(1) and
15+
not first_char = first_char.toUpperCase()
16+
)
17+
}
18+
19+
from Class c
1320
where
1421
c.inSource() and
15-
first_char = c.getName().prefix(1) and
16-
not first_char = first_char.toUpperCase() and
17-
not exists(Class c1, string first_char1 |
22+
lower_case_class(c) and
23+
not exists(Class c1 |
1824
c1 != c and
1925
c1.getLocation().getFile() = c.getLocation().getFile() and
20-
first_char1 = c1.getName().prefix(1) and
21-
not first_char1 = first_char1.toUpperCase()
26+
lower_case_class(c1)
2227
)
2328
select c, "Class names should start in uppercase."

python/ql/src/experimental/Functions/NamingConventionsFunctions.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Write the function name beginning with an lowercase letter. For example, <code>j
2121
<references>
2222

2323
<li>
24-
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code<em>
24+
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code</em>
2525
<a href="https://www.python.org/dev/peps/pep-0008/#function-and-variable-names">Python Function and Variable Names</a>
2626
</li>
2727

python/ql/src/experimental/Functions/NamingConventionsFunctions.ql

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99

1010
import python
1111

12-
from Function f, string first_char
12+
predicate upper_case_function(Function func) {
13+
exists(string first_char |
14+
first_char = func.getName().prefix(1) and
15+
not first_char = first_char.toLowerCase()
16+
)
17+
}
18+
19+
from Function func
1320
where
14-
f.inSource() and
15-
first_char = f.getName().prefix(1) and
16-
not first_char = first_char.toLowerCase() and
17-
not exists(Function f1, string first_char1 |
18-
f1 != f and
19-
f1.getLocation().getFile() = f.getLocation().getFile() and
20-
first_char1 = f1.getName().prefix(1) and
21-
not first_char1 = first_char1.toLowerCase()
21+
func.inSource() and
22+
upper_case_function(func) and
23+
not exists(Function func1 |
24+
func1 != func and
25+
func1.getLocation().getFile() = func.getLocation().getFile() and
26+
upper_case_function(func1)
2227
)
23-
select f, "Function names should start in lowercase."
28+
select func, "Function names should start in lowercase."

0 commit comments

Comments
 (0)