Skip to content

expose vnu options #39

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

Merged
merged 1 commit into from
Jan 11, 2018
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pypy*
dist

.DS_Store
.vscode
54 changes: 37 additions & 17 deletions html5validator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ def main():
help='match file pattern (default: *.html)')
parser.add_argument('--blacklist', type=str, nargs='*',
help='directory names to skip', default=[])
parser.add_argument('--show-warnings', dest='error_only',
action='store_false', default=True)

parser.add_argument('--show-warnings', dest='errors_only',
action='store_false', default=True,
help='show warnings')
parser.add_argument('--no-langdetect',
action='store_true', default=False,
help='disable language detection')
parser.add_argument('--format', choices=['gnu', 'xml', 'json', 'text'],
help='output format', default=None)

parser.add_argument('--ignore', nargs='*', default=None,
type=lambda s: (s.decode('utf-8')
if isinstance(s, bytes) else s),
Expand All @@ -35,42 +43,54 @@ def main():
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')
)
'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')
)
'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')
)
'stack size to 32768k'))

parser.add_argument('--log', default='WARNING',
help=('log level: DEBUG, INFO or WARNING '
'(default: WARNING)'))
parser.add_argument('--version', action='version',
version='%(prog)s ' + VERSION)
args = parser.parse_args()

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))

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

v = Validator(directory=args.root, match=args.match,
blacklist=args.blacklist,
ignore=args.ignore, ignore_re=args.ignore_re)
files = v.all_files()
validator = Validator(directory=args.root,
match=args.match,
blacklist=args.blacklist,
ignore=args.ignore,
ignore_re=args.ignore_re,
java_options=java_options,
vnu_options=vnu_options)
files = validator.all_files()
LOGGER.info('Files to validate: \n {0}'.format('\n '.join(files)))
LOGGER.info('Number of files: {0}'.format(len(files)))

error_count = v.validate(
files,
errors_only=args.error_only,
stack_size=args.stack_size,
)
error_count = validator.validate(files)
sys.exit(min(error_count, 255))


Expand Down
17 changes: 8 additions & 9 deletions html5validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ def __str__(self):
class Validator(object):

def __init__(self, directory='.', match='*.html', blacklist=None,
ignore=None, ignore_re=None):
ignore=None, ignore_re=None,
java_options=None, vnu_options=None):
self.directory = directory
self.match = match
self.blacklist = blacklist if blacklist else []
self.ignore = ignore if ignore else []
self.ignore_re = ignore_re if ignore_re else []
self.java_options = java_options if java_options is not None else []
self.vnu_options = vnu_options if vnu_options is not None else []

# add default ignore_re
self.ignore_re += DEFAULT_IGNORE_RE
Expand Down Expand Up @@ -77,12 +80,7 @@ def all_files(self, skip_invisible=True):
files.append(os.path.join(root, filename))
return files

def validate(self, files=None, errors_only=True, stack_size=None):
vnu_opts, java_opts = [], []
if errors_only:
vnu_opts.append('--errors-only')
if stack_size:
java_opts.append('-Xss{}k'.format(stack_size))
def validate(self, files=None):
if not files:
files = self.all_files()

Expand All @@ -95,9 +93,10 @@ def validate(self, files=None, errors_only=True, stack_size=None):
raise JavaNotFoundException()

try:
cmd = (['java'] + self.java_options +
['-jar', self.vnu_jar_location] + self.vnu_options + files)
o = subprocess.check_output(
['java'] + java_opts +
['-jar', self.vnu_jar_location] + vnu_opts + files,
cmd,
stderr=subprocess.STDOUT,
).decode('utf-8')
except subprocess.CalledProcessError as e:
Expand Down
35 changes: 25 additions & 10 deletions vnujar/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ With a few exceptions, this is a record of mainly just user-facing
changes—that is, either changes to the actual behavior of the checker, or
changes to any options/interfaces the checker exposes for developers.

# 17.11.1
07 October 2017
- Fix bug that made the vnu.jar `--Werror` option not work as expected
- Make vnu.jar exit 0 if all errors have been filtered out

# 17.11.0
06 October 2017
- Allow DPUB roles on more elements (per ARIA in HTML spec updates)
- Add `--Werror` option to the vnu.jar command-line checker. The option
causes the checker to exit non-zero if any warnings are encountered
(even if there are no errors).
- Fix mismatch that caused message-filtering failures
- Fix memory leak in language detector (patch from @tgyurci)
- Stop reporting HTML4-specific parse errors for HTML4-doctype docs

