Skip to content
90 changes: 76 additions & 14 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,80 @@
[MESSAGES CONTROL]
disable=C,R,W
enable=mixed-indentation,
trailing-whitespace,
print-statement,
literal-comparison,
unnecessary-semicolon,
mixed-line-endings,
bad-open-mode,
redundant-unittest-assert,
boolean-datetime,
deprecated-method,
anomalous-unicode-escape-in-string,
anomalous-backslash-in-string,
bad-indentation
disable=
# 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,
# 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,
# 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]
Expand Down
12 changes: 6 additions & 6 deletions addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion addons/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ()):
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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]+)')
Expand Down
2 changes: 0 additions & 2 deletions addons/misra_9.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 1 addition & 2 deletions addons/namingng.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import sys
import os
import re
import argparse
import json

# Auxiliary class
Expand Down Expand Up @@ -243,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
Expand Down
2 changes: 0 additions & 2 deletions addons/test/misra_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions addons/test/y2038_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion addons/y2038.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
'timeval',
'utimbuf',
'itimerspec',
'stat',
'clnt_ops',
'elf_prstatus',
'itimerval',
Expand Down
2 changes: 1 addition & 1 deletion htmlreport/cppcheck-htmlreport
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/cli/fuzz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import re
import tempfile
import pytest
import glob

from testutils import create_gui_project_file, cppcheck
Expand Down
35 changes: 17 additions & 18 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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']
Expand All @@ -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]
Expand Down Expand Up @@ -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("""
Expand Down Expand Up @@ -1563,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
Expand Down
Loading