praveenvijayan / grunt-html-validation

W3C html validaton grunt plugin. Validate all files in a directory automatically.
MIT License
75 stars 39 forks source link

grunt-html-validation Build Status

NPM

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

Getting Started

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']);

The "validation" task

Overview

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']
    }
}

Options

options.reset

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

options.proxy

Type: String
Default value: null

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

proxy: 'http://proxy:8080'

options.serverUrl

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

options.path

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

Default file for storing validation information.

options.reportpath

Type: String
Default value: validation-report.json

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

options.stoponerror

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.

options.maxTry

Type: Number
Default value: 3

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

options.remotePath

Type: String
Default value: ``

options.wrapfile

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>

options.remoteFiles

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/']

options.relaxerror

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']

options.doctype

Type: String
Default value: false

Set false for autodetect or chose one of this options:

options.charset

Type: String
Default value: false

Set false for autodetect or chose one of this options:

options.failHard

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.

Contributing

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

Release History

Bitdeli Badge