Skip to content

Commit 06ce840

Browse files
authored
scriptcheck.yml: re-enabled pylint and mitigated findings / added missing files to Python syntax and lint check (#6464)
1 parent adb2260 commit 06ce840

12 files changed

+56
-49
lines changed

Diff for: .github/workflows/scriptcheck.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
python -m pip install pygments
9090
python -m pip install requests
9191
python -m pip install psutil
92+
python -m pip install setuptools
9293
9394
- name: run Shellcheck
9495
if: matrix.python-latest
@@ -98,10 +99,8 @@ jobs:
9899
- name: run pylint
99100
if: matrix.python-latest
100101
run: |
101-
echo "FIXME pylint is disabled for now because it fails to import files:"
102-
echo "FIXME addons/runaddon.py:1:0: E0401: Unable to import 'cppcheckdata' (import-error)"
103-
echo "FIXME addons/runaddon.py:1:0: E0401: Unable to import 'cppcheck' (import-error)"
104-
# pylint --rcfile=pylintrc_travis --jobs $(nproc) addons/*.py htmlreport/cppcheck-htmlreport htmlreport/*.py tools/*.py
102+
shopt -s globstar
103+
pylint --jobs $(nproc) addons/**/*.py htmlreport/cppcheck-htmlreport htmlreport/**/*.py test/**/*.py tools/**/*.py
105104
106105
- name: check .json files
107106
if: matrix.python-latest
@@ -115,10 +114,12 @@ jobs:
115114
116115
- name: check python syntax
117116
run: |
118-
python -m py_compile addons/*.py
117+
shopt -s globstar
118+
python -m py_compile addons/**/*.py
119119
python -m py_compile htmlreport/cppcheck-htmlreport
120-
python -m py_compile htmlreport/*.py
121-
python -m py_compile tools/*.py
120+
python -m py_compile htmlreport/**/*.py
121+
python -m py_compile test/**/*.py
122+
python -m py_compile tools/**/*.py
122123
123124
- name: compile addons
124125
run: |

Diff for: pylintrc_travis renamed to .pylintrc

File renamed without changes.

Diff for: addons/cppcheckdata.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def __init__(self, element, nestedIn):
677677
self.argumentId = {}
678678

679679
def __repr__(self):
680-
attrs = ["Id", "tokenId", "tokenDefId", "name", "type", "hasVirtualSpecifier",
680+
attrs = ["Id", "tokenId", "tokenDefId", "name", "type", "hasVirtualSpecifier",
681681
"isImplicitlyVirtual", "access", "isInlineKeyword", "isStatic",
682682
"isAttributeNoreturn", "overriddenFunction", "nestedIn", "argumentId"]
683683
return "{}({})".format(
@@ -901,7 +901,7 @@ def setId(self, IdMap):
901901
self.symbolic = IdMap.get(self._symbolicId)
902902

903903
def __repr__(self):
904-
attrs = ["intvalue", "tokvalue", "floatvalue", "movedvalue", "uninit",
904+
attrs = ["intvalue", "tokvalue", "floatvalue", "movedvalue", "uninit",
905905
"bufferSize", "containerSize", "condition", "valueKind"]
906906
return "{}({})".format(
907907
"Value",
@@ -999,7 +999,7 @@ def isMatch(self, file, line, message, errorId):
999999
return True
10001000
# Other Suppression (Globaly set via suppression file or cli command)
10011001
if ((self.fileName is None or fnmatch(file, self.fileName))
1002-
and (self.suppressionType is None)
1002+
and (self.suppressionType is None)
10031003
and (self.symbolName is None or fnmatch(message, '*'+self.symbolName+'*'))
10041004
and fnmatch(errorId, self.errorId)):
10051005
return True

Diff for: addons/misra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ def misra_8_4(self, cfg):
21052105
else:
21062106
self.insert_in_dict(extern_var_without_def, tok.str, tok)
21072107
else:
2108-
self.insert_in_dict(extern_var_without_def, var.nameToken.str, var.nameToken)
2108+
self.insert_in_dict(extern_var_without_def, var.nameToken.str, var.nameToken)
21092109

21102110
for var in extern_var_with_def:
21112111
if var not in extern_var_without_def:

Diff for: addons/namingng.py

+22-20
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ class Config:
146146
if have_error:
147147
sys.exit(1)
148148

149+
# pylint: disable-next=no-member - TODO: fix this
150+
if config.include_guard:
151+
# pylint: disable-next=no-member - TODO: fix this
152+
config.include_guard_header_re = config.include_guard.get('RE_HEADERFILE',"[^/].*\\.h\\Z")
153+
149154
return config
150155

151156

@@ -200,14 +205,15 @@ def check_include_guards(conf,cfg,unguarded_include_files):
200205
# - test whether include guards are in place
201206
max_linenr = conf.include_guard.get('max_linenr', 5)
202207

203-
def report(directive,msg,errorId,column=0):
204-
reportNamingError(directive,msg,errorId,column=column)
208+
def report(directive,msg,errorId,severity='style',column=0):
209+
reportNamingError(directive,msg,errorId,severity=severity,column=column)
205210

206211
def report_pending_ifndef(directive,column):
207212
report(directive,'include guard #ifndef is not followed by #define','includeGuardIncomplete',column=column)
208213

209214
last_fn = None
210215
pending_ifndef = None
216+
guard_column = None
211217
phase = 0
212218
for directive in cfg.directives:
213219
if last_fn != directive.file:
@@ -219,7 +225,7 @@ def report_pending_ifndef(directive,column):
219225
if phase == -1:
220226
# ignore (the remainder of) this file
221227
continue
222-
if not re.match(include_guard_header_re,directive.file):
228+
if not re.match(conf.include_guard_header_re,directive.file):
223229
phase = -1
224230
continue
225231

@@ -263,20 +269,16 @@ def report_pending_ifndef(directive,column):
263269
if pending_ifndef:
264270
report_pending_ifndef(pending_ifndef,guard_column)
265271

266-
def process(dumpfiles, configfile):
272+
def process(dumpfiles, configfile, cli, debugprint):
267273
conf = loadConfig(configfile)
268274

269-
if conf.include_guard:
270-
global include_guard_header_re
271-
include_guard_header_re = conf.include_guard.get('RE_HEADERFILE',"[^/].*\\.h\\Z")
272-
273275
for afile in dumpfiles:
274276
if not afile[-5:] == '.dump':
275277
continue
276-
if not args.cli:
278+
if not cli:
277279
print('Checking ' + afile + '...')
278280
data = cppcheckdata.CppcheckData(afile)
279-
process_data(conf,data)
281+
process_data(conf,data,cli,debugprint)
280282

281283
def check_file_naming(conf,data):
282284
for source_file in data.files:
@@ -297,7 +299,7 @@ def check_namespace_naming(conf,data):
297299
for exp in conf.namespace:
298300
evalExpr(conf.namespace, exp, mockToken, 'Namespace')
299301

300-
def check_variable_naming(conf,cfg):
302+
def check_variable_naming(conf,cfg,debugprint):
301303
for var in cfg.variables:
302304
if not var.nameToken:
303305
continue
@@ -309,7 +311,7 @@ def check_variable_naming(conf,cfg):
309311
prev = prev.previous
310312
varType = prev.str + varType
311313

312-
if args.debugprint:
314+
if debugprint:
313315
print("Variable Name: " + str(var.nameToken.str))
314316
print("original Type Name: " + str(var.nameToken.valueType.originalTypeName))
315317
print("Type Name: " + var.nameToken.valueType.type)
@@ -342,7 +344,7 @@ def check_gpp_naming(conf_list,cfg,access,message):
342344
for exp in conf_list:
343345
evalExpr(conf_list, exp, mockToken, message)
344346

345-
def check_function_naming(conf,cfg):
347+
def check_function_naming(conf,cfg,debugprint):
346348
for token in cfg.tokenlist:
347349
if not token.function:
348350
continue
@@ -353,7 +355,7 @@ def check_function_naming(conf,cfg):
353355
while "*" in retval and len(retval.replace("*", "")) == 0:
354356
prev = prev.previous
355357
retval = prev.str + retval
356-
if args.debugprint:
358+
if debugprint:
357359
print("\t:: {} {}".format(retval, token.function.name))
358360

359361
if retval and retval in conf.function_prefixes:
@@ -373,7 +375,7 @@ def check_class_naming(conf,cfg):
373375
for exp in conf.class_name:
374376
evalExpr(conf.class_name, exp, mockToken, msgType)
375377

376-
def process_data(conf,data):
378+
def process_data(conf,data,cli,debugprint):
377379
if conf.file:
378380
check_file_naming(conf,data)
379381

@@ -382,21 +384,21 @@ def process_data(conf,data):
382384

383385
unguarded_include_files = []
384386
if conf.include_guard and conf.include_guard.get('required',1):
385-
unguarded_include_files = [fn for fn in data.files if re.match(include_guard_header_re,fn)]
387+
unguarded_include_files = [fn for fn in data.files if re.match(conf.include_guard_header_re,fn)]
386388

387389
for cfg in data.configurations:
388-
if not args.cli:
390+
if not cli:
389391
print('Checking config %s...' % cfg.name)
390392
if conf.variable:
391-
check_variable_naming(conf,cfg)
393+
check_variable_naming(conf,cfg,debugprint)
392394
if conf.private_member:
393395
check_gpp_naming(conf.private_member,cfg,'Private','Private member variable')
394396
if conf.public_member:
395397
check_gpp_naming(conf.public_member,cfg,'Public','Public member variable')
396398
if conf.global_variable:
397399
check_gpp_naming(conf.global_variable,cfg,'Global','Global variable')
398400
if conf.function_name:
399-
check_function_naming(conf,cfg)
401+
check_function_naming(conf,cfg,debugprint)
400402
if conf.class_name:
401403
check_class_naming(conf,cfg)
402404
if conf.include_guard:
@@ -414,6 +416,6 @@ def process_data(conf,data):
414416
help="Naming check config file")
415417

416418
args = parser.parse_args()
417-
process(args.dumpfile, args.configfile)
419+
process(args.dumpfile, args.configfile, args.cli, args.debugprint)
418420

419421
sys.exit(0)

Diff for: htmlreport/cppcheck-htmlreport

+3-1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def git_blame(errors, path, file, blame_options):
422422
full_path = os.path.join(path, file)
423423
path, filename = os.path.split(full_path)
424424

425+
cwd = os.getcwd()
425426
if path:
426427
os.chdir(path)
427428

@@ -887,11 +888,12 @@ def main() -> None:
887888
except KeyError:
888889
pass
889890

891+
cwe_url = ""
890892
try:
891893
if error['cwe']:
892894
cwe_url = "<a href=\"https://cwe.mitre.org/data/definitions/" + error['cwe'] + ".html\">" + error['cwe'] + "</a>"
893895
except KeyError:
894-
cwe_url = ""
896+
pass
895897

896898
if error['severity'] in ['error', 'warning']:
897899
message_class = error['severity']

Diff for: test/cli/other_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ def test_filelist(tmpdir):
14631463
]
14641464
assert len(expected), len(lines)
14651465
for i in range(1, len(expected)+1):
1466-
lines.remove('{}/11 files checked 0% done'.format(i, len(expected)))
1466+
lines.remove('{}/{} files checked 0% done'.format(i, len(expected)))
14671467
assert lines == expected
14681468

14691469

Diff for: test/cli/performance_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_slow_initlist_varchanged(tmpdir):
185185
}
186186
}""")
187187
cppcheck([filename]) # should not take more than ~1 second
188-
188+
189189

190190
@pytest.mark.timeout(10)
191191
def test_slow_many_scopes(tmpdir):

Diff for: test/cli/premium_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def copy_cppcheck_premium(tmpdir):
3131
"safety": false
3232
}
3333
""".replace('NAME', PRODUCT_NAME))
34-
35-
return exe
34+
35+
return exe
3636

