Skip to content

Latest commit

 

History

History
293 lines (234 loc) · 7.86 KB

README.md

File metadata and controls

293 lines (234 loc) · 7.86 KB

grunt-w3c-validation

W3C html and css validation grunt plugin. Validate all files in a directory automatically. Forked from https://github.com/praveenvijayan/grunt-html-validation

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-w3c-validation --save-dev

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

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

And add to your task list using html-validation or css-validation:

grunt.registerTask("default", ["html-validation"]);
grunt.registerTask("default", ["css-validation"]);

The "*-validation" task

Overview

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

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

css-validation: {
	options: {
		reset: grunt.option('reset') || false,
		stoponerror:false,
		relaxerror: [],
		profile: 'css3', // possible profiles are: none, css1, css2, css21, css3, svg, svgbasic, svgtiny, mobile, atsc-tv, tv
		medium: 'all', // possible media are: all, aural, braille, embossed, handheld, print, projection, screen, tty, tv, presentation
		warnings: '0' // possible warnings are: 2 (all), 1 (normal), 0 (most important), no (no warnings)
	  },
	  files: {
		src: ['<%= yeoman.app %>/css/*.css']
	  }
}

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.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: ``

Remote base url path. eg: "http://decodize.com/".

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 contains 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:

  • 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

options.charset

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

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.

options.profile

Type: String
Default value: css3

Possible values:

  • none
  • css1
  • css2
  • css3
  • svg
  • svgbasic
  • svgtiny
  • mobile
  • atsc-tv
  • tv

options.medium

Type: String
Default value: all

Possible values:

  • all
  • aural
  • braille
  • embossed
  • handheld
  • print
  • projection
  • screen
  • tty
  • tv
  • presentation

options.warnings

Type: String
Default value: no

Possible values:

  • 2 (all warnings)
  • 1 (normal warnings)
  • 0 (most important warnings)
  • no (no warnings)

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

  • 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.