From ed52d1c7ecf0eaf447b9dbda10a1df053b81fe9e Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 16:15:51 +0200 Subject: [PATCH 1/4] enabled and fixed `no-else-return` pylint warnings --- .pylintrc | 1 - addons/cppcheckdata.py | 3 +-- addons/misra.py | 9 +++------ addons/misra_9.py | 8 +++----- tools/donate_cpu_lib.py | 18 +++++++++--------- tools/matchcompiler.py | 30 +++++++++++++++--------------- 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/.pylintrc b/.pylintrc index a7f650b36b9..99cd36703de 100644 --- a/.pylintrc +++ b/.pylintrc @@ -56,7 +56,6 @@ disable= simplifiable-if-statement, too-many-locals, too-many-arguments, - no-else-return, too-few-public-methods, consider-using-min-builtin, comparison-with-itself, diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 2288c431006..fdc4e3006cb 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -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: diff --git a/addons/misra.py b/addons/misra.py index 551f4fbf028..6d7f67185f1 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -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) @@ -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: @@ -4088,8 +4086,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""" diff --git a/addons/misra_9.py b/addons/misra_9.py index b9a2f33baab..247045a0c4f 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -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: @@ -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]) diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 8ed67569cc9..6ea2d696754 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -139,15 +139,15 @@ def checkout_cppcheck_version(repo_path, version, cppcheck_path): if not has_changes: print('No changes detected') return has_changes - else: - if version != 'main': - print('Fetching {}'.format(version)) - # Since this is a shallow clone, explicitly fetch the remote version tag - refspec = 'refs/tags/' + version + ':ref/tags/' + version - subprocess.check_call(['git', 'fetch', '--depth=1', 'origin', refspec], cwd=repo_path) - print('Adding worktree \'{}\' for {}'.format(cppcheck_path, version)) - subprocess.check_call(['git', 'worktree', 'add', cppcheck_path, version], cwd=repo_path) - return True + + if version != 'main': + print('Fetching {}'.format(version)) + # Since this is a shallow clone, explicitly fetch the remote version tag + refspec = 'refs/tags/' + version + ':ref/tags/' + version + subprocess.check_call(['git', 'fetch', '--depth=1', 'origin', refspec], cwd=repo_path) + print('Adding worktree \'{}\' for {}'.format(cppcheck_path, version)) + subprocess.check_call(['git', 'worktree', 'add', cppcheck_path, version], cwd=repo_path) + return True def get_cppcheck_info(cppcheck_path): diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py index e8023738b77..40cccdcd273 100755 --- a/tools/matchcompiler.py +++ b/tools/matchcompiler.py @@ -158,35 +158,35 @@ def _insertMatchFunctionId( def _compileCmd(tok): if tok == '%any%': return 'true' - elif tok == '%assign%': + if tok == '%assign%': return 'tok->isAssignmentOp()' - elif tok == '%bool%': + if tok == '%bool%': return 'tok->isBoolean()' - elif tok == '%char%': + if tok == '%char%': return '(tok->tokType() == Token::eChar)' - elif tok == '%comp%': + if tok == '%comp%': return 'tok->isComparisonOp()' - elif tok == '%num%': + if tok == '%num%': return 'tok->isNumber()' - elif tok == '%cop%': + if tok == '%cop%': return 'tok->isConstOp()' - elif tok == '%op%': + if tok == '%op%': return 'tok->isOp()' - elif tok == '%or%': + if tok == '%or%': return '(tok->tokType() == Token::eBitOp && tok->str() == MatchCompiler::makeConstString("|") )' - elif tok == '%oror%': + if tok == '%oror%': return '(tok->tokType() == Token::eLogicalOp && tok->str() == MatchCompiler::makeConstString("||"))' - elif tok == '%str%': + if tok == '%str%': return '(tok->tokType() == Token::eString)' - elif tok == '%type%': + if tok == '%type%': return '(tok->isName() && tok->varId() == 0U)' - elif tok == '%name%': + if tok == '%name%': return 'tok->isName()' - elif tok == '%var%': + if tok == '%var%': return '(tok->varId() != 0)' - elif tok == '%varid%': + if tok == '%varid%': return '(tok->isName() && tok->varId() == varid)' - elif (len(tok) > 2) and (tok[0] == "%"): + if (len(tok) > 2) and (tok[0] == "%"): print("unhandled:" + tok) elif tok in tokTypes: cond = ' || '.join(['tok->tokType() == Token::{}'.format(tokType) for tokType in tokTypes[tok]]) From 552d183c700f4569621419899646c9d09bf04523 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 16:20:22 +0200 Subject: [PATCH 2/4] enabled and fixed `no-else-break` pylint warnings --- .pylintrc | 1 - addons/misra.py | 6 +++--- addons/misra_9.py | 26 ++++++++++++------------- tools/donate-cpu-server.py | 40 +++++++++++++++----------------------- 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index 99cd36703de..b9f17ec7411 100644 --- a/.pylintrc +++ b/.pylintrc @@ -61,7 +61,6 @@ disable= comparison-with-itself, too-many-return-statements, no-else-continue, - no-else-break, inconsistent-return-statements, consider-using-in, too-many-nested-blocks, diff --git a/addons/misra.py b/addons/misra.py index 6d7f67185f1..f04bdd9cbf8 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2757,10 +2757,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): diff --git a/addons/misra_9.py b/addons/misra_9.py index 247045a0c4f..1ca1b7ce3e0 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -376,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): diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 7908ac7cf96..1cc973ab8c6 100755 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -222,9 +222,8 @@ def crashReport(results_path: str, query_params: dict): if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'): datestr = line elif pkgs is not None and package_url is None and line.startswith('ftp://'): @@ -323,9 +322,8 @@ def timeoutReport(results_path: str) -> str: if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'): datestr = line elif line.startswith('count:'): @@ -611,9 +609,8 @@ def summaryReport(resultsPath: str, name: str, prefix: str, marker: str) -> str: if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if line.startswith(marker): inResults = True continue @@ -675,9 +672,8 @@ def messageIdReport(resultPath: str, marker: str, messageId: str, query_params: if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if line.startswith('ftp://'): url = line continue @@ -782,9 +778,8 @@ def timeReport(resultPath: str, show_gt: bool, query_params: dict): if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'): datestr = line continue @@ -883,9 +878,8 @@ def timeReportSlow(resultPath: str) -> str: if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'): datestr = line continue @@ -971,9 +965,8 @@ def check_library_report(result_path: str, message_id: str) -> str: if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if not in_results: if line.startswith(start_marker): in_results = True @@ -1037,9 +1030,8 @@ def check_library_function_name(result_path: str, function_name: str, query_para if OLD_VERSION not in line: # Package results seem to be too old, skip break - else: - # Current package, parse on - continue + # Current package, parse on + continue if line.startswith('ftp://'): package_url = line continue From e400842c171c25ba0b0bde8872617e1f5f52b0f5 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 16:24:38 +0200 Subject: [PATCH 3/4] enabled and fixed `no-else-continue` pylint warnings --- .pylintrc | 1 - addons/cppcheckdata.py | 6 ++--- addons/misra.py | 14 +++++------- htmlreport/cppcheck-htmlreport | 4 +--- tools/donate-cpu-server.py | 40 +++++++++++++++++----------------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/.pylintrc b/.pylintrc index b9f17ec7411..b00b486e4a8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -60,7 +60,6 @@ disable= consider-using-min-builtin, comparison-with-itself, too-many-return-statements, - no-else-continue, inconsistent-return-statements, consider-using-in, too-many-nested-blocks, diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index fdc4e3006cb..a7fa1bd74b3 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -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 @@ -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 @@ -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 diff --git a/addons/misra.py b/addons/misra.py index f04bdd9cbf8..083392807be 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1692,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: @@ -2809,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) @@ -2832,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 == '=': @@ -4429,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 diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 0ac928fd517..9196431f781 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -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 diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 1cc973ab8c6..7935b1c9033 100755 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -462,7 +462,7 @@ def generate_package_diff_statistics(filename: str) -> None: if line == 'diff:': is_diff = True continue - elif not is_diff: + if not is_diff: continue if not line.endswith(']'): continue @@ -783,7 +783,7 @@ def timeReport(resultPath: str, show_gt: bool, query_params: dict): if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'): datestr = line continue - elif pkgs is not None and package_url is None and line.startswith('ftp://'): + if pkgs is not None and package_url is None and line.startswith('ftp://'): package_url = line if not line.startswith('elapsed-time:'): continue @@ -883,7 +883,7 @@ def timeReportSlow(resultPath: str) -> str: if datestr is None and line.startswith(str(current_year) + '-') or line.startswith(str(current_year - 1) + '-'): datestr = line continue - elif line.startswith('count:'): + if line.startswith('count:'): count_head = line.split()[1] if count_head == 'TO!': # ignore results with timeouts @@ -1379,13 +1379,13 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa newThread = HttpClientThread(connection, cmd, resultPath, latestResults) newThread.start() continue - elif cmd == 'GetCppcheckVersions\n': + if cmd == 'GetCppcheckVersions\n': reply = 'head ' + OLD_VERSION print_ts('GetCppcheckVersions: ' + reply) connection.send(reply.encode('utf-8', 'ignore')) connection.close() continue - elif cmd == 'get\n': + if cmd == 'get\n': while True: pkg = packages[packageIndex] packageIndex += 1 @@ -1401,7 +1401,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa connection.send(pkg.encode('utf-8', 'ignore')) connection.close() continue - elif cmd.startswith('write\nftp://') or cmd.startswith('write\nhttp://'): + if cmd.startswith('write\nftp://') or cmd.startswith('write\nhttp://'): t_start = time.perf_counter() data = read_data(connection, cmd, pos_nl, max_data_size=1024 * 1024, check_done=True, cmd_name='write') if data is None: @@ -1462,7 +1462,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa generate_package_diff_statistics(filename) print_ts('write finished for {} ({} bytes / {}s)'.format(res.group(1), len(data), (time.perf_counter() - t_start))) continue - elif cmd.startswith('write_info\nftp://') or cmd.startswith('write_info\nhttp://'): + if cmd.startswith('write_info\nftp://') or cmd.startswith('write_info\nhttp://'): t_start = time.perf_counter() data = read_data(connection, cmd, pos_nl, max_data_size=7 * 1024 * 1024, check_done=True, cmd_name='write_info') if data is None: @@ -1501,13 +1501,13 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa f.write(strDateTime() + '\n' + data) print_ts('write_info finished for {} ({} bytes / {}s)'.format(res.group(1), len(data), (time.perf_counter() - t_start))) continue - elif cmd == 'getPackagesCount\n': + if cmd == 'getPackagesCount\n': packages_count = str(len(packages)) connection.send(packages_count.encode('utf-8', 'ignore')) print_ts('getPackagesCount: ' + packages_count) connection.close() continue - elif cmd.startswith('getPackageIdx'): + if cmd.startswith('getPackageIdx'): request_idx = abs(int(cmd[len('getPackageIdx:'):])) if request_idx < len(packages): pkg = packages[request_idx] @@ -1517,7 +1517,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa print_ts('getPackageIdx: index {} is out of range'.format(request_idx)) connection.close() continue - elif cmd.startswith('write_nodata\nftp://'): + if cmd.startswith('write_nodata\nftp://'): data = read_data(connection, cmd, pos_nl, max_data_size=8 * 1024, check_done=False, cmd_name='write_nodata') if data is None: continue @@ -1549,17 +1549,17 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa print_ts('write_nodata:' + url + ' - package not found') break continue + + if pos_nl < 0: + print_ts('invalid command: "' + firstLine + '"') else: - if pos_nl < 0: - print_ts('invalid command: "' + firstLine + '"') - else: - lines = cmd.split('\n') - s = '\\n'.join(lines[:2]) - if len(lines) > 2: - s += '...' - print_ts('invalid command: "' + s + '"') - connection.close() - continue + lines = cmd.split('\n') + s = '\\n'.join(lines[:2]) + if len(lines) > 2: + s += '...' + print_ts('invalid command: "' + s + '"') + connection.close() + continue if __name__ == "__main__": From c099d43cf72315b7cde5d0df1ababdba32d49b69 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 8 Oct 2024 16:23:31 +0200 Subject: [PATCH 4/4] bumped versions of the daca scripts --- tools/donate-cpu-server.py | 2 +- tools/donate_cpu_lib.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 7935b1c9033..75fc4954a93 100755 --- a/tools/donate-cpu-server.py +++ b/tools/donate-cpu-server.py @@ -26,7 +26,7 @@ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # changes) -SERVER_VERSION = "1.3.58" +SERVER_VERSION = "1.3.59" OLD_VERSION = '2.15.0' diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 6ea2d696754..e7394d5593e 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -16,7 +16,7 @@ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # changes) -CLIENT_VERSION = "1.3.61" +CLIENT_VERSION = "1.3.62" # Timeout for analysis with Cppcheck in seconds CPPCHECK_TIMEOUT = 30 * 60