Add tools/check-css and tools/lib/css_parser.py.

`tools/lint-all` now calls the new `tools/check-css`

The css_parser library parsers CSS into a data structure
that remembers line numbers and columns of semantically
meaningful tokens and adjoining white space/tokens.  It
is intended to be used for various linting tasks.

The file `tools/check-css` runs a few files through the
parser and makes sure they round trip.  This has some value
right away, as files that fail to parse will cause an
exception to be thrown and thus alert developers to syntax
errors.  We expect to grow this into more advanced linting
tasks eventually.
This commit is contained in:
Steve Howell
2016-07-31 10:37:20 -07:00
committed by Tim Abbott
parent b82836a901
commit 3b5c187f55
3 changed files with 552 additions and 0 deletions

40
tools/check-css Executable file
View File

@@ -0,0 +1,40 @@
#!/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:
print('CssParserException raised while parsing file %s' % (fn,))
print(e)
sys.exit(1)
if __name__ == '__main__':
check_our_files()