grunt-html-validation

W3C html validation grunt plugin

grunt-html-validation

W3C html validation grunt plugin. Validate all files in a directory automatically.

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-html-validation --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-html-validation');

And add to your task list using validation:

grunt.registerTask('default', ['validation']);

In your project's Gruntfile, add a section named validation to the data object passed into grunt.initConfig().

validation: {
    options: {
        reset: grunt.option('reset') || false,
        stoponerror: false,
        remotePath: 'http://decodize.com/',
        remoteFiles: ['html/moving-from-wordpress-to-octopress/',
                      'css/site-preloading-methods/'], //or 
        remoteFiles: 'validation-files.json', // JSON file contains array of page paths. 
        relaxerror: ['Bad value X-UA-Compatible for attribute http-equiv on element meta.'] //ignores these errors 
    },
    files: {
        src: ['<%= yeoman.app %>/*.html',
              '!<%= yeoman.app %>/index.html',
              '!<%= yeoman.app %>/modules.html',
              '!<%= yeoman.app %>/404.html']
    }
}

Type: Boolean
Default value: 'false'

Resets all the validated files status. When want to revalidate all the validated files - eg: sudo grunt validate --reset=true

Type: String
Default value: null

Setup your proxy when you are behind a corporate proxy and encounters ETIMEDOUT.

proxy: 'http://proxy:8080'

Type: String
Default value: null

Supply a different validator server URL, for instance if you run a local server. Eg: http://localhost/w3c-validator/check

Type: String
Default value: 'validation-status.json'

Default file for storing validation information.

Type: String
Default value: validation-report.json

Consolidated report in JSON format, if reportpath is false it will not generated.

Type: Boolean
Default value: false

When hit by a validation error, html-validator continue validating next file by default and this process continues until all files in the list completes validation. If 'stoponerror' set to true, validator will stop validating next file.

Type: Number
Default value: 3

Number of retries when network error occuers. Default case, after 3 reties validator will move to next file.

Type: String
Default value: ``

Type: String
Default value: ``

File that will wrap your files inside.

The file must contain a comment that will be replaced by each file content: <!-- CONTENT -->

Useful to validate partials because w3c validator need <html>, <head>, <body>...

Note: line reported will be the partial line, if you see a negative number this means that the error is in the wrapfile.

example

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
      <!-- CONTENT -->
  </body>
</html>

Type: Array
Default value: ``

Array of page paths to be validated. When remote files are not present validator will append file names from local folder. remotePath is mandatory when this option is specified.

eg:

remoteFiles: ['html/moving-from-wordpress-to-octopress/',
              'css/site-preloading-methods/']

you can also provide a file that contains an array of pages.

remoteFiles: 'validation-files.json'
['html/getting-started-with-yeoman-1-dot-0-beta-on-windows',
'html/slidemote-universal-remote-control-for-html5-presentations/',
'html/simple-responsive-image-technique/']

Type: Array
Default value: ``

Helps to skip certain w3c errors messages from validation. Give exact error message or a regular expression in an array & validator will ignore those relaxed errors from validation.

relaxerror: ['Bad value X-UA-Compatible for attribute http-equiv on element meta.',
             'document type does not allow element "[A-Z]+" here']

Type: String
Default value: false

Set false for autodetect or chose one of this options:

  • HTML5
  • XHTML 1.0 Strict
  • XHTML 1.0 Transitional
  • XHTML 1.0 Frameset
  • HTML 4.01 Strict
  • HTML 4.01 Transitional
  • HTML 4.01 Frameset
  • HTML 4.01 + RDFa 1.1
  • HTML 3.2
  • HTML 2.0
  • ISO/IEC 15445:2000 ("ISO HTML")
  • XHTML 1.1
  • XHTML + RDFa
  • XHTML Basic 1.0
  • XHTML Basic 1.1
  • XHTML Mobile Profile 1.2
  • XHTML-Print 1.0
  • XHTML 1.1 plus MathML 2.0
  • XHTML 1.1 plus MathML 2.0 plus SVG 1.1
  • MathML 2.0
  • SVG 1.0
  • SVG 1.1
  • SVG 1.1 Tiny
  • SVG 1.1 Basic
  • SMIL 1.0
  • SMIL 2.0

Type: String
Default value: false

Set false for autodetect or chose one of this options:

  • utf-8
  • utf-16
  • iso-8859-1
  • iso-8859-2
  • iso-8859-3
  • iso-8859-4
  • iso-8859-5
  • iso-8859-6-i
  • iso-8859-7
  • iso-8859-8
  • iso-8859-8-i
  • iso-8859-9
  • iso-8859-10
  • iso-8859-11
  • iso-8859-13
  • iso-8859-14
  • iso-8859-15
  • iso-8859-16
  • us-ascii
  • euc-jp
  • shift_jis
  • iso-2022-jp
  • euc-kr
  • gb2312
  • gb18030
  • big5
  • big5-HKSCS
  • tis-620
  • koi8-r
  • koi8-u
  • iso-ir-111
  • macintosh
  • windows-1250
  • windows-1251
  • windows-1252
  • windows-1253
  • windows-1254
  • windows-1255
  • windows-1256
  • windows-1257

Type: boolean
Default value: false

If true, the task will fail at the end of its run if there were any validation errors that were not ignored via options.relaxerror.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Report issues here

  • 2014-05-27 v0.1.18 Version bump, Fixes #54
  • 2014-05-15 v0.1.17 Fixes #50, #52
  • 2014-04-23 v0.1.16 Fixes
  • 2014-04-03 v0.1.15 Updated dependencies (jshnt, nodeunit, request), gitignore, code cleanup etc..
  • 2014-03-23 v0.1.14 Updated with wrapfile & server url options.
  • 2013-12-26 v0.1.13 Fixed running multiple tasks fail due to validation failure.
  • 2013-12-17 v0.1.11 Option to set proxy, w3cjs updated to 0.1.22, added fail hard and some bug fixes
  • 2013-11-22 v0.1.9 Fix some bugs
  • 2013-11-22 v0.1.8 Added options for specify doctype and charset
  • 2013-11-22 v0.1.7 Added support for RegExp in relaxed validation
  • 2013-08-31   v0.1.6   Added relaxed validation, w3cjs updated from 0.1.9 to 0.1.10.
  • 2013-08-31   v0.1.5   Added remote validation support. Max network error retry count.
  • 2013-08-19   v0.1.4   Fixed issues. Added 'stoponerror' option, validation report added.
  • 2013-08-05   v0.1.2   Fixed issues.
  • 2013-04-20   v0.1.0   Initial release.