Skip to content

Commit

Permalink
Merge pull request #42 from betaorbust/master
Browse files Browse the repository at this point in the history
Fix cross-file options leak bug
  • Loading branch information
lazd committed Feb 28, 2016
2 parents d1532ec + a520c74 commit 5f7ab61
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,17 @@ var formatOutput = function(report, file, options) {

var cssLintPlugin = function(options) {
options = options || {};

var ruleset = {};

var rcLoader = new RcLoader('.csslintrc', options, { loader: 'async' });

// Build a list of all available rules
csslint.getRules().forEach(function(rule) {
ruleset[rule.id] = 1;
});

return through.obj(function(file, enc, cb) {
if (file.isNull()) return cb(null, file); // pass along
if (file.isStream()) return cb(new gutil.PluginError('gulp-csslint: Streaming not supported'), file);

var ruleset = {};
// Build a list of all available rules
csslint.getRules().forEach(function(rule) {
ruleset[rule.id] = 1;
});

var content = file.contents.toString(enc);

if (!content) return cb(null, file); // pass along
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/leaktest1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*csslint duplicate-properties:false*/
.no-leak-1{
height: 42px;
width: 20px;
height: 21px;
}
5 changes: 5 additions & 0 deletions test/fixtures/leaktest2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.no-leak-2{
height: 42px;
width: 20px;
height: 21px;
}
23 changes: 23 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ describe('gulp-csslint', function() {
stream.end();
});

it('should not leak options across files', function(done) {
var failedFiles = 0;
var file1 = getFile('fixtures/leaktest1.css');
var file2 = getFile('fixtures/leaktest2.css');
var stream = cssLintPlugin({});

stream.on('data', function(newFile) {
should.exist(newFile.csslint.success);
if (!newFile.csslint.success) {
failedFiles++;
}
});

stream.once('end', function() {
failedFiles.should.equal(1);
done();
});

stream.write(file1);
stream.write(file2);
stream.end();
});

it('should support options', function(done) {
var a = 0;

Expand Down

0 comments on commit 5f7ab61

Please sign in to comment.