mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Add check_rubocop
Uses rubocop to check syntax / style of ruby files.
This commit is contained in:
parent
616c1ebd18
commit
a2d690a0ab
7 changed files with 50 additions and 0 deletions
27
pre_commit_hooks/check_rubocop.py
Normal file
27
pre_commit_hooks/check_rubocop.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def check_rubocop(argv=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='filenames to check.')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retval = 0
|
||||
|
||||
command = ["rubocop"] + args.filenames
|
||||
|
||||
try:
|
||||
retval = subprocess.check_call(command, shell=False)
|
||||
except subprocess.CalledProcessError as err:
|
||||
print('{0}: rubocop failed ({1})'.format(args.filenames, err))
|
||||
retval = 1
|
||||
|
||||
return retval
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(check_rubocop())
|
||||
Loading…
Add table
Add a link
Reference in a new issue