Skip to content

Commit dc58f6f

Browse files
author
dilanbhalla
committed
function/class synatax
1 parent a2677f8 commit dc58f6f

10 files changed

+118
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
7+
<overview>
8+
<p>A class name that begins with a lowercase letter does not follow standard
9+
naming conventions. This decreases code readability. For example, <code>class background</code>.
10+
</p>
11+
12+
</overview>
13+
<recommendation>
14+
15+
<p>
16+
Write the class name beginning with an uppercase letter. For example, <code>class Background</code>.
17+
</p>
18+
19+
</recommendation>
20+
21+
<references>
22+
23+
<li>
24+
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code<em>
25+
<a href="https://www.python.org/dev/peps/pep-0008/#class-names"</a>
26+
</li>
27+
28+
</references>
29+
30+
</qhelp>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Misnamed class
3+
* @description A class name that begins with a lowercase letter decreases readability.
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @precision medium
7+
* @id python/misnamed-type
8+
* @tags maintainability
9+
*/
10+
11+
import python
12+
13+
from Class c
14+
where
15+
c.inSource() and
16+
not c.getName().substring(0, 1).toUpperCase() = c.getName().substring(0, 1)
17+
select c, "Class names should start in uppercase."
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
7+
<overview>
8+
<p>A function name that begins with an uppercase letter does not follow standard
9+
naming conventions. This decreases code readability. For example, <code>Jump</code>.
10+
</p>
11+
12+
</overview>
13+
<recommendation>
14+
15+
<p>
16+
Write the function name beginning with an lowercase letter. For example, <code>jump</code>.
17+
</p>
18+
19+
</recommendation>
20+
21+
<references>
22+
23+
<li>
24+
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code<em>
25+
<a href="https://www.python.org/dev/peps/pep-0008/#function-and-variable-names"</a>
26+
</li>
27+
28+
</references>
29+
30+
</qhelp>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Misnamed function
3+
* @description A function name that begins with an uppercase letter decreases readability.
4+
* @kind problem
5+
* @problem.severity recommendation
6+
* @precision medium
7+
* @id python/misnamed-function
8+
* @tags maintainability
9+
*/
10+
11+
import python
12+
13+
from Function f
14+
where
15+
f.inSource() and
16+
not f.getName().substring(0, 1).toLowerCase() = f.getName().substring(0, 1)
17+
select f, "Function names should start in lowercase."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| NamingConventionsClasses.py:2:1:2:14 | Class badName | Class names should start in uppercase. |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BAD, do not start class or interface name with lowercase letter
2+
class badName:
3+
4+
def hello(self):
5+
print("hello")
6+
7+
# Good, class name starts with capital letter
8+
class GoodName:
9+
10+
def hello(self):
11+
print("hello")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Classes/NamingConventionsClasses.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| NamingConventionsFunctions.py:4:5:4:25 | Function HelloWorld | Function names should start in lowercase. |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Test:
2+
3+
# BAD, do not start function name with uppercase letter
4+
def HelloWorld(self):
5+
print("hello world")
6+
7+
# GOOD, function name starts with lowercase letter
8+
def hello_world(self):
9+
print("hello world")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Functions/NamingConventionsFunctions.ql

0 commit comments

Comments
 (0)