Better linting and travis CI again

This commit is contained in:
PeridexisErrant 2015-09-30 22:29:52 +10:00
parent 9db16450c1
commit cecba96841
7 changed files with 26 additions and 22 deletions

View file

@ -3,7 +3,8 @@ python:
- "2.7" - "2.7"
- "3.4" - "3.4"
- "3.5" - "3.5"
install: pip install sphinx
script: script:
- pip install sphinx
- python misc/lint.py - python misc/lint.py
- make html - make html
sudo: false

View file

@ -4,12 +4,19 @@
Any other automatic checks should be in this file too. Any other automatic checks should be in this file too.
""" """
from io import open
import os import os
from os.path import * from os.path import *
import sys import sys
text_extensions = ('rst', 'md', 'txt', 'html', 'css', 'js') text_extensions = ('rst', 'md', 'txt', 'html', 'css', 'js')
def error(fname, lineno, issue):
"""Print the problem and location."""
print('ERROR: {}:{} - {}'.format(fname, lineno+1, issue))
def lint(path): def lint(path):
"""Run linters on all files, print problem files.""" """Run linters on all files, print problem files."""
print('Checking for tabs or trailing whitespace...') print('Checking for tabs or trailing whitespace...')
@ -21,19 +28,15 @@ def lint(path):
fname.endswith(ext) for ext in text_extensions): fname.endswith(ext) for ext in text_extensions):
continue continue
with open(fname, encoding='utf-8') as fh: with open(fname, encoding='utf-8') as fh:
if '\t' in fh.read():
failed = True
print('ERROR: tabs found in {}'.format(fname))
if any(line.replace('\n', '') != line.rstrip()
for line in fh.readlines()):
failed = True
print('ERROR: trailing whitespace in {}'.format(fname))
fh.seek(0)
for i, line in enumerate(fh.readlines()): for i, line in enumerate(fh.readlines()):
if len(line) > 81: if len(line) > 81:
failed = True failed = True
print('ERROR: {}:{} - line too long'.format( error(fname, i, 'too long')
fname, i + 1)) if line.replace('\n', '') != line.rstrip():
failed = True
error(fname, i, 'trailing space')
if '\t' in line:
error(fname, i, 'contains tab')
if failed: if failed:
print('Use your text editor to convert tabs to spaces, wrap lines ' print('Use your text editor to convert tabs to spaces, wrap lines '
'or trim trailing whitespace with minimal effort.') 'or trim trailing whitespace with minimal effort.')