Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bezoerb/gulp-htmlhint
https://github.com/bezoerb/gulp-htmlhint
gulp-plugin htmlhint
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/bezoerb/gulp-htmlhint
- Owner: bezoerb
- License: mit
- Created: 2014-01-14T05:41:36.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T19:16:45.000Z (over 1 year ago)
- Last Synced: 2024-04-13T20:32:43.078Z (7 months ago)
- Topics: gulp-plugin, htmlhint
- Language: JavaScript
- Size: 1.56 MB
- Stars: 81
- Watchers: 7
- Forks: 21
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# gulp-htmlhint [![NPM version][npm-image]][npm-url] [![Build Status][ci-image]][ci-url]
> [htmlhint](https://github.com/yaniswang/HTMLHint) wrapper for [gulp](https://github.com/wearefractal/gulp) to validate your HTML
## Usage
First, install `gulp-htmlhint` as a development dependency:
```shell
npm install --save-dev gulp-htmlhint
```Then, add it to your `gulpfile.js`:
```javascript
var htmlhint = require("gulp-htmlhint");gulp.src("./src/*.html")
.pipe(htmlhint())
```## API
### htmlhint([options [, customRules]])
#### options
See all rules here: [https://github.com/HTMLHint/HTMLHint/wiki/Rules](https://github.com/yaniswang/HTMLHint/wiki/Rules)If `options` is empty, the task will use standard options.
##### options.htmlhintrc
Type: `String`
Default value: `null`If this filename is specified, options and globals defined there will be used. Task and target options override the options within the `htmlhintrc` file. The `htmlhintrc` file must be valid JSON and looks something like this:
```json
{
"tag-pair": true
}
``````javascript
var htmlhint = require("gulp-htmlhint");gulp.src("./src/*.html")
.pipe(htmlhint('.htmlhintrc'))
```#### customRules
Type: `Array` _Optional_
Default value: `null`Array that contains all user-defined custom rules. Rules added to this param need not exist in the `htmlhintrc` file.
All rules inside this array should be valid objects and look like this:```javascript
{
id: 'my-custom-rule',
description: 'Custom rule definition',
init: function(parser, reporter){
//Code goes here
}
}
```Here is an example:
```javascript
var htmlhint = require("gulp-htmlhint");var customRules = [];
customRules.push({
id: 'my-custom-rule',
description: 'Custom rule definition',
init: function(parser, reporter){
//Code goes here
}
});gulp.src("./src/*.html")
.pipe(htmlhint('.htmlhintrc', customRules))
```Note: You can call `htmlhint` function four different ways:
- Without params (task will use standard options).
- With `options` param alone.
- With `customRules` param alone (task will only use custom rules options).
- With both `options` and `customRules` params defined.## Reporters
### Default reporter
```javascript
var htmlhint = require("gulp-htmlhint");gulp.src("./src/*.html")
.pipe(htmlhint())
.pipe(htmlhint.reporter())
```### Fail reporters
#### failOnError
Use this reporter if you want your task to fail on the first file that triggers an HTMLHint Error.
It also prints a summary of all errors in the first bad file.```javascript
var htmlhint = require("gulp-htmlhint");gulp.src("./src/*.html")
.pipe(htmlhint())
.pipe(htmlhint.failOnError())
```#### failAfterError
Use this reporter if you want to collect statistics from all files before failing.
It also prints a summary of all errors in the first bad file.```javascript
var htmlhint = require("gulp-htmlhint");gulp.src("./src/*.html")
.pipe(htmlhint())
.pipe(htmlhint.failAfterError())
```#### Reporter options
Optionally, you can pass a config object to either fail reporter.
##### suppress
Type: `Boolean`
Default value: `false`When set to `true`, errors are not displayed on failure.
Use in conjunction with the default and/or custom reporter(s).
Prevents duplication of error messages when used along with another reporter.```javascript
var htmlhint = require("gulp-htmlhint");gulp.src("./src/*.html")
.pipe(htmlhint())
.pipe(htmlhint.reporter("htmlhint-stylish"))
.pipe(htmlhint.failOnError({ suppress: true }))
```### Third-party reporters
[gulp-reporter](https://github.com/gucong3000/gulp-reporter) used in team project, it fails only when error belongs to the current author of git.
## License
[MIT License](bezoerb.mit-license.org)
[npm-url]: https://npmjs.org/package/gulp-htmlhint
[npm-image]: https://badge.fury.io/js/gulp-htmlhint.svg[ci-url]: https://github.com/bezoerb/gulp-htmlhint/actions/workflows/test.yml
[ci-image]: https://github.com/bezoerb/gulp-htmlhint/actions/workflows/test.yml/badge.svg