forked from ctriley/pre-commit-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcppcheck.py
executable file
·42 lines (32 loc) · 1.19 KB
/
cppcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
"""Wrapper script for cppcheck."""
import sys
from typing import List
from hooks.utils import StaticAnalyzerCmd
class CppcheckCmd(StaticAnalyzerCmd):
"""Class for the cppcheck command."""
command = "cppcheck"
lookbehind = "Cppcheck "
def __init__(self, args: List[str]):
super().__init__(self.command, self.lookbehind, args)
self.parse_args(args)
# quiet for stdout purposes
self.add_if_missing(["-q"])
# make cppcheck behave as expected for pre-commit
self.add_if_missing(["--error-exitcode=1"])
# Enable all of the checks
self.add_if_missing(["--enable=all"])
# Per https://github.com/pocc/pre-commit-hooks/pull/30, suppress missingIncludeSystem messages
self.add_if_missing(
["--suppress=unmatchedSuppression", "--suppress=missingIncludeSystem", "--suppress=unusedFunction"]
)
def run(self):
"""Run cppcheck"""
for filename in self.files:
self.run_command([filename] + self.args)
self.exit_on_error()
def main(argv: List[str] = sys.argv):
cmd = CppcheckCmd(argv)
cmd.run()
if __name__ == "__main__":
main()