Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format flag issue #59

Merged
merged 3 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "pypy"
#- "pypy3" temporarily disable until updated to Python 3.3
addons:
Expand Down
17 changes: 17 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ This is an example for Ruby project:
jdk_switcher use oraclejdk8
pip install html5validator

Integration with GitLab CI
--------------------------------

There is a docker image available to be used with GitLab CI or stand alone.
`Docker image <https://hub.docker.com/r/cyb3rjak3/html5validator>`_,
`Docker image repo <https://github.com/Cyb3r-Jak3/html5validator-docker>`_.

Example for html test `(Full) <https://gitlab.com/Cyb3r-Jak3/Portfolio-Website/blob/master/.gitlab-ci.yml>`_:

.. code-block:: yaml

html_test:
stage: html_test
image: cyb3rjak3/html5validator:latest
script:
- html5validator --root public/ --also-check-css --format text


Technical Notes
---------------
Expand Down
33 changes: 33 additions & 0 deletions html5validator/tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,43 @@ def test_stack_size():
'-lll']) == 0


def test_valid_format_flags():
assert subprocess.call(['html5validator',
'--root={}/valid/'.format(HTML_TEST_FILES),
'--format', 'text']) == 0
assert subprocess.call(['html5validator',
'--root={}/valid/'.format(HTML_TEST_FILES),
'--format', 'gnu']) == 0
assert subprocess.call(['html5validator',
'--root={}/valid/'.format(HTML_TEST_FILES),
'--format', 'json']) == 0
assert subprocess.call(['html5validator',
'--root={}/valid/'.format(HTML_TEST_FILES),
'--format', 'xml']) == 0


def test_invalid_format_flags():
assert subprocess.call(['html5validator',
'--root={}/invalid/'.format(HTML_TEST_FILES),
'--format', 'text']) == 3
assert subprocess.call(['html5validator',
'--root={}/invalid/'.format(HTML_TEST_FILES),
'--format', 'gnu']) == 1
assert subprocess.call(['html5validator',
'--root={}/invalid/'.format(HTML_TEST_FILES),
'--format', 'json']) == 1
assert subprocess.call(['html5validator',
'--root={}/invalid/'.format(HTML_TEST_FILES),
'--format', 'xml']) == 8


if __name__ == '__main__':
test_valid()
test_invalid()
test_return_value()
test_angularjs()
test_multiple_ignoreres()
test_ignore_and_ignorere()
test_stack_size()
test_valid_format_flags()
test_invalid_format_flags()
Cyb3r-Jak3 marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 28 additions & 3 deletions html5validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@

LOGGER = logging.getLogger(__name__)

DEFAULT_IGNORE_RE = ['Picked up _JAVA_OPTIONS:.*']
DEFAULT_IGNORE_RE = [
r'\APicked up _JAVA_OPTIONS:.*',
r'\ADocument checking completed. No errors found.*',
]

DEFAULT_IGNORE = [
'{"messages":[]}'
]

DEFAULT_IGNORE_XML = [
'</messages>',
'<?xml version=\'1.0\' encoding=\'utf-8\'?>',
'<messages xmlns="http://n.validator.nu/messages/">'
]
Cyb3r-Jak3 marked this conversation as resolved.
Show resolved Hide resolved


class JavaNotFoundException(Exception):
Expand Down Expand Up @@ -43,6 +56,9 @@ def __init__(self,
# add default ignore_re
self.ignore_re += DEFAULT_IGNORE_RE

# add default ignore
self.ignore += DEFAULT_IGNORE

# process fancy quotes in ignore
self.ignore = [self._normalize_string(s) for s in self.ignore]
self.ignore_re = [self._normalize_string(s) for s in self.ignore_re]
Expand Down Expand Up @@ -144,14 +160,23 @@ def validate(self, files):

e = stderr.splitlines()

# Removes any empty items in the list
e = list(filter(None, e))

# Prevents removal of xml tags if there are errors
if self.format == "xml" and len(e) < 4:
self.ignore = DEFAULT_IGNORE_XML

LOGGER.debug(e)

for i in self.ignore:
e = [l for l in e if i not in l]
for i in self.ignore_re:
regex = re.compile(i)
e = [l for l in e if not regex.search(l)]

if stderr:
LOGGER.error(stderr)
if e:
LOGGER.error(e)
else:
LOGGER.info('All good.')
return len(e)