grunt-htmlhint-plus
v0.6.0
Published
Grunt task to hint html code.
Downloads
493
Maintainers
Readme
Grunt-htmlhint-plus
Grunt task to hint html code.
Getting Started
This plugin requires Grunt >=0.4.0
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-htmlhint-plus --save-dev
Or you may like yarn:
yarn add grunt-htmlhint-plus -D
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-htmlhint-plus');
Htmlhintplus Task
Run this task with the grunt htmlhintplus
command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Options
src {String|Array}
Source path. Support file path, glob and globs.
options.rules {Object}
Htmlhint rules. Default is:
- "tagname-lowercase": true,
- "attr-lowercase": true,
- "attr-value-double-quotes": true,
- "attr-value-not-empty": true,
- "attr-no-duplication": true,
- "doctype-first": true,
- "tag-pair": true,
- "tag-self-close": false,
- "spec-char-escape": true,
- "id-unique": true,
- "src-not-empty": true,
- "head-script-disabled": false,
- "img-alt-require": true,
- "doctype-html5": true,
- "id-class-value": "dash",
- "style-disabled": false,
- "space-tab-mixed-disabled": true,
- "id-class-ad-disabled": true,
- "href-abs-or-rel": true,
- "attr-unsafe-chars": true
For the whole rules list, please see Rules page.
options.htmlhintrc {String}
Htmlhintrc file path. Has higher priority than rules
option.
options.force {Boolean}
Throw fatal fail or not at the end of this task, when there is hint error. Default false
.
options.newer {Boolean}
Only hint changed file and new file. Default true
.
options.ignore {Object}
Ignore strings between key and value from this object. Default {}
.
options.customRules {Array}
An array of paths to custom rule files to load and use in your HTMLHinting. See issue #47 on the HTMLHint project. For examples of how to write a custom rule.
options.extendRules {Boolean}
Extend the default rules instead of only running the rules specified. Default false
.
options.output {String|Array}
A string or array of output file types for reporting. Multiple types can also be selected separating them with a pipe character (ex: console|checkstyle|json
). Available output types include console
, default
(alias for console), text
, json
, and checkstyle
. Default console
.
Usage Examples
Basic
// Project configuration
htmlhintplus: {
build: {
options: {
rules: {
'tag-pair': true,
'custom-rule': true
},
customRules: [
'rules/custom-rule.js'
],
extendRules: true,
output: [ 'console', 'text', 'json', 'checkstyle' ]
}
src: 'path/to/file'
}
}
Use htmlhintrc file
// Project configuration
htmlhintplus: {
html: {
options: {
htmlhintrc: 'path/to/file'
}
src: [
'path/to/file',
'path/to/file2'
]
}
}
Use global options
// Project configuration
htmlhintplus: {
options: {
htmlhintrc: 'path/to/file',
newer: true
},
build: {
options: {
force: false
},
src: [
'path/1/*.html',
'path/2/**/*.html'
]
}
}
Demo
Run the test demo:
grunt test