From 567b1dbc2fa178c1d5cc529fb57ad0cbd5cc682b Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 12:18:14 +0200 Subject: [PATCH 01/10] .pylintrc: enabled `W` messages group --- .pylintrc | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/.pylintrc b/.pylintrc index 547417375a0..ed94c79d530 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,18 +1,34 @@ [MESSAGES CONTROL] -disable=C,R,W -enable=mixed-indentation, - trailing-whitespace, - print-statement, - literal-comparison, - unnecessary-semicolon, +disable=C,R, + # W start + redefined-builtin, + broad-exception-caught, + fixme, + bare-except, + redefined-outer-name, + attribute-defined-outside-init, + unspecified-encoding, + global-statement, + protected-access, + redundant-u-string-prefix, + broad-exception-raised, + subprocess-popen-preexec-fn, + format-string-without-interpolation, + cell-var-from-loop, + logging-not-lazy, + unknown-option-value, + implicit-str-concat, + unused-wildcard-import, + pointless-statement, + wildcard-import, + unused-argument, + deprecated-module, + pointless-string-statement, + arguments-renamed, + duplicate-string-formatting-argument +enable=trailing-whitespace, mixed-line-endings, - bad-open-mode, - redundant-unittest-assert, - boolean-datetime, - deprecated-method, - anomalous-unicode-escape-in-string, - anomalous-backslash-in-string, - bad-indentation + literal-comparison [REPORTS] reports=no [TYPECHECK] From 5c3b6aa4f16400e040f4c4d7742e02287a3616f1 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 12:18:59 +0200 Subject: [PATCH 02/10] fixed `unnecessary-pass` pylint warnings --- test/cli/other_test.py | 1 - tools/compare-normal-exhaustive.py | 1 - tools/test-my-pr.py | 2 -- 3 files changed, 4 deletions(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 1206c45c57d..a97345a4048 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -1030,7 +1030,6 @@ def test_valueflow_debug(tmpdir): } """ ) - pass test_file_h_2 = os.path.join(tmpdir, 'test2.h') with open(test_file_h_2, 'wt') as f: f.write(""" diff --git a/tools/compare-normal-exhaustive.py b/tools/compare-normal-exhaustive.py index 7139748331f..e83548901b6 100755 --- a/tools/compare-normal-exhaustive.py +++ b/tools/compare-normal-exhaustive.py @@ -68,7 +68,6 @@ def format_float(a, b=1): cppcheck_path = os.path.join(work_path, 'cppcheck') try: lib.clone_cppcheck(cppcheck_path, '') - pass except Exception as e: print('Failed to clone Cppcheck repository ({}), retry later'.format(e)) sys.exit(1) diff --git a/tools/test-my-pr.py b/tools/test-my-pr.py index 715df3297bb..2f33a824423 100755 --- a/tools/test-my-pr.py +++ b/tools/test-my-pr.py @@ -64,14 +64,12 @@ def format_float(a, b=1): try: lib.clone_cppcheck(repo_dir, old_repo_dir) - pass except Exception as e: print('Failed to clone Cppcheck repository ({}), retry later'.format(e)) sys.exit(1) try: lib.checkout_cppcheck_version(repo_dir, 'main', main_dir) - pass except Exception as e: print('Failed to checkout main ({}), retry later'.format(e)) sys.exit(1) From 0c0dccd70a16e0f29116066f13d72b9cde4c586c Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 12:22:04 +0200 Subject: [PATCH 03/10] mitigated `unused-import` pylint warnings --- addons/misra_9.py | 2 -- addons/namingng.py | 1 - addons/test/misra_test.py | 2 -- test/cli/helloworld_test.py | 1 - test/cli/performance_test.py | 3 +-- test/cli/premium_test.py | 4 +--- test/cli/suppress-syntaxError_test.py | 1 - test/cli/testutils.py | 1 - tools/compare-normal-exhaustive.py | 1 - tools/donate_cpu_lib.py | 1 + 10 files changed, 3 insertions(+), 14 deletions(-) diff --git a/addons/misra_9.py b/addons/misra_9.py index 806d27d225f..7f8e33ac245 100644 --- a/addons/misra_9.py +++ b/addons/misra_9.py @@ -1,5 +1,3 @@ -import cppcheckdata - # Holds information about an array, struct or union's element definition. class ElementDef: def __init__(self, elementType, name, valueType, dimensions = None): diff --git a/addons/namingng.py b/addons/namingng.py index 920ea7afb09..a0e18fcc032 100755 --- a/addons/namingng.py +++ b/addons/namingng.py @@ -36,7 +36,6 @@ import sys import os import re -import argparse import json # Auxiliary class diff --git a/addons/test/misra_test.py b/addons/test/misra_test.py index 546b075a709..9285087993e 100644 --- a/addons/test/misra_test.py +++ b/addons/test/misra_test.py @@ -7,11 +7,9 @@ # Command in cppcheck directory: # PYTHONPATH=./addons python3 -m pytest addons/test/test-misra.py -import os import pytest import re import sys -import tempfile from .util import dump_create, dump_remove, convert_json_output diff --git a/test/cli/helloworld_test.py b/test/cli/helloworld_test.py index 94f136024fe..a59dc349e89 100644 --- a/test/cli/helloworld_test.py +++ b/test/cli/helloworld_test.py @@ -4,7 +4,6 @@ import os import re import tempfile -import pytest import glob from testutils import create_gui_project_file, cppcheck diff --git a/test/cli/performance_test.py b/test/cli/performance_test.py index f79203377c5..0dbd27b085f 100644 --- a/test/cli/performance_test.py +++ b/test/cli/performance_test.py @@ -2,10 +2,9 @@ # python -m pytest test-other.py import os -import sys import pytest -from testutils import cppcheck, assert_cppcheck +from testutils import cppcheck diff --git a/test/cli/premium_test.py b/test/cli/premium_test.py index f8f52401c92..56e88eb5e74 100644 --- a/test/cli/premium_test.py +++ b/test/cli/premium_test.py @@ -1,14 +1,12 @@ # python -m pytest premium_test.py -import logging import os import shutil import sys import time -import pytest -from testutils import cppcheck, assert_cppcheck, __lookup_cppcheck_exe +from testutils import cppcheck, __lookup_cppcheck_exe PRODUCT_NAME = 'Cppcheck Premium ' + str(time.time()) diff --git a/test/cli/suppress-syntaxError_test.py b/test/cli/suppress-syntaxError_test.py index bc3248c8afb..16bd20a753a 100644 --- a/test/cli/suppress-syntaxError_test.py +++ b/test/cli/suppress-syntaxError_test.py @@ -1,7 +1,6 @@ # python -m pytest test-suppress-syntaxError.py -import pytest from testutils import cppcheck def test_j(): diff --git a/test/cli/testutils.py b/test/cli/testutils.py index 2e875e2126c..b7e8b51252c 100644 --- a/test/cli/testutils.py +++ b/test/cli/testutils.py @@ -2,7 +2,6 @@ import logging import os import select -import signal import subprocess import time diff --git a/tools/compare-normal-exhaustive.py b/tools/compare-normal-exhaustive.py index e83548901b6..6eca7f12038 100755 --- a/tools/compare-normal-exhaustive.py +++ b/tools/compare-normal-exhaustive.py @@ -8,7 +8,6 @@ import os import sys import random -import subprocess def format_float(a, b=1): diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index d721914476e..efaffaa6a3a 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -72,6 +72,7 @@ def check_requirements(): result = False try: + # pylint: disable-next=unused-import - intentional import psutil except ImportError as e: print("Error: {}. Module is required.".format(e)) From c1cc713a1955926c0f5b17f1d7f57bb50f1d0923 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 12:25:01 +0200 Subject: [PATCH 04/10] mitigated `super-init-not-called` pylint warnings --- tools/reduce_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/reduce_test.py b/tools/reduce_test.py index 6ea01d28d58..f3e9486634e 100644 --- a/tools/reduce_test.py +++ b/tools/reduce_test.py @@ -3,8 +3,8 @@ class ReduceTest(Reduce): + # pylint: disable-next=super-init-not-called - we do not want the super __init__ to be called def __init__(self): - # we do not want the super __init__ to be called # super().__init__('', '', '') pass From a47bec4e67a68347c4abe6df3ebdc6a55d5d6575 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 12:35:15 +0200 Subject: [PATCH 05/10] mitigated `unused-variable` pylint warnings --- addons/misra.py | 8 +++----- addons/test/y2038_test.py | 1 + htmlreport/cppcheck-htmlreport | 2 +- test/cli/fuzz_test.py | 2 +- test/cli/other_test.py | 34 +++++++++++++++---------------- test/cli/performance_test.py | 6 +++--- test/cli/proj2_test.py | 22 ++++++++++---------- test/cli/samples_test.py | 4 ++-- test/signal/test-signalhandler.py | 8 ++++---- test/signal/test-stacktrace.py | 2 +- tools/MT-Unsafe.py | 2 +- tools/donate-cpu-server.py | 4 ++-- tools/donate_cpu_lib.py | 4 +--- 13 files changed, 48 insertions(+), 51 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index bdd00ebf85f..6c04c91696d 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -635,7 +635,6 @@ def bitsOfEssentialType(ty): def get_function_pointer_type(tok): ret = '' - par = 0 while tok and (tok.isName or tok.str == '*'): ret += ' ' + tok.str tok = tok.next @@ -3965,7 +3964,7 @@ def misra_21_20(self, cfg): # Calling dangerous function if token.str in ('asctime', 'ctime', 'gmtime', 'localtime', 'localeconv', 'getenv', 'setlocale', 'strerror'): - name, args = cppcheckdata.get_function_call_name_args(token) + name, _ = cppcheckdata.get_function_call_name_args(token) if name and name == token.str: # make assigned pointers invalid for varId in assigned.get(name, ()): @@ -4039,7 +4038,7 @@ def misra_22_9(self, cfg): errno_is_set = False for token in cfg.tokenlist: if token.str == '(' and not simpleMatch(token.link, ') {'): - name, args = cppcheckdata.get_function_call_name_args(token.previous) + name, _ = cppcheckdata.get_function_call_name_args(token.previous) if name is None: continue errno_is_set = is_errno_setting_function(name) @@ -4057,7 +4056,7 @@ def misra_22_10(self, cfg): last_function_call = None for token in cfg.tokenlist: if token.isName and token.next and token.next.str == '(' and not simpleMatch(token.next.link, ') {'): - name, args = cppcheckdata.get_function_call_name_args(token) + name, _ = cppcheckdata.get_function_call_name_args(token) last_function_call = name if token.str == '}': last_function_call = None @@ -4351,7 +4350,6 @@ def loadRuleTexts(self, filename): num1 = 0 num2 = 0 appendixA = False - ruleText = False expect_more = False Rule_pattern = re.compile(r'^Rule ([0-9]+).([0-9]+)') diff --git a/addons/test/y2038_test.py b/addons/test/y2038_test.py index f76a87613e7..282e55650d7 100644 --- a/addons/test/y2038_test.py +++ b/addons/test/y2038_test.py @@ -81,6 +81,7 @@ def test_3_no_use_time_bits(capsys): def test_4_good(capsys): + # pylint: disable-next=unused-variable - FIXME is_safe = check_y2038_safe('./addons/test/y2038/y2038-test-4-good.c.dump', quiet=True) # assert(is_safe is True) # FIXME: This should be a "good" example returning "True" instead of "False" captured = capsys.readouterr() diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 3415f3b6087..0ac928fd517 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -647,7 +647,7 @@ def main() -> None: '-M --> not including moving of lines and returns original author of the line') # Parse options and make sure that we have an output directory set. - options, args = parser.parse_args() + options, _ = parser.parse_args() try: sys.argv[1] diff --git a/test/cli/fuzz_test.py b/test/cli/fuzz_test.py index 3264b6c34eb..b8cf09a5657 100644 --- a/test/cli/fuzz_test.py +++ b/test/cli/fuzz_test.py @@ -39,7 +39,7 @@ def test_fuzz_timeout(): fuzz_timeout_dir = os.path.join(__script_dir, 'fuzz-timeout') for f in os.listdir(fuzz_timeout_dir): try: - ret, stdout, _ = cppcheck(['-q', '--language=c++', '--enable=all', '--inconclusive', f], cwd=fuzz_timeout_dir, timeout=5) + cppcheck(['-q', '--language=c++', '--enable=all', '--inconclusive', f], cwd=fuzz_timeout_dir, timeout=5) except subprocess.TimeoutExpired: failures.append(f) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index a97345a4048..326b831648e 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -265,7 +265,7 @@ def test_addon_ctu_exitcode(tmpdir): with open(test_file, 'wt') as f: f.write("""typedef enum { BLOCK = 0x80U, } E;""") args = ['--addon=misra', '--enable=style', '--error-exitcode=1', test_file] - exitcode, stdout, stderr = cppcheck(args) + exitcode, _, stderr = cppcheck(args) assert '2.3' in stderr, stderr assert exitcode == 1 @@ -587,7 +587,7 @@ def test_addon_namingng_config(tmpdir): test_file_basename = 'test.c' test_file = os.path.join(tmpdir, test_file_basename) - with open(test_file, 'a') as f: + with open(test_file, 'a'): # only create the file pass @@ -852,7 +852,7 @@ def test_missing_addon(tmpdir): def test_file_filter(tmpdir): test_file = os.path.join(tmpdir, 'test.cpp') - with open(test_file, 'wt') as f: + with open(test_file, 'wt'): pass args = ['--file-filter=*.cpp', test_file] @@ -865,10 +865,10 @@ def test_file_filter(tmpdir): def test_file_filter_2(tmpdir): test_file_1 = os.path.join(tmpdir, 'test.cpp') - with open(test_file_1, 'wt') as f: + with open(test_file_1, 'wt'): pass test_file_2 = os.path.join(tmpdir, 'test.c') - with open(test_file_2, 'wt') as f: + with open(test_file_2, 'wt'): pass args = ['--file-filter=*.cpp', test_file_1, test_file_2] @@ -881,10 +881,10 @@ def test_file_filter_2(tmpdir): def test_file_filter_3(tmpdir): test_file_1 = os.path.join(tmpdir, 'test.cpp') - with open(test_file_1, 'wt') as f: + with open(test_file_1, 'wt'): pass test_file_2 = os.path.join(tmpdir, 'test.c') - with open(test_file_2, 'wt') as f: + with open(test_file_2, 'wt'): pass args = ['--file-filter=*.c', test_file_1, test_file_2] @@ -942,16 +942,16 @@ def test_file_order(tmpdir): def test_markup(tmpdir): test_file_1 = os.path.join(tmpdir, 'test_1.qml') - with open(test_file_1, 'wt') as f: + with open(test_file_1, 'wt'): pass test_file_2 = os.path.join(tmpdir, 'test_2.cpp') - with open(test_file_2, 'wt') as f: + with open(test_file_2, 'wt'): pass test_file_3 = os.path.join(tmpdir, 'test_3.qml') - with open(test_file_3, 'wt') as f: + with open(test_file_3, 'wt'): pass test_file_4 = os.path.join(tmpdir, 'test_4.cpp') - with open(test_file_4, 'wt') as f: + with open(test_file_4, 'wt'): pass args = ['--library=qt', test_file_1, test_file_2, test_file_3, test_file_4, '-j1'] @@ -971,16 +971,16 @@ def test_markup(tmpdir): def test_markup_j(tmpdir): test_file_1 = os.path.join(tmpdir, 'test_1.qml') - with open(test_file_1, 'wt') as f: + with open(test_file_1, 'wt'): pass test_file_2 = os.path.join(tmpdir, 'test_2.cpp') - with open(test_file_2, 'wt') as f: + with open(test_file_2, 'wt'): pass test_file_3 = os.path.join(tmpdir, 'test_3.qml') - with open(test_file_3, 'wt') as f: + with open(test_file_3, 'wt'): pass test_file_4 = os.path.join(tmpdir, 'test_4.cpp') - with open(test_file_4, 'wt') as f: + with open(test_file_4, 'wt'): pass args = ['--library=qt', '-j2', test_file_1, test_file_2, test_file_3, test_file_4] @@ -1562,10 +1562,10 @@ def test_filelist(tmpdir): def test_markup_lang(tmpdir): test_file_1 = os.path.join(tmpdir, 'test_1.qml') - with open(test_file_1, 'wt') as f: + with open(test_file_1, 'wt'): pass test_file_2 = os.path.join(tmpdir, 'test_2.cpp') - with open(test_file_2, 'wt') as f: + with open(test_file_2, 'wt'): pass # do not assert processing markup file with enforced language diff --git a/test/cli/performance_test.py b/test/cli/performance_test.py index 0dbd27b085f..f2eecff570c 100644 --- a/test/cli/performance_test.py +++ b/test/cli/performance_test.py @@ -15,7 +15,7 @@ def test_slow_array_many_floats(tmpdir): filename = os.path.join(tmpdir, 'hang.c') with open(filename, 'wt') as f: f.write("const float f[] = {\n") - for i in range(20000): + for _ in range(20000): f.write(' 13.6f,\n') f.write("};\n") cppcheck([filename]) # should not take more than ~1 second @@ -28,7 +28,7 @@ def test_slow_array_many_strings(tmpdir): filename = os.path.join(tmpdir, 'hang.c') with open(filename, 'wt') as f: f.write("const char *strings[] = {\n") - for i in range(20000): + for _ in range(20000): f.write(' "abc",\n') f.write("};\n") cppcheck([filename]) # should not take more than ~1 second @@ -40,7 +40,7 @@ def test_slow_long_line(tmpdir): filename = os.path.join(tmpdir, 'hang.c') with open(filename, 'wt') as f: f.write("#define A() static const int a[] = {\\\n") - for i in range(5000): + for _ in range(5000): f.write(" -123, 456, -789,\\\n") f.write("};\n") cppcheck([filename]) # should not take more than ~1 second diff --git a/test/cli/proj2_test.py b/test/cli/proj2_test.py index 868d832ddf0..89e7d8757bc 100644 --- a/test/cli/proj2_test.py +++ b/test/cli/proj2_test.py @@ -32,18 +32,18 @@ def cppcheck_local(args): return ret, stdout, stderr def test_file_filter(): - ret, stdout, stderr = cppcheck(['proj2/','--file-filter=proj2/a/*']) + ret, stdout, _ = cppcheck(['proj2/','--file-filter=proj2/a/*']) file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0 assert stdout.find('Checking %s ...' % file1) >= 0 - ret, stdout, stderr = cppcheck(['proj2/','--file-filter=proj2/b*']) + ret, stdout, _ = cppcheck(['proj2/','--file-filter=proj2/b*']) assert ret == 0, stdout assert stdout.find('Checking %s ...' % file2) >= 0 def test_local_path(): create_compile_commands() - ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json']) + ret, stdout, _ = cppcheck_local(['--project=compile_commands.json']) file1 = os.path.join('a', 'a.c') file2 = os.path.join('b', 'b.c') assert ret == 0, stdout @@ -52,19 +52,19 @@ def test_local_path(): def test_local_path_force(): create_compile_commands() - ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json', '--force']) + ret, stdout, _ = cppcheck_local(['--project=compile_commands.json', '--force']) assert ret == 0, stdout assert stdout.find('AAA') >= 0 def test_local_path_maxconfigs(): create_compile_commands() - ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json', '--max-configs=2']) + ret, stdout, _ = cppcheck_local(['--project=compile_commands.json', '--max-configs=2']) assert ret == 0, stdout assert stdout.find('AAA') >= 0 def test_relative_path(): create_compile_commands() - ret, stdout, stderr = cppcheck(['--project=proj2/' + COMPILE_COMMANDS_JSON]) + ret, stdout, _ = cppcheck(['--project=proj2/' + COMPILE_COMMANDS_JSON]) file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0, stdout @@ -73,7 +73,7 @@ def test_relative_path(): def test_absolute_path(): create_compile_commands() - ret, stdout, stderr = cppcheck(['--project=' + os.path.realpath('proj2/' + COMPILE_COMMANDS_JSON)]) + ret, stdout, _ = cppcheck(['--project=' + os.path.realpath('proj2/' + COMPILE_COMMANDS_JSON)]) file1 = os.path.realpath('proj2/a/a.c') file2 = os.path.realpath('proj2/b/b.c') assert ret == 0, stdout @@ -82,7 +82,7 @@ def test_absolute_path(): def test_gui_project_loads_compile_commands_1(): create_compile_commands() - ret, stdout, stderr = cppcheck(['--project=proj2/proj2.cppcheck']) + ret, stdout, _ = cppcheck(['--project=proj2/proj2.cppcheck']) file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0, stdout @@ -95,7 +95,7 @@ def test_gui_project_loads_compile_commands_2(): create_gui_project_file('proj2/test.cppcheck', import_project='compile_commands.json', exclude_paths=[exclude_path_1]) - ret, stdout, stderr = cppcheck(['--project=proj2/test.cppcheck']) + ret, stdout, _ = cppcheck(['--project=proj2/test.cppcheck']) file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') # Excluded by test.cppcheck assert ret == 0, stdout @@ -105,7 +105,7 @@ def test_gui_project_loads_compile_commands_2(): def test_gui_project_loads_relative_vs_solution(): create_gui_project_file('test.cppcheck', import_project='proj2/proj2.sln') - ret, stdout, stderr = cppcheck(['--project=test.cppcheck']) + ret, stdout, _ = cppcheck(['--project=test.cppcheck']) file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0, stdout @@ -120,7 +120,7 @@ def test_gui_project_loads_relative_vs_solution(): def test_gui_project_loads_absolute_vs_solution(): create_gui_project_file('test.cppcheck', import_project=realpath('proj2/proj2.sln')) - ret, stdout, stderr = cppcheck(['--project=test.cppcheck']) + ret, stdout, _ = cppcheck(['--project=test.cppcheck']) file1 = os.path.realpath('proj2/a/a.c') file2 = os.path.realpath('proj2/b/b.c') print(stdout) diff --git a/test/cli/samples_test.py b/test/cli/samples_test.py index 71848936e80..44bbbbb526e 100644 --- a/test/cli/samples_test.py +++ b/test/cli/samples_test.py @@ -29,12 +29,12 @@ def test_samples(): bad_src = os.path.join('samples', entry, 'bad.c') # check that good input does not produce any warnings - ret, stdout, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', good_src], cwd=__root_dir) + ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', good_src], cwd=__root_dir) if not ret == 0: failures[good_src] = stderr # check that the bad inout produces a warning - ret, stdout, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', bad_src], cwd=__root_dir) + ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', bad_src], cwd=__root_dir) if not ret == 1: failures[bad_src] = stderr diff --git a/test/signal/test-signalhandler.py b/test/signal/test-signalhandler.py index 2d9939f101d..c5ed2eb202c 100644 --- a/test/signal/test-signalhandler.py +++ b/test/signal/test-signalhandler.py @@ -31,7 +31,7 @@ def _call_process(arg): def test_assert(): - exitcode, stdout, stderr = _call_process('assert') + _, stdout, stderr = _call_process('assert') if sys.platform == "darwin": assert stderr.startswith("Assertion failed: (false), function my_assert, file test-signalhandler.cpp, line "), stderr else: @@ -46,7 +46,7 @@ def test_assert(): def test_abort(): - exitcode, stdout, stderr = _call_process('abort') + _, stdout, _ = _call_process('abort') lines = stdout.splitlines() assert lines[0] == 'Internal error: cppcheck received signal SIGABRT - abort or assertion' # no stacktrace on MaCos @@ -57,7 +57,7 @@ def test_abort(): def test_segv(): - exitcode, stdout, stderr = _call_process('segv') + _, stdout, stderr = _call_process('segv') assert stderr == '' lines = stdout.splitlines() if sys.platform == "darwin": @@ -74,7 +74,7 @@ def test_segv(): # TODO: make this work @pytest.mark.skip def test_fpe(): - exitcode, stdout, stderr = _call_process('fpe') + _, stdout, stderr = _call_process('fpe') assert stderr == '' lines = stdout.splitlines() assert lines[0].startswith('Internal error: cppcheck received signal SIGFPE - FPE_FLTDIV (at 0x7f'), lines[0] diff --git a/test/signal/test-stacktrace.py b/test/signal/test-stacktrace.py index 8f9e5763207..3d92b253728 100644 --- a/test/signal/test-stacktrace.py +++ b/test/signal/test-stacktrace.py @@ -30,7 +30,7 @@ def _call_process(): def test_stack(): - exitcode, stdout, stderr = _call_process() + _, stdout, stderr = _call_process() assert stderr == '' lines = stdout.splitlines() assert lines[0] == 'Callstack:' diff --git a/tools/MT-Unsafe.py b/tools/MT-Unsafe.py index a30395ff011..9783993090d 100755 --- a/tools/MT-Unsafe.py +++ b/tools/MT-Unsafe.py @@ -149,7 +149,7 @@ def do_man_dir(directory): if os.path.isfile(directory): return do_man_page(directory) - for path, directories, files in os.walk(directory): + for path, _, files in os.walk(directory): for file in files: dprint(2, 'calling do_man_page(%s)' % ( os.path.join(path, file))) diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py index 96d4c60fb36..cdf79fa2f4f 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.54" +SERVER_VERSION = "1.3.55" OLD_VERSION = '2.14.0' @@ -1282,7 +1282,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa while True: # wait for a connection print_ts('waiting for a connection') - connection, client_address = sock.accept() + connection, _ = sock.accept() try: bytes_received = connection.recv(128) cmd = bytes_received.decode('utf-8', 'ignore') diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index efaffaa6a3a..6c409acaa7e 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -37,10 +37,8 @@ def detect_make(): for m in make_cmds: try: - #print('{} --version'.format(m)) subprocess.check_call([m, '--version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - except OSError as e: - #print("'{}' not found ({})".format(m, e)) + except OSError: continue print("using '{}'".format(m)) From 8e4b090d60436ec2305ab50e61ca0b2f2c4f27b1 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 12:38:19 +0200 Subject: [PATCH 06/10] fixed `duplicate-value` pylint warnings --- addons/y2038.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/y2038.py b/addons/y2038.py index 7c8f409dc5a..93d237afd06 100755 --- a/addons/y2038.py +++ b/addons/y2038.py @@ -57,7 +57,6 @@ 'timeval', 'utimbuf', 'itimerspec', - 'stat', 'clnt_ops', 'elf_prstatus', 'itimerval', From 7e3294fa3d84aa37a6563f22e01ba1168dbd90a0 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 15:10:33 +0200 Subject: [PATCH 07/10] mitigated `deprecated-argument` pylint warnings --- tools/daca2-download.py | 1 + tools/donate_cpu_lib.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/daca2-download.py b/tools/daca2-download.py index 8a05332abda..5891e66f1d8 100755 --- a/tools/daca2-download.py +++ b/tools/daca2-download.py @@ -90,6 +90,7 @@ def removeAll(): try: for filename in filenames: if os.path.isdir(filename): + # pylint: disable=deprecated-argument - FIXME: onerror was deprecated in Python 3.12 shutil.rmtree(filename, onerror=handleRemoveReadonly) else: os.remove(filename) diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py index 6c409acaa7e..3020a63b08f 100644 --- a/tools/donate_cpu_lib.py +++ b/tools/donate_cpu_lib.py @@ -299,6 +299,7 @@ def __remove_tree(folder_name): return def rmtree_func(): + # pylint: disable=deprecated-argument - FIXME: onerror was deprecated in Python 3.12 shutil.rmtree(folder_name, onerror=__handle_remove_readonly) print('Removing existing temporary data...') From 43ef9c4bb7bceddbd88972de5333e0846d36fc30 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 15:13:33 +0200 Subject: [PATCH 08/10] .pylintrc: enabled `C` messages group --- .pylintrc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index ed94c79d530..e03190cbd8f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,5 +1,5 @@ [MESSAGES CONTROL] -disable=C,R, +disable=R, # W start redefined-builtin, broad-exception-caught, @@ -25,10 +25,28 @@ disable=C,R, deprecated-module, pointless-string-statement, arguments-renamed, - duplicate-string-formatting-argument -enable=trailing-whitespace, - mixed-line-endings, - literal-comparison + duplicate-string-formatting-argument, + # C start + consider-using-f-string, + invalid-name, + line-too-long, + missing-module-docstring, + missing-function-docstring, + import-outside-toplevel, + missing-class-docstring, + superfluous-parens, + too-many-lines, + trailing-newlines, + missing-final-newline, + unnecessary-negation, + use-implicit-booleaness-not-len, + wrong-import-order, + use-implicit-booleaness-not-comparison, + multiple-imports, + consider-using-enumerate, + unnecessary-lambda-assignment, + consider-using-dict-items, + consider-iterating-dictionary [REPORTS] reports=no [TYPECHECK] From a59bb45bb6e86133b7005e8596fe9bbaee06c13e Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 15:20:57 +0200 Subject: [PATCH 09/10] fixed `singleton-comparison` pylint warnings --- addons/cppcheckdata.py | 12 ++++++------ addons/misc.py | 2 +- addons/namingng.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 2de7a3512e3..5340e3d5ade 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -978,22 +978,22 @@ def __repr__(self): def isMatch(self, file, line, message, errorId): # Line Suppression if ((self.fileName is None or fnmatch(file, self.fileName)) - and (self.suppressionType == None) # Verify use of default suppression type (None = unique) - and (self.lineNumber != None and int(line) == int(self.lineNumber)) + and (self.suppressionType is None) # Verify use of default suppression type (None = unique) + and (self.lineNumber is not None and int(line) == int(self.lineNumber)) and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*')) and fnmatch(errorId, self.errorId)): return True # File Suppression if ((self.fileName is None or fnmatch(file, self.fileName)) - and (self.suppressionType != None and self.suppressionType == "file") # Verify use of file (global) suppression type + and (self.suppressionType is not None and self.suppressionType == "file") # Verify use of file (global) suppression type and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*')) and fnmatch(errorId, self.errorId)): return True # Block Suppression Mode if ((self.fileName is None or fnmatch(file, self.fileName)) - and (self.suppressionType != None and self.suppressionType == "block") # Type for Block suppression - and (self.lineBegin != None and int(line) > int(self.lineBegin)) # Code Match is between the Block suppression - and (self.lineEnd != None and int(line) < int(self.lineEnd)) # Code Match is between the Block suppression + and (self.suppressionType is not None and self.suppressionType == "block") # Type for Block suppression + and (self.lineBegin is not None and int(line) > int(self.lineBegin)) # Code Match is between the Block suppression + and (self.lineEnd is not None and int(line) < int(self.lineEnd)) # Code Match is between the Block suppression and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*')) and fnmatch(errorId, self.errorId)): return True diff --git a/addons/misc.py b/addons/misc.py index 15a742c28f9..670d6152ff5 100644 --- a/addons/misc.py +++ b/addons/misc.py @@ -16,7 +16,7 @@ VERIFY_ACTUAL = [] def reportError(token, severity, msg, id): - if id == 'debug' and DEBUG == False: + if id == 'debug' and not DEBUG: return if VERIFY: VERIFY_ACTUAL.append(str(token.linenr) + ':' + id) diff --git a/addons/namingng.py b/addons/namingng.py index a0e18fcc032..9da177321ef 100755 --- a/addons/namingng.py +++ b/addons/namingng.py @@ -242,7 +242,7 @@ def report_pending_ifndef(directive,column): phase = -1 continue guard_name,guard_column = check_include_guard_name(conf,directive) - if guard_name == None: + if guard_name is None: phase = -1 continue pending_ifndef = directive From b66244baae18631f525511ee138ada75c8584b6d Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 11 Jun 2024 15:33:00 +0200 Subject: [PATCH 10/10] .pylintrc: enabled `R` messages group --- .pylintrc | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index e03190cbd8f..03c7bddf103 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,5 +1,5 @@ [MESSAGES CONTROL] -disable=R, +disable= # W start redefined-builtin, broad-exception-caught, @@ -46,7 +46,35 @@ disable=R, consider-using-enumerate, unnecessary-lambda-assignment, consider-using-dict-items, - consider-iterating-dictionary + consider-iterating-dictionary, + # R start + duplicate-code, + consider-using-with, + too-many-statements, + too-many-branches, + use-list-literal, + 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, + too-many-public-methods, + consider-using-sys-exit, + use-dict-literal, + chained-comparison, + too-many-instance-attributes, + consider-using-join, + too-many-boolean-expressions, + useless-object-inheritance, + use-a-generator [REPORTS] reports=no [TYPECHECK]