3737

3838
def test_misra_c_builtin_style_checks(tmpdir):

Diff for: test/cli/testutils.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def __lookup_cppcheck_exe():
7878
def __run_subprocess_tty(args, env=None, cwd=None, timeout=None):
7979
import pty
8080
mo, so = pty.openpty()
81-
me, se = pty.openpty()
81+
me, se = pty.openpty()
8282
p = subprocess.Popen(args, stdout=so, stderr=se, env=env, cwd=cwd)
8383
for fd in [so, se]:
8484
os.close(fd)
85-
85+
8686
select_timeout = 0.04 # seconds
8787
readable = [mo, me]
8888
result = {mo: b'', me: b''}
@@ -110,15 +110,15 @@ def __run_subprocess_tty(args, env=None, cwd=None, timeout=None):
110110
if p.poll() is None:
111111
p.kill()
112112
return_code = p.wait()
113-
113+
114114
stdout = result[mo]
115-
stderr = result[me]
115+
stderr = result[me]
116116
return return_code, stdout, stderr
117117

118-
118+
119119
def __run_subprocess(args, env=None, cwd=None, timeout=None):
120120
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, cwd=cwd)
121-
121+
122122
try:
123123
comm = p.communicate(timeout=timeout)
124124
return_code = p.returncode
@@ -143,9 +143,9 @@ def __run_subprocess(args, env=None, cwd=None, timeout=None):
143143
#os.killpg(os.getpgid(p.pid), signal.SIGTERM) # Send the signal to all the process groups
144144
p.terminate()
145145
comm = p.communicate()
146-
146+
147147
stdout = comm[0]
148-
stderr = comm[1]
148+
stderr = comm[1]
149149
return return_code, stdout, stderr
150150

