Showing 1,039 of 1,039 total issues
Rename field "status" Open
self.status = status
- 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()
Merge this if statement with the enclosing one. Open
if file_contents[line_num][0:sec_len] == sec_id:
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Merge this if statement with the enclosing one. Open
if pkg_manager in PKG_MANAGER_TO_CONFIG_FILE:
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed. Open
def has_duplicated_subkeys(file_path, file_contents, sections):
- 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
Refactor this function to reduce its Cognitive Complexity from 51 to the 15 allowed. Open
def simplify(self, sort=True):
- 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
Function "reference_check" has 8 parameters, which is greater than the 7 authorized. Open
def reference_check(env_yaml, rule_dirs, profile_path, product, product_yaml, reference,
excludes, controls_manager=None):
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
def do_something(param1, param2, param3, param4, param5): ...
Compliant Solution
def do_something(param1, param2, param3, param4): ...
Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed. Open
def move_patches_up_to_date_to_source_data_stream_component(datastreamtree):
- 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
Method "__init__" has 8 parameters, which is greater than the 7 authorized. Open
def __init__(self, env_yaml, resolved_rules_dir, templates_dir,
remediations_dir, checks_dir, platforms_dir, cpe_items_dir):
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
def do_something(param1, param2, param3, param4, param5): ...
Compliant Solution
def do_something(param1, param2, param3, param4): ...
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed. Open
def new_stig_overlay(xccdftree, ssgtree, outfile, quiet):
- 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
Rename function "createNodeRuleFunc" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Open
def createNodeRuleFunc(args):
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Refactor this function to reduce its Cognitive Complexity from 98 to the 15 allowed. Open
def main():
- 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
Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed. Open
def translate(self, tree, store_defname=False):
- 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
Refactor this function to reduce its Cognitive Complexity from 143 to the 15 allowed. Open
def parse(self, expr, simplify=False):
- 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
Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. Open
def ssg_xccdf_stigid_mapping(ssgtree):
- 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
Merge this if statement with the enclosing one. Open
if not os.path.isdir(group_path):
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Merge this if statement with the enclosing one. Open
if (disa_ref_href in ref_href_list) and (rule.get("id") not in profile_ruleids):
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Merge this if statement with the enclosing one. Open
if re.search(ref_exp, ref.text):
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed. Open
def get_profile_choices_for_input(input_tree, benchmark_id, tailoring_tree):
- 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
Either remove or fill this block of code. Open
pass
- Read upRead up
- Exclude checks
Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.
Noncompliant Code Example
for i in range(3): pass
Exceptions
When a block contains a comment, this block is not considered to be empty.
Refactor this function to reduce its Cognitive Complexity from 41 to the 15 allowed. Open
def _start_operation(self, ast, operation, precedence):
- 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.