lint: Fix incorrect line length calculations in Python 2.

Previously, we would incorrectly be counting bytes in Python 2, which
meant lines with unicode characters in them appeared to the linter to
be far longer than they actually were.
This commit is contained in:
Tim Abbott 2017-01-08 22:45:48 -08:00
parent 190d320afa
commit b54f8b3b14
1 changed files with 5 additions and 1 deletions

View File

@ -157,7 +157,11 @@ def build_custom_checkers(by_lang):
except Exception:
print("Exception with %s at %s line %s" % (rule['pattern'], fn, i+1))
traceback.print_exc()
if (max_length is not None and len(line) > max_length and
if isinstance(line, bytes):
line_length = len(line.decode("utf-8"))
else:
line_length = len(line)
if (max_length is not None and line_length > max_length and
'# type' not in line and 'test' not in fn and 'example' not in fn and
not re.match("\[[a-z0-9_-]*\]: http.*", line) and
"#ignorelongline" not in line and 'migrations' not in fn):