Showing 650 of 650 total issues
Function load_config
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def load_config(args=None):
"""
Load configuration from file, environ, or command line arguments.
Parameters
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Refactor this function to reduce its Cognitive Complexity from 24 to the 15 allowed. Open
def update(args, config={}):
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3. Open
username = input("Wprowadź nazwę użytkownika: ")
- Exclude checks
Rename field "serial" Open
self.serial = aioserial.AioSerial(
- Read upRead up
- Exclude checks
It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.
Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.
Noncompliant Code Example
class Foo: foo = '' def getFoo(self): ... foo = Foo() foo.getFoo() # what does this return?
Compliant Solution
class Foo: name = '' def getName(self): ... foo = Foo() foo.getName()
Remove this commented out code. Open
# permissions=feature_value,
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3. Open
if step_enabled("user", args) and input(
"Czy chcesz stworzć nowego użytkownika-administratora? [y/n]"
- Exclude checks
Correct one of the identical sub-expressions on both sides of operator "==". Open
if sys.platform == "linux" or 1 == 1:
- Read upRead up
- Exclude checks
Using the same value on either side of a binary operator is almost always a mistake. In the case of logical operators, it is either a copy/paste error and therefore a bug, or it is simply wasted code, and should be simplified. In the case of bitwise operators and most binary mathematical operators, having the same value on both sides of an operator yields predictable results, and should be simplified.
This rule ignores *
, +
, and =
.
Noncompliant Code Example
if a == a: # Noncompliant work() if a != a: # Noncompliant work() if a == b and a == b: # Noncompliant work() if a == b or a == b: # Noncompliant work() j = 5 / 5 # Noncompliant k = 5 - 5 # Noncompliant
Exceptions
The following are ignored:
- The expression
1 << 1
See
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
- {rule:python:S1656} - Implements a check on
=
.
Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed. Open
def extract_uid(self, block0: Union[str, bytearray]) -> str:
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Remove this commented out code. Open
# feature_value = secure.PermissionsPolicy().geolocation("'none'").vibrate("'none'")
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Refactor this function to reduce its Cognitive Complexity from 59 to the 15 allowed. Open
def install(args):
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.