diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..01fb8bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/pre_commit_hooks.egg-info \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 287452f..78f36db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ # A list of common hooks I use - repo: git://github.com/Lucas-C/pre-commit-hooks - sha: b600798f8dacfcc29862e3d58367b89d3090c6a7 + sha: 0f5055d31f39ea3ac1f5335a0cca320200cd0c51 hooks: - id: forbid-crlf - id: remove-crlf @@ -16,7 +16,7 @@ - --html-files-dir - . - repo: git://github.com/pre-commit/pre-commit-hooks - sha: e306ff3b7d0d9a6fc7d128ef9ca2e0b6e6e76e8f + sha: 3fa02652357ff0dbb42b5bc78c673b7bc105fcf3 hooks: - id: trailing-whitespace files: '' @@ -25,7 +25,7 @@ - id: check-json - id: check-yaml - repo: git://github.com/pre-commit/mirrors-pylint - sha: 4972270a188e28f100cd0db472e05f59d9621e54 + sha: 4de6c8dfadef1a271a814561ce05b8bc1c446d22 hooks: - id: pylint args: diff --git a/.pylintrc b/.pylintrc index c05d646..927dce8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,5 +1,5 @@ [MESSAGES CONTROL] -disable = bad-continuation, duplicate-code, import-error, missing-docstring +disable = bad-continuation, duplicate-code, import-error, missing-docstring, multiple-imports [FORMAT] max-line-length = 110 diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000..e42b23c --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1 @@ +pre-commit \ No newline at end of file diff --git a/hooks.yaml b/hooks.yaml index 3afe1db..18aefc6 100644 --- a/hooks.yaml +++ b/hooks.yaml @@ -25,12 +25,17 @@ args: [ --whitespaces-count, '4' ] files: '' exclude: (Makefile|debian/rules)(\.in)?$ +- id: validate-html + name: HTML validator using v.Nu through svenkreiss/html5validator + entry: validate_html + language: python + files: .*\.(html|hbs)$ - id: forbid-html-img-without-alt-text name: HTML img tag alt text checker description: "List every tag without a alt= or data-ng-attr-alt= attribute" entry: forbid_html_img_without_alt_text language: python - files: .*\.html$ + files: .*\.(html|hbs)$ - id: forbid-non-std-html-attributes name: Non-standard HTML attributes checker description: "Detect any non-standard attribute that is not prefixed with data-" @@ -39,7 +44,7 @@ args: - --extra-known-attributes - content,http-equiv,placeholder,role,style - files: .*\.html$ + files: .*\.(html|hbs)$ - id: detect-missing-css-classes name: Missing CSS classes checker name: Detect unused or missing CSS classes definitions, and abort if any of the later ones is found diff --git a/pre_commit_hooks/utils.py b/pre_commit_hooks/utils.py index 4514e8f..302e418 100644 --- a/pre_commit_hooks/utils.py +++ b/pre_commit_hooks/utils.py @@ -1,5 +1,3 @@ -import string - # Taken from: http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/ KNOWN_BINARY_FILE_EXT = ['.pdf'] diff --git a/pre_commit_hooks/validate_html.py b/pre_commit_hooks/validate_html.py new file mode 100755 index 0000000..2d7839f --- /dev/null +++ b/pre_commit_hooks/validate_html.py @@ -0,0 +1,44 @@ +from __future__ import print_function +import argparse, sys +from html5validator.validator import Validator + +def main(argv=None): + parser = argparse.ArgumentParser() + parser.add_argument('filenames', nargs='*', help='filenames to check') + parser.add_argument('--error_only', dest='error_only', + action='store_false', default=True) + parser.add_argument('--ignore', nargs='*', default=None, + type=lambda s: (s.decode('utf-8') + if isinstance(s, bytes) else s), + help='ignore messages containing the given strings') + parser.add_argument('--ignore-re', nargs='*', default=None, + type=lambda s: (s.decode('utf-8') + if isinstance(s, bytes) else s), + dest='ignore_re', + help='regular expression of messages to ignore') + parser.add_argument('-l', action='store_const', const=2048, + dest='stack_size', + help=('run on larger files: sets Java ' + 'stack size to 2048k') + ) + parser.add_argument('-ll', action='store_const', const=8192, + dest='stack_size', + help=('run on larger files: sets Java ' + 'stack size to 8192k') + ) + parser.add_argument('-lll', action='store_const', const=32768, + dest='stack_size', + help=('run on larger files: sets Java ' + 'stack size to 32768k') + ) + args = parser.parse_args(argv) + + validator = Validator(directory=None, match=None, ignore=args.ignore, ignore_re=args.ignore_re) + sys.exit(validator.validate( + args.filenames, + errors_only=args.error_only, + stack_size=args.stack_size, + )) + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/setup.py b/setup.py index 3b679a4..d41b9f6 100644 --- a/setup.py +++ b/setup.py @@ -25,13 +25,15 @@ packages=find_packages('.'), install_requires=[ + 'html5validator', 'lxml', - 'tinycss2' + 'tinycss2', ], entry_points={ 'console_scripts': [ 'detect_missing_css_classes = pre_commit_hooks.detect_missing_css_classes:main', 'forbid_crlf = pre_commit_hooks.forbid_crlf:main', + 'validate_html = pre_commit_hooks.validate_html:main', 'forbid_html_img_without_alt_text = pre_commit_hooks.forbid_html_img_without_alt_text:main', 'forbid_non_std_html_attributes = pre_commit_hooks.forbid_non_std_html_attributes:main', 'forbid_tabs = pre_commit_hooks.forbid_tabs:main',