From 1c1330ac630cd5e0cfe62721565233f64d5aa326 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 16:24:38 +0200 Subject: [PATCH] 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 b9f17ec74112..b00b486e4a85 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 fc3e0facf31f..e2fe2e9e88a8 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 f04bdd9cbf82..083392807beb 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 0ac928fd5179..9196431f7811 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 1cc973ab8c62..7935b1c9033e 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__":