Skip to content

Commit

Permalink
enabled and fixed no-else-* pylint warnings (danmar#6883)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored and Ludvig Gunne Lindström committed Oct 19, 2024
1 parent f01e9b4 commit 10f0d2a
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 116 deletions.
3 changes: 0 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ disable=
simplifiable-if-statement,
too-many-locals,
too-many-arguments,
no-else-return,
too-few-public-methods,
consider-using-min-builtin,
comparison-with-itself,
too-many-return-statements,
no-else-continue,
no-else-break,
inconsistent-return-statements,
consider-using-in,
too-many-nested-blocks,
Expand Down
9 changes: 4 additions & 5 deletions addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ def iterconfigurations(self):
if event == 'start':
cfg = Configuration(node.get('cfg'))
continue
elif event == 'end':
if event == 'end':
cfg.setIdMap(cfg_arguments)
yield cfg
cfg = None
Expand Down Expand Up @@ -1353,7 +1353,7 @@ def iterconfigurations(self):
if event == 'start':
cfg_function = Function(node, cfg.scopes[-1])
continue
elif event == 'end':
if event == 'end':
cfg.functions.append(cfg_function)
cfg_function = None

Expand Down Expand Up @@ -1397,7 +1397,7 @@ def iterconfigurations(self):
if event == 'start':
cfg_valueflow = ValueFlow(node)
continue
elif event == 'end':
if event == 'end':
cfg.valueflow.append(cfg_valueflow)
cfg_valueflow = None

Expand Down Expand Up @@ -1593,8 +1593,7 @@ def __nonzero__(self):
def __getattr__(self, k):
if k in self._keys:
return None
else:
raise AttributeError
raise AttributeError

def bind_split(s):
if '@' in s:
Expand Down
29 changes: 12 additions & 17 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@ def getEssentialType(expr):
return e
if bitsOfEssentialType(e2) >= bitsOfEssentialType(e1):
return e2
else:
return e1
return e1

elif expr.str == "~":
e1 = getEssentialType(expr.astOperand1)
Expand Down Expand Up @@ -1422,8 +1421,7 @@ def __repr__(self):
def get_num_significant_naming_chars(self, cfg):
if cfg.standards and cfg.standards.c == "c89":
return 31
else:
return 63
return 63

def _save_ctu_summary_typedefs(self, dumpfile, typedef_info):
if self._ctu_summary_typedefs:
Expand Down Expand Up @@ -1694,8 +1692,7 @@ def misra_4_1(self, rawTokens):
if (isHexEscapeSequence(sequence) or isOctalEscapeSequence(sequence) or
isSimpleEscapeSequence(sequence)):
continue
else:
self.reportError(token, 4, 1)
self.reportError(token, 4, 1)

def misra_4_2(self, rawTokens):
for token in rawTokens:
Expand Down Expand Up @@ -2759,10 +2756,10 @@ def misra_12_3(self, data):
if prev.str == ';':
self.reportError(token, 12, 3)
break
elif prev.str in ')}]':
prev = prev.link
elif prev.str in '({[':
if prev.str in '({[':
break
if prev.str in ')}]':
prev = prev.link
prev = prev.previous

def misra_12_4_check_expr(self, expr):
Expand Down Expand Up @@ -2811,7 +2808,7 @@ def misra_12_4(self, cfg):
while expr.str not in (";", "{", "}"):
expr = expr.next
continue
elif known_value == 0:
if known_value == 0:
expr = expr.astOperand2
self.misra_12_4_check_expr(expr)

Expand All @@ -2834,8 +2831,7 @@ def misra_13_1(self, data):
if tn and tn.next and tn.next.str == '=':
tn = tn.next.next
continue
else:
break
break
if tn.str == '.' and tn.next and tn.next.isName:
tn = tn.next
if tn.next and tn.next.str == '=':
Expand Down Expand Up @@ -4088,8 +4084,7 @@ def get_violations(self, violation_type=None):
"""Return the list of violations for a normal checker run"""
if violation_type is None:
return self.violations.items()
else:
return self.violations[violation_type]
return self.violations[violation_type]

def get_violation_types(self):
"""Return the list of violations for a normal checker run"""
Expand Down Expand Up @@ -4432,9 +4427,9 @@ def loadRuleTexts(self, filename):

if severity_loc < 2:
continue
else:
rule.misra_severity = ''
have_severity = True

rule.misra_severity = ''
have_severity = True

if rule is None:
continue
Expand Down
34 changes: 16 additions & 18 deletions addons/misra_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def getChildByValueElement(self, ed):
def getEffectiveLevel(self):
if self.parent and self.parent.elementType == "array":
return self.parent.getEffectiveLevel() + 1
else:
return 0
return 0

def setInitialized(self, designated=False, positional=False):
if designated:
Expand Down Expand Up @@ -201,11 +200,10 @@ def isMisra93Compliant(self):
self.isOnlyDesignated()) and
all([not (child.isDesignated or child.isPositional) or child.isMisra93Compliant() for child in self.children]))
return result
elif self.elementType == 'record':
if self.elementType == 'record':
result = all([child.isMisra93Compliant() for child in self.children])
return result
else:
return True
return True

def isMisra94Compliant(self):
return self.numInits <= 1 and all([child.isMisra94Compliant() for child in self.children])
Expand Down Expand Up @@ -378,22 +376,22 @@ def unwindAndContinue(self):

self.token = self.token.astParent.astOperand2
break
else:
self.token = self.token.astParent
if self.token.str == '{':
if self.root:
self.ed = self.root.getLastValueElement()
self.ed.markAsCurrent()

# Cleanup if root is dummy node representing excess levels in initializer
if self.root.name == '<-':
self.root.children[0].parent = self.root.parent
self.token = self.token.astParent
if self.token.str == '{':
if self.root:
self.ed = self.root.getLastValueElement()
self.ed.markAsCurrent()

self.root = self.root.parent
# Cleanup if root is dummy node representing excess levels in initializer
if self.root.name == '<-':
self.root.children[0].parent = self.root.parent

if self.token.astParent is None:
self.token = None
break
self.root = self.root.parent

if self.token.astParent is None:
self.token = None
break

def misra_9_x(self, data, rule, rawTokens = None):

Expand Down
4 changes: 1 addition & 3 deletions htmlreport/cppcheck-htmlreport
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,7 @@ def main() -> None:
with io.open(source_filename, 'r', encoding=options.source_encoding) as input_file:
content = input_file.read()
except IOError:
if error['id'] == 'unmatchedSuppression':
continue # file not found, bail out
else:
if error['id'] != 'unmatchedSuppression':
sys.stderr.write("ERROR: Source file '%s' not found.\n" %
source_filename)
continue
Expand Down
Loading

0 comments on commit 10f0d2a

Please sign in to comment.