Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit cpplint only after checking all files #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions hooks/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ def __init__(self, args: List[str]):

def run(self):
"""Run cpplint"""
error_occurred = False
for filename in self.files:
self.run_command(self.args + [filename]) # cpplint is unique in requiring args before filename
self.exit_on_error()
self.run_command_cpplint(self.args + [filename]) # cpplint is unique in requiring args before filename
if self.returncode != 0:
error_occurred = True

if error_occurred:
sys.exit(1)


def main(argv: List[str] = sys.argv):
Expand Down
9 changes: 9 additions & 0 deletions hooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def run_command(self, args: List[str]):
self.stderr += sp_child.stderr
self.returncode = sp_child.returncode

def run_command_cpplint(self, args: List[str]):
"""Run the command and check for errors. Args includes options and filepaths"""
args = [self.command, *args]
sp_child = sp.run(args, stdout=sp.PIPE, stderr=sp.PIPE)
self.returncode = sp_child.returncode

if self.returncode != 0:
sys.stderr.buffer.write(sp_child.stderr + sp_child.stdout)

def exit_on_error(self):
if self.returncode != 0:
sys.stderr.buffer.write(self.stdout + self.stderr)
Expand Down