Skip to content

Commit

Permalink
Adapting to html5validator API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Jan 21, 2018
1 parent 8d49487 commit ce6dfbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
22 changes: 6 additions & 16 deletions pre_commit_hooks/validate_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main(argv=None):
parser.add_argument('filenames', nargs='*', help='filenames to check')
parser.add_argument('--show-warnings', dest='errors_only',
action='store_false', default=True)
parser.add_argument('--no-langdetect', action='store_true', default=False,
parser.add_argument('--no-langdetect', dest='detect_language', action='store_false', default=True,
help='disable language detection')
parser.add_argument('--format', choices=['gnu', 'xml', 'json', 'text'],
help='output format', default=None)
Expand Down Expand Up @@ -45,26 +45,16 @@ def main(argv=None):

logging.basicConfig(level=getattr(logging, args.log))

java_options = ''
vnu_options = []
if args.errors_only:
vnu_options.append('--errors_only')
if args.no_langdetect:
vnu_options.append('--no-langdetect')
if args.format:
vnu_options.append('--format')
vnu_options.append(args.format)
java_options = []
if args.stack_size:
java_options.append('-Xss{}k'.format(args.stack_size))

placeholder = Placeholder(args.mustache_remover_default_value, args.mustache_remover_env)
validator = CustomHTMLValidator(mustache_remover_name=args.mustache_remover,
mustache_remover_copy_ext=args.mustache_remover_copy_ext,
mustache_remover_placeholder=placeholder,
templates_include_dir=args.templates_include_dir,
java_options=java_options, vnu_options=vnu_options,
directory=None, match=None, ignore=args.ignore, ignore_re=args.ignore_re)
errors_only=args.errors_only,
detect_language=args.detect_language,
format=args.format,
stack_size=args.stack_size,
ignore=args.ignore, ignore_re=args.ignore_re)
return validator.validate(
args.filenames,
remove_mustaches=args.remove_mustaches,
Expand Down
4 changes: 2 additions & 2 deletions tests/validate_html_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_validate_jinja2_errors(caplog):
'--templates-include-dir=tests',
'tests/jinja-template.html']) == 2
errors = caplog.text.splitlines()
assert 'Expected "<!DOCTYPE html>"' in errors[0]
assert 'Element "head" is missing a required instance of child element "title"' in errors[1]
assert any('Expected "<!DOCTYPE html>"' in line for line in errors)
assert any('Element "head" is missing a required instance of child element "title"' in line for line in errors)


def test_validate_handlebar_ko(tmpdir, caplog):
Expand Down

0 comments on commit ce6dfbb

Please sign in to comment.