Skip to content

Commit

Permalink
exit cpplint only after completing all files
Browse files Browse the repository at this point in the history
  • Loading branch information
r-shah22 authored Apr 18, 2023
1 parent 336fdd7 commit c4fc2ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit c4fc2ea

Please sign in to comment.