151151

@@ -190,13 +190,13 @@ def cppcheck(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe
190190
args.append(arg_executor)
191191

192192
logging.info(exe + ' ' + ' '.join(args))
193-
193+
194194
run_subprocess = __run_subprocess_tty if tty else __run_subprocess
195195
return_code, stdout, stderr = run_subprocess([exe] + args, env=env, cwd=cwd, timeout=timeout)
196-
196+
197197
stdout = stdout.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
198198
stderr = stderr.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
199-
199+
200200
if remove_checkers_report:
201201
if stderr.find('[checkersReport]\n') > 0:
202202
start_id = stderr.find('[checkersReport]\n')

Diff for: tools/donate-cpu-server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
2727
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
2828
# changes)
29-
SERVER_VERSION = "1.3.53"
29+
SERVER_VERSION = "1.3.54"
3030

3131
OLD_VERSION = '2.14.0'
3232

@@ -1204,7 +1204,7 @@ def run(self):
12041204
text = check_library_function_name(self.resultPath, var_name, queryParams, nonfunc_id='unknownMacro')
12051205
httpGetResponse(self.connection, text, 'text/plain')
12061206
else:
1207-
filename = resultPath + url
1207+
filename = self.resultPath + url
12081208
if not os.path.isfile(filename):
12091209
print_ts('HTTP/1.1 404 Not Found')
12101210
self.connection.send(b'HTTP/1.1 404 Not Found\r\n\r\n')

Diff for: tools/matchcompiler.py

+2
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ def convertFile(self, srcname, destname, line_directive):
691691
for line in srclines:
692692
if not modified:
693693
line_orig = line
694+
else:
695+
line_orig = None
694696

695697
linenr += 1
696698
# Compile Token::Match and Token::simpleMatch

0 commit comments

Comments
 (0)