gulp-htmlhint
Advanced tools
Comparing version 0.2.1 to 0.3.0
0.3.0 / 2015-07-18 | ||
================== | ||
* Merge pull request #15 from doshprompt/require-reporter | ||
* Merge pull request #16 from doshprompt/fail-reporter | ||
* feat(failReporter): use suppress=true instead of errors=false | ||
* Update README.md | ||
* chore(README): more details on failReporter | ||
* feat(failReporter): add ability to turn off file errors on failure | ||
* test(reporter): load custom reporter by package name | ||
* feat(reporter): custom reporter can be loaded by its package name | ||
0.2.1 / 2015-07-17 | ||
@@ -3,0 +15,0 @@ ================== |
40
index.js
@@ -148,5 +148,9 @@ var fs = require('fs'), | ||
if (customReporter === 'fail') { | ||
return htmlhintPlugin.failReporter(); | ||
} | ||
if (typeof customReporter === 'string') { | ||
if (customReporter === 'fail') { | ||
return htmlhintPlugin.failReporter(); | ||
} else { | ||
reporter = require(customReporter); | ||
} | ||
} | ||
@@ -167,4 +171,5 @@ if (typeof reporter === 'undefined') { | ||
htmlhintPlugin.failReporter = function(){ | ||
htmlhintPlugin.failReporter = function(opts){ | ||
'use strict'; | ||
opts = opts || {}; | ||
return through2.obj(function (file, enc, cb) { | ||
@@ -174,13 +179,20 @@ // something to report and has errors | ||
if (file.htmlhint && !file.htmlhint.success) { | ||
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; | ||
})); | ||
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 | ||
}); | ||
error = new PluginError('gulp-htmlhint', { | ||
message: messages.join(os.EOL), | ||
showStack: false | ||
}); | ||
} | ||
} | ||
@@ -187,0 +199,0 @@ cb(error, file); |
{ | ||
"name": "gulp-htmlhint", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "A plugin for Gulp", | ||
@@ -28,2 +28,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"htmlhint-stylish": "^1.0.0", | ||
"jshint": "^2.6.3", | ||
@@ -30,0 +31,0 @@ "mocha": "^2.2.1", |
@@ -68,2 +68,3 @@ # gulp-htmlhint [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url] | ||
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. | ||
@@ -78,3 +79,21 @@ ```javascript | ||
Optionally, you can pass the `htmlhint.failReporter` a config object | ||
__Plugin options:__ | ||
- *supress* | ||
When set to `true`, it does not display file errors 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.failReporter({ suppress: true }) | ||
``` | ||
## License | ||
@@ -81,0 +100,0 @@ |
@@ -206,2 +206,28 @@ /*global describe, it*/ | ||
it('should load custom reporters by package name', function(done) { | ||
var valid = 0; | ||
var stream = vfs.src('test/fixtures/valid.html') | ||
.pipe(htmlhint()) | ||
.pipe(htmlhint.reporter('htmlhint-stylish')); | ||
stream.on('error', function(err) { | ||
should.not.exist(err); | ||
}); | ||
stream.on('data', function(file) { | ||
should.exist(file); | ||
file.htmlhint.success.should.be.true; | ||
should.exist(file.path); | ||
should.exist(file.relative); | ||
should.exist(file.contents); | ||
++valid; | ||
}); | ||
stream.once('end', function() { | ||
valid.should.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -230,2 +256,26 @@ | ||
}); | ||
it('should not show file errors if suppress option is explicitly set', function(done){ | ||
var error = false; | ||
var stream = vfs.src('test/fixtures/invalid.html') | ||
.pipe(htmlhint()) | ||
.pipe(htmlhint.failReporter({ | ||
suppress: true | ||
})); | ||
stream.on('error', function(err){ | ||
error = true; | ||
gutil.colors.stripColor(err.message).should.containEql('HTMLHint failed.'); | ||
err.name.should.equal('Error'); | ||
done(); | ||
}); | ||
stream.once('end', function() { | ||
error.should.be.true; | ||
done(); | ||
}); | ||
}); | ||
}); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
65730
385
109
5
3