Skip to content

Commit a520c74

Browse files
committed
Fix cross-file option leaks.
1 parent d1532ec commit a520c74

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,17 @@ var formatOutput = function(report, file, options) {
3333

3434
var cssLintPlugin = function(options) {
3535
options = options || {};
36-
37-
var ruleset = {};
38-
3936
var rcLoader = new RcLoader('.csslintrc', options, { loader: 'async' });
40-
41-
// Build a list of all available rules
42-
csslint.getRules().forEach(function(rule) {
43-
ruleset[rule.id] = 1;
44-
});
45-
4637
return through.obj(function(file, enc, cb) {
4738
if (file.isNull()) return cb(null, file); // pass along
4839
if (file.isStream()) return cb(new gutil.PluginError('gulp-csslint: Streaming not supported'), file);
4940

41+
var ruleset = {};
42+
// Build a list of all available rules
43+
csslint.getRules().forEach(function(rule) {
44+
ruleset[rule.id] = 1;
45+
});
46+
5047
var content = file.contents.toString(enc);
5148

5249
if (!content) return cb(null, file); // pass along

test/fixtures/leaktest1.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*csslint duplicate-properties:false*/
2+
.no-leak-1{
3+
height: 42px;
4+
width: 20px;
5+
height: 21px;
6+
}

test/fixtures/leaktest2.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.no-leak-2{
2+
height: 42px;
3+
width: 20px;
4+
height: 21px;
5+
}

test/main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,29 @@ describe('gulp-csslint', function() {
113113
stream.end();
114114
});
115115

116+
it('should not leak options across files', function(done) {
117+
var failedFiles = 0;
118+
var file1 = getFile('fixtures/leaktest1.css');
119+
var file2 = getFile('fixtures/leaktest2.css');
120+
var stream = cssLintPlugin({});
121+
122+
stream.on('data', function(newFile) {
123+
should.exist(newFile.csslint.success);
124+
if (!newFile.csslint.success) {
125+
failedFiles++;
126+
}
127+
});
128+
129+
stream.once('end', function() {
130+
failedFiles.should.equal(1);
131+
done();
132+
});
133+
134+
stream.write(file1);
135+
stream.write(file2);
136+
stream.end();
137+
});
138+
116139
it('should support options', function(done) {
117140
var a = 0;
118141

0 commit comments

Comments
 (0)