mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
function/class synatax
This commit is contained in:
30
python/ql/src/Classes/NamingConventionsClasses.qhelp
Normal file
30
python/ql/src/Classes/NamingConventionsClasses.qhelp
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
|
||||
<overview>
|
||||
<p>A class name that begins with a lowercase letter does not follow standard
|
||||
naming conventions. This decreases code readability. For example, <code>class background</code>.
|
||||
</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>
|
||||
Write the class name beginning with an uppercase letter. For example, <code>class Background</code>.
|
||||
</p>
|
||||
|
||||
</recommendation>
|
||||
|
||||
<references>
|
||||
|
||||
<li>
|
||||
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code<em>
|
||||
<a href="https://www.python.org/dev/peps/pep-0008/#class-names"</a>
|
||||
</li>
|
||||
|
||||
</references>
|
||||
|
||||
</qhelp>
|
||||
17
python/ql/src/Classes/NamingConventionsClasses.ql
Normal file
17
python/ql/src/Classes/NamingConventionsClasses.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @name Misnamed class
|
||||
* @description A class name that begins with a lowercase letter decreases readability.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @precision medium
|
||||
* @id python/misnamed-type
|
||||
* @tags maintainability
|
||||
*/
|
||||
|
||||
import python
|
||||
|
||||
from Class c
|
||||
where
|
||||
c.inSource() and
|
||||
not c.getName().substring(0, 1).toUpperCase() = c.getName().substring(0, 1)
|
||||
select c, "Class names should start in uppercase."
|
||||
30
python/ql/src/Functions/NamingConventionsFunctions.qhelp
Normal file
30
python/ql/src/Functions/NamingConventionsFunctions.qhelp
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
|
||||
<overview>
|
||||
<p>A function name that begins with an uppercase letter does not follow standard
|
||||
naming conventions. This decreases code readability. For example, <code>Jump</code>.
|
||||
</p>
|
||||
|
||||
</overview>
|
||||
<recommendation>
|
||||
|
||||
<p>
|
||||
Write the function name beginning with an lowercase letter. For example, <code>jump</code>.
|
||||
</p>
|
||||
|
||||
</recommendation>
|
||||
|
||||
<references>
|
||||
|
||||
<li>
|
||||
Guido van Rossum, Barry Warsaw, Nick Coghlan <em>PEP 8 -- Style Guide for Python Code<em>
|
||||
<a href="https://www.python.org/dev/peps/pep-0008/#function-and-variable-names"</a>
|
||||
</li>
|
||||
|
||||
</references>
|
||||
|
||||
</qhelp>
|
||||
17
python/ql/src/Functions/NamingConventionsFunctions.ql
Normal file
17
python/ql/src/Functions/NamingConventionsFunctions.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @name Misnamed function
|
||||
* @description A function name that begins with an uppercase letter decreases readability.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @precision medium
|
||||
* @id python/misnamed-function
|
||||
* @tags maintainability
|
||||
*/
|
||||
|
||||
import python
|
||||
|
||||
from Function f
|
||||
where
|
||||
f.inSource() and
|
||||
not f.getName().substring(0, 1).toLowerCase() = f.getName().substring(0, 1)
|
||||
select f, "Function names should start in lowercase."
|
||||
@@ -0,0 +1 @@
|
||||
| NamingConventionsClasses.py:2:1:2:14 | Class badName | Class names should start in uppercase. |
|
||||
@@ -0,0 +1,11 @@
|
||||
# BAD, do not start class or interface name with lowercase letter
|
||||
class badName:
|
||||
|
||||
def hello(self):
|
||||
print("hello")
|
||||
|
||||
# Good, class name starts with capital letter
|
||||
class GoodName:
|
||||
|
||||
def hello(self):
|
||||
print("hello")
|
||||
@@ -0,0 +1 @@
|
||||
Classes/NamingConventionsClasses.ql
|
||||
@@ -0,0 +1 @@
|
||||
| NamingConventionsFunctions.py:4:5:4:25 | Function HelloWorld | Function names should start in lowercase. |
|
||||
@@ -0,0 +1,9 @@
|
||||
class Test:
|
||||
|
||||
# BAD, do not start function name with uppercase letter
|
||||
def HelloWorld(self):
|
||||
print("hello world")
|
||||
|
||||
# GOOD, function name starts with lowercase letter
|
||||
def hello_world(self):
|
||||
print("hello world")
|
||||
@@ -0,0 +1 @@
|
||||
Functions/NamingConventionsFunctions.ql
|
||||
Reference in New Issue
Block a user