zulip/tools/check-css
Steve Howell 2a07b204bf css parser: Show line numbers for errors.
This is a fairly major overhaul of the CSS parser to support
line numbers in error messages.

Basically, instead of passing "slices" of tokens around, we pass
indexes into the token arrays to all of our sub-parsers, which
allows them to have access to previous tokens in certain cases.
This is particularly important for errors where stuff is missing
(vs. being wrong).

In testing this out I found a few more places to catch errors.
2017-02-01 10:02:03 -08:00

45 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
from lib.css_parser import parse, CssParserException
import os
import sys
import glob
try:
import lister
from typing import cast, Callable, Dict, Iterable, List
except ImportError as e:
print("ImportError: {}".format(e))
print("You need to run the Zulip linters inside a Zulip dev environment.")
print("If you are using Vagrant, you can `vagrant ssh` to enter the Vagrant guest.")
sys.exit(1)
def validate(fn):
# type: (str) -> None
text = open(fn).read()
section_list = parse(text)
if text != section_list.text():
print('BOO! %s broken' % (fn,))
open('foo.txt', 'w').write(section_list.text())
os.system('diff %s foo.txt' % (fn,))
sys.exit(1)
def check_our_files():
# type: () -> None
fns = glob.glob('static/styles/*.css')
for fn in fns:
try:
validate(fn)
except CssParserException as e:
msg = '''
ERROR! Some CSS seems to be misformatted.
{}
See line {} in file {}
'''.format(e.msg, e.token.line, fn)
print(msg)
sys.exit(1)
if __name__ == '__main__':
check_our_files()