# 17.9.0
20 August 2017
- Allow script[nomodule]
- Allow the hover, any-hover, pointer, and any-pointer media features
- Allow @scope, @updateviacache, @workertype for link[rel=serviceworker]
- Allow `script[nomodule]`
- Allow `hover`, `any-hover`, `pointer`, and `any-pointer` media features
- Allow `@scope`, `@updateviacache`, `@workertype` for `link[rel=serviceworker]`
- Allow `&;` (don’t report it as “`&` did not start a character reference”)
- Add `acceptlanguage` query parameter, to specify an Accept-Language
request-header value for checker to send when fetching remote documents
Expand All @@ -21,21 +36,21 @@ changes to any options/interfaces the checker exposes for developers.
context**” wording in error message with “Attribute "foo" not allowed on
element "param" **at this point**” (for consistent working for that error
between the command-line checker and the web-based checker).
- Disallow the "contextmenu" attribute and type=contextmenu and type=toolbar
- Disallow the `contextmenu` attribute and `type=contextmenu` and `type=toolbar`
for the `menu` element.
- Allow link[rel=serviceworker]
- Allow `link[rel=serviceworker]`
- Allow floating-point numbers in attribute values to start with decimal point
- Allow a[href] in SVG wherever a[xlink:href] is allowed
- Allow the "focusable" and "tabindex" attributes on SVG elements
- Fix bug that disallowed `progress` & `meter` as label[for] targets
- Allow `a[href]` in SVG wherever `a[xlink:href]` is allowed
- Allow the `focusable` and `tabindex` attributes on SVG elements
- Fix bug that disallowed `progress` & `meter` as `label[for]` targets
- Default to text/html for checking file uploads
- Emit warnings for use of rel={copyright,previous}
- Emit warnings for use of `rel={copyright,previous}`
- Prevent Bulgarian ➡ Russian misidentifications in language detector
- Skip figcaption elements when running the language detector

# 17.3.0
26 March 2017
- Allow color attribute with link[rel="mask-icon"]
- Allow `color` attribute with `link[rel="mask-icon"]`
- Allow `meta[name]` to have `itemref`/`itemscope`/`itemtype`/`itemid`
- Allow `allow-top-navigation-by-user-activation` in `iframe[sandbox]`
- Stop hiding “sectioning roots” headings in “Heading-level outline”
Expand Down
13 changes: 9 additions & 4 deletions vnujar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ frontend such as:
Use the `vnu.jar` HTML checker as an executable for command-line checking of
documents by invoking it like this:

java -jar ~/vnu.jar [--errors-only] [--exit-zero-always]
java -jar ~/vnu.jar [--errors-only] [--Werror] [--exit-zero-always]
[--asciiquotes] [--no-stream] [--format gnu|xml|json|text]
[--filterfile FILENAME] [--filterpattern PATTERN] [--html]
[--skip-non-html] [--no-langdetect] [--help] [--verbose] [--version]
Expand Down Expand Up @@ -111,9 +111,7 @@ executable provides the following options:
Specifies whether ASCII quotation marks are substituted for Unicode smart
quotation marks in messages.

default: "no"

possible values: "yes" or "no"
default: [unset; Unicode smart quotation marks are used in messages]

#### --errors-only

Expand All @@ -122,6 +120,13 @@ executable provides the following options:

default: [unset; all message reported, including warnings & info messages]

#### --Werror

Makes the checker exit non-zero if any warnings are encountered (even if
there are no errors).

default: [unset; checker exits zero if only warnings are encountered]

#### --exit-zero-always

Makes the checker exit zero even if errors are reported for any documents.
Expand Down
16 changes: 11 additions & 5 deletions vnujar/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ <h2>Usage</h2>
<p>Use the <code>vnu.jar</code> HTML checker as an executable for
command-line checking of documents by invoking it like this:
<pre>
java -jar ~/vnu.jar [--errors-only] [--exit-zero-always]
java -jar ~/vnu.jar [--errors-only] [--Werror] [--exit-zero-always]
[--asciiquotes] [--no-stream] [--format gnu|xml|json|text]
[--filterfile FILENAME] [--filterpattern PATTERN]
[--html] [--skip-non-html] [--no-langdetect]
Expand Down Expand Up @@ -249,14 +249,12 @@ <h3 id="options">Options</h3>
<p>When used from the command line as described in this section, the
<code>vnu.jar</code> executable provides the following options:

<h4 id="errors-only">--asciiquotes</h4>
<h4 id="asciiquotes">--asciiquotes</h4>
<pre>
Specifies whether ASCII quotation marks are substituted for Unicode
smart quotation marks in messages.

default: "no"

possible values: "yes" or "no"
default: [unset; Unicode smart quotation marks are used in messages]
</pre>

<h4 id="errors-only">--errors-only</h4>
Expand All @@ -267,6 +265,14 @@ <h4 id="errors-only">--errors-only</h4>
default: [unset; all message reported, including warnings & info messages]
</pre>

<h4 id="Werror">--Werror</h4>
<pre>
Makes the checker exit non-zero if any warnings are encountered (even if
there are no errors).

default: [unset; checker exits zero if only warnings are encountered]
</pre>

<h4 id="exit-zero-always">--exit-zero-always</h4>
<pre>
Makes the checker exit zero even if errors are reported for any documents.
Expand Down
Binary file modified vnujar/vnu.jar
Binary file not shown.