gulp-htmlhint = function (options) {
'use strict';
var ruleset = {};
if (!options) {
options = {};
}
// Read Htmlhint options from a specified htmlhintrc file.
if (typeof options === 'string') {
// Don't catch readFile errors, let them bubble up
options = {
htmlhintrc: './' + options
};
}
// if necessary check for required param(s), e.g. options hash, etc.
// read config file for htmlhint if available
if (options.htmlhintrc) {
try {
var externalOptions = fs.readFileSync(options.htmlhintrc, 'utf-8');
options = JSON.parse(stripJsonComments(externalOptions));
} catch (err) {
throw new Error('gulp-htmlhint: Cannot parse .htmlhintrc');
}
}
// Build a list of all available rules
for (var key in HTMLHint.defaultRuleset) {
if (HTMLHint.defaultRuleset.hasOwnProperty(key)) {
ruleset[key] = 1;
}
}
// normalize htmlhint options
// htmllint only checks for rulekey, so remove rule if set to false
for (var rule in options) {
if (options[rule]) {
ruleset[rule] = options[rule];
} else {
delete ruleset[rule];
}
}
return through2.obj(function (file, enc, cb) {
var report = HTMLHint.verify(file.contents.toString(), ruleset);
// send status down-stream
file.htmlhint = formatOutput(report, file, options);
cb(null, file);
});
}n/a
addRule = function (rule) {
'use strict';
return HTMLHint.addRule(rule);
}...
gutil.log(data.message);
gutil.log(data.evidence);
});
};
htmlhintPlugin.addRule = function (rule) {
'use strict';
return HTMLHint.addRule(rule);
};
htmlhintPlugin.reporter = function (customReporter) {
'use strict';
var reporter = defaultReporter;
if (typeof customReporter === 'function') {
...failReporter = function (opts) {
'use strict';
opts = opts || {};
return through2.obj(function (file, enc, cb) {
// something to report and has errors
var error;
if (file.htmlhint && !file.htmlhint.success) {
if (opts.suppress === true) {
error = new PluginError('gulp-htmlhint', {
message: 'HTMLHint failed.',
showStack: false
});
} else {
var errorCount = file.htmlhint.errorCount;
var plural = errorCount === 1 ? '' : 's';
var msg = c.cyan(errorCount) + ' error' + plural + ' found in ' + c.magenta(file.path);
var messages = [msg].concat(getMessagesForFile(file).map(function (m) {
return m.message;
}));
error = new PluginError('gulp-htmlhint', {
message: messages.join(os.EOL),
showStack: false
});
}
}
cb(error, file);
});
}...
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.failReporter())
```
Optionally, you can pass the `htmlhint.failReporter` a config object
__Plugin options:__
- *suppress*
...reporter = function (customReporter) {
'use strict';
var reporter = defaultReporter;
if (typeof customReporter === 'function') {
reporter = customReporter;
}
if (typeof customReporter === 'string') {
if (customReporter === 'fail') {
return htmlhintPlugin.failReporter();
}
reporter = require(customReporter);
}
if (typeof reporter === 'undefined') {
throw new Error('Invalid reporter');
}
return through2.obj(function (file, enc, cb) {
// Only report if HTMLHint ran and errors were found
if (file.htmlhint && !file.htmlhint.success) {
reporter(file);
}
cb(null, file);
});
}...
### Default reporter
```javascript
var htmlhint = require("gulp-htmlhint");
gulp.src("./src/*.html")
.pipe(htmlhint())
.pipe(htmlhint.reporter())
```
### Fail reporter
Use this reporter if you want your task to fail in case of a HTMLHint Error.
It also prints a summary of all errors in the first bad file.
...