Skip to content

Instantly share code, notes, and snippets.

@dhermes
Created September 27, 2016 18:10
Show Gist options
  • Save dhermes/cacef3a150d0d2f25dcccb9443fb33e6 to your computer and use it in GitHub Desktop.
Save dhermes/cacef3a150d0d2f25dcccb9443fb33e6 to your computer and use it in GitHub Desktop.
import os
import subprocess
IGNORED = (
'docs/_static/images/favicon.ico',
'docs/_static/images/gcp-logo-32x32.png',
'docs/_static/images/gcp-logo.png',
'system_tests/data/CloudPlatform_128px_Retina.png',
'system_tests/data/five-point-one-mb-file.zip',
'system_tests/key.json.enc',
)
MAKEFILES = (
'Makefile.bigtable_v2',
'Makefile.datastore',
'docs/Makefile',
)
def main():
git_root = subprocess.check_output(
['git', 'rev-parse', '--show-toplevel'])
git_root = git_root.strip()
os.chdir(git_root)
all_files = subprocess.check_output(
['git', 'ls-files'])
all_files = all_files.strip().split('\n')
for filename in all_files:
if filename in IGNORED:
continue
with open(filename, 'rb') as file_obj:
lines = file_obj.readlines()
if len(lines) == 0:
raise ValueError(filename, 'empty file')
last_line = lines[-1]
if not last_line.endswith('\n'):
raise ValueError(filename, 'no end newline')
if last_line == '\n':
raise ValueError(filename, 'trailing newline')
for line in lines:
if '\r' in line:
raise ValueError(filename, line,
'windows linefeed')
if '\t' in line:
if filename not in MAKEFILES:
raise ValueError(filename, line,
'tab character')
if line.rstrip() + '\n' != line:
raise ValueError(filename, line,
'trailing whitespace')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment