Coder Social home page Coder Social logo

validator / grunt-html Goto Github PK

View Code? Open in Web Editor NEW
171.0 171.0 84.0 71.33 MB

Grunt plugin for HTML validation, using the official Nu Html Checker (v.Nu)

License: MIT License

JavaScript 100.00%
checker css grunt gruntplugin html htmllint javascript lint validator vnu vnu-jar

grunt-html's Introduction

The Nu Html Checker (v.Nu) Chat room Download latest

The Nu Html Checker (v.Nu) helps you catch unintended mistakes in your HTML, CSS, and SVG. It enables you to batch-check documents from the command line and from other scripts/apps, and to deploy your own instance of the checker as a service (like validator.w3.org/nu). Its source code is available, as are instructions on how to build, test, and run the code.

A Dockerfile (see Pulling the Docker image below) and npm, pip, and brew packages are also available.

It is released upstream in these formats:

Note: The vnu.jar and vnu.war files require you to have Java 11 or above installed. The pre-compiled Linux, Windows, and macOS binaries don’t require you to have any version of Java already installed at all.

You can get the latest release or run docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest, npm install vnu-jar, npm install --registry=https://npm.pkg.github.com @validator/vnu-jar, brew install vnu, or pip install html5validator and see the Usage and Web-based checking sections below. Or automate your document checking with a frontend such as:

Usage

Run the checker with one of the following invocations:

vnu-runtime-image/bin/vnu OPTIONS FILES (Linux or macOS)

vnu-runtime-image\bin\vnu.bat OPTIONS FILES (Windows)

java -jar ~/vnu.jar OPTIONS FILES (any system with Java8+ installed)

…where FILES are the documents to check, and OPTIONS are zero or more of the following options:

--errors-only --Werror --exit-zero-always --stdout --asciiquotes
--user-agent USER_AGENT --no-langdetect --no-stream --filterfile FILENAME
--filterpattern PATTERN --css --skip-non-css --also-check-css --svg
--skip-non-svg --also-check-svg --xml --html --skip-non-html
--format gnu|xml|json|text --help --verbose --version

The Options section below provides details on each option, and the rest of this section provides some specific examples.

Note: Throughout these examples, replace ~/vnu.jar with the actual path to that jar file on your system, and replace vnu-runtime-image/bin/vnu and vnu-runtime-image\bin\vnu.bat with the actual path to the vnu or vnu.bat program on your system — or if you add the vnu-runtime-image/bin or vnu-runtime-image\bin directory your system PATH environment variable, you can invoke the checker with just vnu.

To check one or more documents from the command line:

  vnu-runtime-image/bin/vnu      FILE.html FILE2.html FILE3.html...

  vnu-runtime-image\bin\vnu.bat  FILE.html FILE2.html FILE3.html...

  java -jar ~/vnu.jar            FILE.html FILE2.html FILE3.html...

Note: If you get a StackOverflowError error when invoking the checker, try adjusting the thread stack size by providing the -Xss option to java:

  java -Xss512k -jar ~/vnu.jar ...

  vnu-runtime-image/bin/java -Xss512k \
      -m vnu/nu.validator.client.SimpleCommandLineValidator ...

To check all documents in a particular directory DIRECTORY_PATH as HTML:

  java -jar ~/vnu.jar            DIRECTORY_PATH

  vnu-runtime-image/bin/vnu      DIRECTORY_PATH

  vnu-runtime-image\bin\vnu.bat  DIRECTORY_PATH

More examples

Note: The examples in this section assume you have the vnu-runtime-image/bin or vnu-runtime-image\bin directory in your system PATH environment variable. If you’re using the jar file instead, replace vnu in the examples with java -jar ~/vnu.jar.

To check all documents in a particular directory DIRECTORY_PATH as HTML, but skip any documents whose names don’t end with the extensions .html, .htm, .xhtml, or .xht:

  vnu --skip-non-html DIRECTORY_PATH

To check all documents in a particular directory as CSS:

  vnu --css DIRECTORY_PATH

To check all documents in a particular directory as CSS, but skip any documents whose names don’t end with the extension .css:

  vnu --skip-non-css DIRECTORY_PATH

To check all documents in a particular directory, with documents whose names end in the extension .css being checked as CSS, and all other documents being checked as HTML:

  vnu --also-check-css DIRECTORY_PATH

To check all documents in a particular directory as SVG:

  vnu --svg DIRECTORY_PATH

To check all documents in a particular directory as SVG, but skip any documents whose names don’t end with the extension .svg:

  vnu --skip-non-svg DIRECTORY_PATH

To check all documents in a particular directory, with documents whose names end in the extension .svg being checked as SVG, and all other documents being checked as HTML:

  vnu --also-check-svg DIRECTORY_PATH

To check a Web document:

  vnu _URL_

  example: vnu http://example.com/foo

To check standard input:

  vnu -

  example:

  echo '<!doctype html><title>...' | vnu -

  echo '<!doctype html><title>...' | java -jar ~/vnu.jar -

Options

When used from the command line as described in this section, the checker provides the following options:

--asciiquotes

Specifies whether ASCII quotation marks are substituted for Unicode smart
quotation marks in messages.

default: [unset; Unicode smart quotation marks are used in messages]

--errors-only

Specifies that only error-level messages and non-document-error messages are
reported (so that warnings and info messages are not reported).

default: [unset; all messages 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.

default: [unset; checker exits 1 if errors are reported for any documents]

--stdout

Makes the checker report errors and warnings to stdout rather than stderr.

default: [unset; checker reports errors and warnings to stderr]

--filterfile FILENAME

Specifies a filename. Each line of the file contains either a regular
expression or starts with "#" to indicate the line is a comment. Any error
message or warning message that matches a regular expression in the file is
filtered out (dropped/suppressed).

default: [unset; checker does no message filtering]

--filterpattern REGEXP

Specifies a regular expression. Any error message or warning message that
matches the regular expression is filtered out (dropped/suppressed).

As with all other checker options, this option may only be specified once.
So to filter multiple error messages or warning messages, you must provide a
single regular expression that will match all the messages. The typical way
to do that for regular expressions is to OR multiple patterns together using
the "|" character.

default: [unset; checker does no message filtering]

--format format

Specifies the output format for reporting the results.

default: "gnu"

possible values: "gnu", "xml", "json", "text" [see information at URL below]

https://github.com/validator/validator/wiki/Service-%C2%BB-Common-params#out

--help

Shows detailed usage information.

--skip-non-css

Check documents as CSS but skip documents that don’t have *.css extensions.

default: [unset; all documents found are checked]

--css

Force all documents to be checked as CSS, regardless of extension.

default: [unset]

--skip-non-svg

Check documents as SVG but skip documents that don’t have *.svg extensions.

default: [unset; all documents found are checked]

--svg

Force all documents to be checked as SVG, regardless of extension.

default: [unset]

--skip-non-html

Skip documents that don’t have *.html, *.htm, *.xhtml, or *.xht extensions.

default: [unset; all documents found are checked, regardless of extension]

--html

Forces any *.xhtml or *.xht documents to be parsed using the HTML parser.

default: [unset; XML parser is used for *.xhtml and *.xht documents]

--xml

Forces any *.html documents to be parsed using the XML parser.

default: [unset; HTML parser is used for *.html documents]

--also-check-css

Check CSS documents (in addition to checking HTML documents).

default: [unset; no documents are checked as CSS]

--also-check-svg

Check SVG documents (in addition to checking HTML documents).

default: [unset; no documents are checked as SVG]

--user-agent USER_AGENT

Specifies the value of the User-Agent request header to send when checking
HTTPS/HTTP URLs.

default: "Validator.nu/LV"

--no-langdetect

Disables language detection, so that documents are not checked for missing
or mislabeled html[lang] attributes.

default: [unset; language detection & html[lang] checking are performed]

--no-stream

Forces all documents to be be parsed in buffered mode instead of streaming
mode (causes some parse errors to be treated as non-fatal document errors
instead of as fatal document errors).

default: [unset; non-streamable parse errors cause fatal document errors]

--verbose

Specifies "verbose" output. (Currently this just means that the names of
files being checked are written to stdout.)

default: [unset; output is not verbose]

--version

Shows the checker version number.

Web-based checking

The Nu Html Checker — along with being usable as a standalone command-line client — can be run as an HTTP service, similar to validator.w3.org/nu, for browser-based checking of HTML documents, CSS stylesheets, and SVG images over the Web. To that end, the checker is released as several separate packages:

  • Linux, Windows, and macOS binaries for deploying the checker as a simple self-contained service on any system

  • vnu.jar for deploying the checker as a simple self-contained service on a system with Java installed

  • vnu.war for deploying the checker to a servlet container such as Tomcat

All deployments expose a REST API that enables checking of HTML documents, CSS stylesheets, and SVG images from other clients, not just web browsers. And the Linux, Windows, and macOS binaries and vnu.jar package also include a simple HTTP client that enables you to either send documents to a locally-running instance of the checker HTTP service — for fast command-line checking — or to any remote instance of the checker HTTP service running anywhere on the Web.

The latest releases of the Linux, Windows, and macOS binaries and vnu.jar and vnu.war packages are available from the validator project at github. The following are detailed instructions on using them.

Note: Throughout these instructions, replace ~/vnu.jar with the actual path to that jar file on your system, and replace vnu-runtime-image/bin/java and vnu-runtime-image\bin\java.exe with the actual path to the checker java or java.exe program on your system — or if you add the vnu-runtime-image/bin or vnu-runtime-image\bin directory your system PATH environment variable, you can invoke the checker with just java nu.validator.servlet.Main 8888.

Standalone web server

To run the checker as a standalone service (using a built-in Jetty server), open a new terminal window and invoke the checker like this:

java -cp ~/vnu.jar              nu.validator.servlet.Main 8888

vnu-runtime-image/bin/java      nu.validator.servlet.Main 8888

vnu-runtime-image\bin\java.exe  nu.validator.servlet.Main 8888

Then open http://0.0.0.0:8888 in a browser. (To listen on a different port, replace 8888 with the port number.)

Warning: Future checker releases will bind by default to the address 127.0.0.1. Your checker deployment might become unreachable unless you use the nu.validator.servlet.bind-address system property to bind the checker to a different address:

java -cp ~/vnu.jar \
    -Dnu.validator.servlet.bind-address=128.30.52.73 \
    nu.validator.servlet.Main 8888

vnu-runtime-image/bin/java \
    -Dnu.validator.servlet.bind-address=128.30.52.73 \
    nu.validator.servlet.Main 8888

vnu-runtime-image\bin\java.exe  \
    -Dnu.validator.servlet.bind-address=128.30.52.73 \
    nu.validator.servlet.Main 8888

When you open http://0.0.0.0:8888 (or whatever URL corresponds to the nu.validator.servlet.bind-address value you’re using), you’ll see a form similar to validator.w3.org/nu that allows you to enter the URL of an HTML document, CSS stylesheet, or SVG image, and have the results of checking that resource displayed in the browser.

Note: If you get a StackOverflowError error when using the checker, try adjusting the thread stack size by providing the -Xss option to java:

  java -Xss512k -cp ~/vnu.jar nu.validator.servlet.Main 8888

  vnu-runtime-image/bin/java -Xss512k -m vnu/nu.validator.servlet.Main 8888

Deployment to servlet container

To run the checker inside of an existing servlet container such as Apache Tomcat you will need to deploy the vnu.war file to that server following its documentation. For example, on Apache Tomcat you could do this using the Manager application or simply by copying the file to the webapps directory (since that is the default appBase setting). Typically you would see a message similar to the following in the catalina.out log file.

May 7, 2014 4:42:04 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/vnu.war

Assuming your servlet container is configured to receive HTTP requests sent to localhost on port 80 and the context root of this application is vnu (often the default behavior is to use the WAR file's filename as the context root unless one is explicitly specified) you should be able to access the application by connecting to http://localhost/vnu/.

Note: You may want to customize the /WEB-INF/web.xml file inside the WAR file (you can use any ZIP-handling program) to modify the servlet filter configuration. For example, if you wanted to disable the inbound-size-limit filter, you could comment out that filter like this:

<!--
  <filter>
      <filter-name>inbound-size-limit-filter</filter-name>
      <filter-class>nu.validator.servlet.InboundSizeLimitFilter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>inbound-size-limit-filter</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
-->

HTTP client (for fast command-line checking)

The checker is packaged with an HTTP client you can use from the command line to either send documents to a locally-running instance of the checker HTTP service — for fast command-line checking — or to a remote instance anywhere on the Web.

To check documents locally using the packaged HTTP client, do this:

  1. Start up the checker as a local HTTP service, as described in the Standalone web server section.

  2. Open a new terminal window and invoke the HTTP client like this:

java -cp ~/vnu.jar nu.validator.client.HttpClient FILE.html...

vnu-runtime-image/bin/java nu.validator.client.HttpClient FILE.html...

To send documents to an instance of the checker on the Web, such as html5.validator.nu/, use the nu.validator.client.host and nu.validator.client.port options, like this:

java -cp ~/vnu.jar -Dnu.validator.client.port=80 \
    -Dnu.validator.client.host=html5.validator.nu \
    nu.validator.client.HttpClient FILE.html...

…or like this:

vnu-runtime-image/bin/java -Dnu.validator.client.port=80 \
    -Dnu.validator.client.host=html5.validator.nu \
    nu.validator.client.HttpClient FILE.html...

Other options are documented below.

HTTP client options

When using the packaged HTTP client for sending documents to an instance of the checker HTTP service for checking, you can set Java system properties to control configuration options for the checker behavior.

For example, you can suppress warning-level messages and only show error-level ones by setting the value of the nu.validator.client.level system property to error, like this:

java -Dnu.validator.client.level=error \
       -cp ~/vnu.jar nu.validator.client.HttpClient FILE.html...

…or like this:

vnu-runtime-image/bin/java -Dnu.validator.client.level=error \
       -cp ~/vnu.jar nu.validator.client.HttpClient FILE.html...

Most of the properties listed below map to the common input parameters for the checker service, as documented at github.com/validator/validator/wiki/Service-»-Common-params.

nu.validator.client.host

Specifies the hostname of the checker for the client to connect to.

default: "127.0.0.1"

nu.validator.client.port

Specifies the hostname of the checker for the client to connect to.

default: "8888"

example: java -Dnu.validator.client.port=8080 -jar ~/vnu.jar FILE.html

nu.validator.client.level

Specifies the severity level of messages to report; to suppress
warning-level messages, and only show error-level ones, set this property to
"error".

default: [unset]

possible values: "error"

example: java -Dnu.validator.client.level=error -jar ~/vnu.jar FILE.html

nu.validator.client.parser

Specifies which parser to use.

default: "html"; or, for *.xhtml input files, "xml"

possible values: [see information at URL below]

https://github.com/validator/validator/wiki/Service-%C2%BB-Common-params#parser

nu.validator.client.charset

Specifies the encoding of the input document.

default: [unset]

nu.validator.client.content-type

Specifies the content-type of the input document.

default: "text/html"; or, for *.xhtml files, "application/xhtml+xml"

nu.validator.client.out

Specifies the output format for messages.

default: "gnu"

possible values: [see information at URL below]

https://github.com/validator/validator/wiki/Service-%C2%BB-Common-params#out

nu.validator.client.asciiquotes

Specifies whether ASCII quotation marks are substituted for Unicode smart
quotation marks in messages.

default: "yes"

possible values: "yes" or "no"

HTTP servlet options

nu.validator.servlet.bind-address

Binds the validator service to the specified IP address.

default: 0.0.0.0 [causes the checker to listen on all interfaces]

possible values: The IP address of any network interface

example: -Dnu.validator.servlet.bind-address=127.0.0.1

nu.validator.servlet.connection-timeout

Specifies the connection timeout.

default: 5000

possible values: number of milliseconds

example: -Dnu.validator.servlet.connection-timeout=5000

nu.validator.servlet.socket-timeout

Specifies the socket timeout.

default: 5000

possible values: number of milliseconds

example: -Dnu.validator.servlet.socket-timeout=5000

Pulling the Docker image

You can pull the checker Docker image from https://ghcr.io/validator/validator in the GitHub container registry.

To pull and run the latest version of the checker:

  docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest

To pull and run a specific tag/version of the checker from the container registry — for example, the 17.11.1 version:

  docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:17.11.1

To bind the checker to a specific address (rather than have it listening on all interfaces):

  docker run -it --rm -p 128.30.52.73:8888:8888
  ghcr.io/validator/validator:latest

To make the checker run with a connection timeout and socket timeout different than the default 5 seconds, use the CONNECTION_TIMEOUT_SECONDS and SOCKET_TIMEOUT_SECONDS environment variables:

  docker run -it --rm \
     -e CONNECTION_TIMEOUT_SECONDS=15 \
     -e SOCKET_TIMEOUT_SECONDS=15 \
     -p 8888:8888 \
     validator/validator

To make the checker run with particular Java system properties set, use the JAVA_TOOL_OPTIONS environment variable:

  docker run -it --rm \
     -e JAVA_TOOL_OPTIONS=-Dnu.validator.client.asciiquotes=yes  \
     -p 8888:8888 \
     validator/validator

To define a service named vnu for use with docker compose, create a Compose file named docker-compose.yml (for example), with contents such as the following:

  version: '2' services:
    vnu:
      image: validator/validator ports:
        - "8888:8888"
      network_mode: "host" #so "localhost" refers to the host machine.

Build instructions

Follow the steps below to build, test, and run the checker such that you can open http://0.0.0.0:8888/ in a Web browser to use the checker Web UI.

  1. Make sure you have git, python, and JDK 8 or above installed.

  2. Set the JAVA_HOME environment variable:

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 <-- Ubuntu, etc.

    export JAVA_HOME=$(/usr/libexec/java_home) <-- MacOS

  3. Create a working directory:

    git clone https://github.com/validator/validator.git

  4. Change into your working directory:

    cd validator

  5. Start the checker Python script:

    python ./checker.py all

The first time you run the checker Python script, you’ll need to be online and the build will need time to download several megabytes of dependencies.

The steps above will build, test, and run the checker such that you can open http://0.0.0.0:8888/ in a Web browser to use the checker Web UI.

Warning: Future checker releases will bind by default to the address 127.0.0.1. Your checker deployment might become unreachable unless you use the --bind-address option to bind the checker to a different address:

    python ./checker.py --bind-address=128.30.52.73 all

Use python ./checker.py --help to see command-line options for controlling the behavior of the script, as well as build-target names you can call separately; e.g.:

  • python ./checker.py build # to build only

  • python ./checker.py build test # to build and test

  • python ./checker.py run # to run only

  • python ./checker.py jar # to compile vnu.jar

  • python ./checker.py update-shallow &&
      python ./checker.py dldeps &&
      python ./checker.py jar       # to compile vnu.jar faster

grunt-html's People

Contributors

arttse avatar bennieswart avatar blech75 avatar burgaard avatar cvrebert avatar dependabot[bot] avatar ericdunsworth avatar iestyn avatar is2ei avatar jawshooah avatar jzaefferer avatar laurentgoderre avatar mgroeninger avatar mpparsley avatar nschonni avatar sideshowbarker avatar strille avatar thewarpaint avatar willfarrell avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-html's Issues

Invalid JSON when used with Java environment variables

Our builds are done in a Docker container and this has several environment variables set including JAVA_TOOL_OPTIONS. Sadly this causes Java to print a message on stderr. When grunt-html reads from stderr and tries to parse the JSON, it throws a "helpful" exception like Unexpected token P without a stack trace. It seems that this Java notice can't be disabled.

You can test by running JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8" java in your shell. You should see Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 followed by the help. There is an openjdk issue for this https://bugs.openjdk.java.net/browse/JDK-8039152.

What would be nice is to provide better error handling so that a user can easily tell that the Java validator isn't returning valid JSON. I think that this is probably worth doing. I can make a PR if you like.

We could also test for this message and strip it before parsing but I'm not sure that you want a hack for something this although it should help it be more universal.

I have worked around this by removing this environment variable from process.env and this prevents it being passed to spawned processes too. With this fix, I have no problems so feel free to just close this if you like.

I recently converted one of our projects to use grunt-html instead of grunt-validate-html. Its working great - thanks.

specifying options per file list

First, thank you for this great plugin.

It appears that the options property can only be set on htmllint, not specific sub-tasks.

htmllint: {
    foo_action: ["file_foo.html"],
    bar_action: ["file_bar.html"],
    options: {
        // options for foo_action and bar_action
    }
}

If possible, something along the lines of the example below would be much more useful for me

htmllint: {
    foo_action: {
       files: ["file_foo.html"],
       options: {
           // foo specific options
       }
    },
    bar_action: {
       files: ["file_foo.html"],
       options: {
           // bar specific options
       }
    },
    options: {
       // options for foo and bar actions
    }
}

Is this possible? Am I missing something in the instructions?

Fatal error: Unexpected token P

Hello,
I'm trying to validate my HTML using grunt-HTML, but although my file is validated by the W3C Validator, grunt-html outputs Fatal error: Unexpected token P
When I run java -jar /home/konfiot/gravity/node_modules/grunt-html/vnu.jar client/html/index.html I get the following output Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar.
I know it might be a duplicate of #65, but I didn't find any solution on this issue.
Thanks in advace for any help

Validate from URL

It should be possible to use URLs instead of files to validate. That would make this tool much more useful when testing full applications.

Support for partials

Great plugin, thanks! It would be really cool if it would support the validation of partials via a wrapper-file (possibly though grunt-contrib-concat) or a config item wrap-pre: '<html><body>', wrap-post: '</body></html>'

Fatal error: Unexpected token E

I was using grunt-html in a project and it worked fine for a while. Then the htmllint task began to fail with "Fatal error: Unexpected token E".

This issue is not a duplicate of #65 "Fatal error: Unexpected token P", because in my case, I don't have JAVA_TOOL_OPTIONS defined in my environment.

Running grunt with --stack resulted in

SyntaxError: Unexpected token E
    at Object.parse (native)
    at /Users/kim/Projects/sandboot/node_modules/grunt-html/lib/htmllint.js:46:25
    at ChildProcess.exithandler (child_process.js:210:5)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:817:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:469:12)

So I added console.error(stderr); to grunt-html/lib/htmllint.js before line 46 and got

Exception in thread "main" java.lang.NoClassDefFoundError: nu/validator/datatype/CdoCdcPair
    at nu.validator.datatype.Html5DatatypeLibrary.createDatatype(Html5DatatypeLibrary.java:152)
    at nu.validator.spec.html5.Html5AttributeDatatypeBuilder.endElement(Html5AttributeDatatypeBuilder.java:155)
    at nu.validator.saxtree.TreeParser.endElement(TreeParser.java:132)
    at nu.validator.saxtree.Element.revisit(Element.java:110)
    at nu.validator.saxtree.TreeParser.parse(TreeParser.java:95)
    at nu.validator.htmlparser.sax.HtmlParser.parse(HtmlParser.java:428)
    at nu.validator.spec.html5.Html5AttributeDatatypeBuilder.parseSyntaxDescriptions(Html5AttributeDatatypeBuilder.java:75)
    at nu.validator.messages.MessageEmitterAdapter.<clinit>(MessageEmitterAdapter.java:289)
    at nu.validator.client.SimpleCommandLineValidator.setErrorHandler(SimpleCommandLineValidator.java:326)
    at nu.validator.client.SimpleCommandLineValidator.setup(SimpleCommandLineValidator.java:190)
    at nu.validator.client.SimpleCommandLineValidator.main(SimpleCommandLineValidator.java:179)
Caused by: java.lang.ClassNotFoundException: nu.validator.datatype.CdoCdcPair
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 11 more
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    at java.util.zip.ZipFile.read(Native Method)
    at java.util.zip.ZipFile.access$1200(ZipFile.java:31)
    at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:461)
    at java.util.zip.ZipFile$1.fill(ZipFile.java:244)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:141)
    at sun.misc.Resource.getBytes(Resource.java:108)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:257)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    ... 16 more

Then I checked vnu.jar embedded with grunt-html to see if it was corrupted:

$ java -jar vnu.jar
Usage:

    java -jar vnu.jar [--errors-only] [--no-stream]
         [--format gnu|xml|json|text] [--help] [--html]
         [--skip-non-html] [--verbose] [--version] FILES

    java -cp vnu.jar nu.validator.servlet.Main 8888

    java -cp vnu.jar nu.validator.client.HttpClient FILES

For detailed usage information, use "java -jar vnu.jar --help" or see:

  http://validator.github.io/

To read from stdin, use "-" as the filename, like this: "java -jar vnu.jar - ".
Mac-10ddb1d127ad:grunt-html kim$ java -jar vnu.jar 
Usage:

    java -jar vnu.jar [--errors-only] [--no-stream]
         [--format gnu|xml|json|text] [--help] [--html]
         [--skip-non-html] [--verbose] [--version] FILES

    java -cp vnu.jar nu.validator.servlet.Main 8888

    java -cp vnu.jar nu.validator.client.HttpClient FILES

For detailed usage information, use "java -jar vnu.jar --help" or see:

  http://validator.github.io/

To read from stdin, use "-" as the filename, like this: "java -jar vnu.jar - ".

In order to move on, I then deleted node_modules/grunt-html and ran npm install to reinstall it.

Unfortunately, that worked. So, somehow I had a corrupted Jar file which may or may not have been vnu.jar and I have no idea how the corruption happened.

Not sure this helps at all, but hopefully it'll help other people who run into the same error message.

"Fatal error: Cannot read property '1' of null" when running task

Hi!

When I run the task as it is documented in the wiki:

grunt.initConfig({
  htmllint: {
    all: ["demos/**/*.html", "tests/**/*.html"]
  }
});

I get "Fatal error: Cannot read property '1' of null":

$ grunt htmllint
Running "htmllint:all" (htmllint) task
Fatal error: Cannot read property '1' of null

I tried some config variations, but I always get the error stated above.
Here's my setup:

$ grunt --version
grunt-cli v0.1.13
grunt v0.4.5

$ node --version
v0.12.0

All other tasks in the same gruntfile work perfectly.

Greetings!

Json Reporter

Hi,

Could the results in the json reporter be grouped by the file name, like it is in the checkstyle reporter?

Ignore using Regex literal or String literal as exampled in README doesn't work

Attempting to use a String literal or Regex literal for ignoring errors throws the following error:

all: {
    options: {
        ignore: 'The “clear” attribute on the “br” element is obsolete. Use CSS instead.'
    },
    src: "html4.html"
}

Fatal error: Object Attribute "The 'clear' attribute on the 'br' element is obsolete. Use CSS instead.” at this point. has no method 'every'

The ignore rules must be wrapped in an array, every if just one.

Add a `force` option

HTML validation is great, but I don't want a warning to fail my build. A force option would allow grunt to continue even if grunt-html produces warnings.

Using the ignore option is not helpful, as I'd still like to be notified of imperfect markup. I just don't want it to fail the entire build.

Directly using grunt --force doesn't help either, as there are other, more critical steps in my build that should not be allowed to fail.

Update to grunt 0.4

utils -> util
second callback argument to spawn is an object, need to reference result.stdout

Check all src files exist

Seems like the validator gets stuck when the target is a file that doesn't exist. Should add a check to the grunt task to warn about missing files and not run them through the validator.

Adding output.html file

Is there any way we can specify output.html file to the config. i have added htmllint task to watch list so correct html code will be available in output.html file.

Problem with angular 2 directive e.g *ngIf, (click), [class.selected]

Code:
<div *ngIf="hero" [class.selected]="hero === selectedHero" (click)="onSelect(hero)">

i have added below in ignore list

    '(\\([a-z]+\\))',
    '(\\[[a-z.]+\\])',
    '(\\[\\((ng)[a-z]+\\)\\])',
    '(\\*ng)[a-z]+'

still Error:
Attribute “*ngif” is not serializable as XML 1.0.
Attribute “[class.selected]” is not serializable as XML 1.0.
Attribute “(click)” is not serializable as XML 1.0.

more about angular2 syntax https://angular.io/docs/ts/latest/guide/structural-directives.html

on mac: "Error: Unable to access jarfile" thrown

On my mac when I run the grunt command i get this error. It is due to the fact that the one of the parent directories in the file system tree containing this project has a space on it. An easy way to fix this is simply encapsulating the java -jar command with double quotes here:

https://github.com/jzaefferer/grunt-html/blob/master/lib/htmllint.js#L14

change the first parameter in that exec call from:
'java -jar ' + jar + ' --format json ' + chunk
to
'java -jar "' + jar + '" --format json ' + chunk

Use vnu-jar package

An NPM package was now setup to publish the JAR when releases are tagged https://www.npmjs.com/package/vnu-jar
This might cause more noise for this repo if something upstream breaks, but at least then there is no need to bump this package everytime there is a new upstream semver release.

Empty file list causes fatal error

If the list of sourcefiles is empty ( or the wildcards don't match anything ), the linter exits with a fatal error, eg

 grunt.initConfig({
     htmllint: {
         bug: 'nonexistent/*.html'
     }
});

grunt htmllint:bug
Running "htmllint:bug" (htmllint) task
Fatal error: Unexpected token E

More specific name

html is a pretty generic name for a task; htmllint is more descriptive and matches lint and csslint.

An error occurred while processing a template

This is the error I get:

An error occurred while processing a template (Cannot call method 'indexOf' of undefined). Use --force to continue.

Haven't been able to make htmllint work.

Allow for excluding files/folders

I'm trying to run this task with the following config:

   grunt.initConfig({
     htmllint: {
       all: ["**/*.html", "!coverage/**/*.html"]
      }
    });

I want all the html files to be tested except those in the code coverage directory but when I tried the standard ! prefix this I get the following error:

Error: Command failed: /bin/sh: 1: Syntax error: "(" unexpected

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

Feature request: Ignore certain error messages

The grunt task should have an option to ignore certain errors. Originally suggested via #15:

I am using grunt-html to validate a set of HTML files which are actually HTML fragments, so I need to ignore certain messages. I added an option called 'ignore', which accepts an array of messages to ignore.

Example usage:

grunt.initConfig({
    htmllint: {
        options: {
            ignore: [
                'Element "head" is missing a required instance of child element "title".',
                'Start tag seen without seeing a doctype first. Expected e.g. "<!DOCTYPE html>".'
            ]
        },
        all: ['content/**/*.html']
    }
});

The filtering should be implemented in lib/htmllint.js along with tests.

Terminal colour coding

Feature request: Apply same colour coding ad JSHint to error messages returned for easy reading.

HTML5?

Does this plugin validates according to the HTML5 specs? Does it takes into account the doctype to choose which type of validation applies?

Please test 16.12.27 release candidate of vnu.jar

I plan to do a new vnu.jar release soon and have prepared a package revved at 16.12.27 which should be considered a release candidate.

You should be able to get the npm either with 16.12.27 as the version or the tag dev. (If I messed up anything with the packaging of that, I trust that @Arttse can help me unwind it.)

It’s also available from https://github.com/validator/validator/releases/tag/16.12.27 and from https://sideshowbarker.net/nightlies/jar/

I’d appreciate it if y’all could test it and let me know if you run into any problems or surprises.

Every regexp I tried doesn't work

For example:
a settings like ignore: [ '/.+/'] should ignore everything, right?

A settings like ignore: ['/Element “.+-component” .+'] should ignore the following 'knockout' error ?:

Element “blabla-component” not allowed as child of element “div” in this context. (Suppressing further errors from this subtree.)

I'm using grunt: 1.0.0, grunt-html: 8.0.2

wrong errors reported on Grunt-reporter

config:

        options: {
          ignore: [
            'Element "head" is missing a required instance of child element "title".',
            'Attribute "ng-app" not allowed on element "body" at this point.',
            'Element “title” must not be empty.',
            /ng-/i,
            /qms-/i,
            /bs-/i,
            /ui-/i,
            /DOCTYPE html/i,
            /data:image\/x-icon;,/i,
            /not allowed on element .+ at this point\./i,
            /not allowed as child of element/i,
            /Bad value “{{[^}]+}}”/
          ],
          errorlevels: ['error'],
          //reporter: 'checkstyle',
          //reporterOutput: 'htmllint-results.xml',
        }

errors reported on Grunt-reporter (shows ignored errors, notice the "ng-app"):

app\404.html [L1:C11] Comments seen before doctype. Internet Explorer will go into the quirks mode.
app\debug.html [L1:C11] Comments seen before doctype. Internet Explorer will go into the quirks mode.
app\debug.html [L21:C35] Attribute "ng-app" not allowed on element "body" at this point.

errors in checkstyle file (as expected):

    <file name="....tpl.html">
        <error line="52" column="44" severity="error" message="Self-closing syntax (“/&gt;”) used on a non-void HTML element. Ignoring the slash and treating as a start tag." source="htmllint.ValidationError" />
        <error line="53" column="23" severity="error" message="End tag “button” seen, but there were open elements." source="htmllint.ValidationError" />
        <error line="52" column="44" severity="error" message="Unclosed element “span”." source="htmllint.ValidationError" />
    </file>

(testet on 291cf04)

Is there any way to exclude specific files?

Hi - I have a couple of files that fail linting, and I expect them to fail, but they are within directories with other files that need linting fully. I guess I can set up a task that lists all the other files in an array in the target list but I was hoping there is some easy way to exclude them instead, which would be easier and more robust. I can then have a separate grunt task to lint those files with the relevant messages in the ignore section.
Thanks,
Will

Bad value “breadcrumbs” for attribute “role” on element “nav”.

I was attempting to validate HTML that used the following code:

<nav role="breadcrumbs" aria-label="breadcrumb navigation">
  <ol class="breadcrumb">
    <li><a href="#">Home</a></li>
    <li><a href="#">Library</a></li>
    <li class="active">Data</li>
  </ol>
</nav>

I got:

_gh_pages/components/index.html [L3154:C63] Bad value “breadcrumbs” for attribute “role” on element “nav”.

I'm not sure why I'm getting this though as breadcrumbs is a valid role per the W3 spec found here: http://www.w3.org/TR/2007/WD-aria-role-20070601/#breadcrumbs

I'm sure there must be something I'm missing here and was hoping you may be able to address what I'm missing.

Video tags are parsed incorrectly

Here's a perfect valid video tag:

<video preload>
   <source src="video.mp4" type="video/mp4; codecs=avc1.42E01E,mp4a.40.2">
   <source src="video.webm" type="video/webm; codecs=vp8,vorbis">
   <source src="video.ogv" type="video/ogg; codecs=theora,vorbis">
</video>

Error message

Bad value “video/mp4; codecs=avc1.42E01E,mp4a.40.2” for attribute “type” on element “source”: Expected a token character, whitespace or a semicolon but saw “,” instead.
Bad value “video/webm; codecs=vp8,vorbis” for attribute “type” on element “source”: Expected a token character, whitespace or a semicolon but saw “,” instead.
Bad value “video/ogg; codecs=theora,vorbis” for attribute “type” on element “source”: Expected a token character, whitespace or a semicolon but saw “,” instead.

java.lang.StackOverflowError when running

Hey guys im getting a java.lang.StackOverflowError error whenever I run the grunt task here's my config:

htmllint: {
    all: ["html/index.html"]
}

I'm currently running Java 7 update 51 on windows.

Check files with HTML

Currently if I run the validator on a file like 'app.html.php', the validator will not run on the file because it must end in an '.html' extension. The validator should be able to run on files like '.html..php'

Doesn't work on Travis anymore

Travis currently has Java 7 as default, since the v6 release we required Java 8, since that is now the minimum supported by vnuvalidator. For Travis Java projects its possible to specify the JDK version: https://github.com/jzaefferer/grunt-html/blob/545caebe6858d8a624fd6a8320cba5424893b0db/.travis.yml#L10-L11

But this doesn't work for node (see jquery/jquery-ui#1674 ), and I don't think its acceptable to ask everyone to change their node projects to java and specify the node dependency manually.

Would be nice if Travis would just update the default JDK to 8. Not sure what else to do. Any ideas, @XhmikosR, @jawshooah, @LaurentGoderre?

Update to be grunt 0.4.x compatible

When I try to utilize the htmllint task with grunt 0.4.0a, it fails:

Running "htmllint:all" (htmllint) task
Warning: Cannot call method 'spawn' of undefined Use --force to continue.

Aborted due to warnings.

Here's my [simplified] "Gruntfile.js" configuration:

module.exports = function(grunt) {
  grunt.initConfig({
    htmllint: {
      all: ['*.html']
    }
  });

  grunt.loadNpmTasks('grunt-html');

  grunt.registerTask('default', ['htmllint']);
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.