Commit 0685ba08 authored by Antti Tanhuanpää's avatar Antti Tanhuanpää

Initial dump

parents
#!/usr/bin/env python3
import shlex
import subprocess
import sys
linters = {
'js': ('/usr/bin/eslint', '--stdin'),
'py': ('/usr/bin/flake8', '--ignore=E121,E123,E126,E266,E501,E704,E731', '-'),
'scss': ('/usr/bin/scss-lint', '-'),
}
def lint(filename, fail_on_keyerror=False):
try:
_, extension = filename.rsplit('.', 1)
except ValueError:
return True
try:
linter_args = linters[extension]
except KeyError:
print('Not linter found for', filename, file=sys.stderr)
return not fail_on_keyerror
print(filename)
git_args = ('/usr/bin/git', 'show', shlex.quote(':%s' % filename))
with subprocess.Popen(git_args, stdout=subprocess.PIPE) as pipe:
ret = subprocess.call(linter_args, stdin=pipe.stdout)
return ret == 0
def main(*args):
ret = True
while True:
line = sys.stdin.readline()
if not line:
break
filename = line.strip()
ret &= lint(filename)
return 1 ^ ret
if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment