Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, most people blow away that whitespace and it makes me sad :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's why I usually add it to PRs when making them. IDEs really enjoy strpping that whitespace...

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
/*.log
.idea/
*.iml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are workstation-specific files that should be in your global .gitignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like global ignores (the fact they're not supported out of the box is telling to me), but I can remove the change, no problem

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not hurting anything, so don't worry about it. I generally use that canned comment for when people add .DS_Store to my .gitignore ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I can see that one. or thumbs.db or whatever the Windows ones are called

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ gulp.task('css', function() {
#### ruleConfiguration
Type: `Object`

If you pass `lookup: false`, the local .csslintrc is not looked up automatically.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that, if there is ever a CSSLint property called lookup, we'll have a problem...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't currently have one, so I'm not too worried: https://github.com/CSSLint/csslint/wiki/Rules-by-ID

However, we could prefix it with an underscore or accept false as a second argument to avoid lookup... Thoughts?


You can pass rule configuration as an object. See the [list of rules by ID on the CSSLint wiki](https://github.com/stubbornella/csslint/wiki/Rules-by-ID) for valid rule IDs.

Any properties passed wil be in _addition_ to (or overwriting) the ones in .csslintrc (unless `lookup: false` is passed).

```javascript
gulp.src('client/css/*.css')
.pipe(csslint({
Expand Down
52 changes: 26 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

var gutil = require('gulp-util');
var c = gutil.colors;
var error = gutil.PluginError;
var es = require('event-stream');
var fs = require('fs');
var csslint = require('csslint').CSSLint;
var RcLoader = require('rcloader');

var formatOutput = function(report, file, options) {
if (!report.messages.length) {
Expand Down Expand Up @@ -40,41 +42,39 @@ var cssLintPlugin = function(options) {

var ruleset = {};

// Read CSSLint options from a specified csslintrc file.
if (typeof options === 'string') {
// Don't catch readFile errors, let them bubble up
var externalOptions = fs.readFileSync('./'+options);

try {
options = JSON.parse(externalOptions);
}
catch(err) {
throw new Error('Error parsing csslintrc: '+err);
}
}
var rcLoader = new RcLoader('.csslintrc', options, { loader: 'async' });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see options is passed to RcLoader here, nice.


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

for (var rule in options) {
if (!options[rule]) {
// Remove rules that are turned off
delete ruleset[rule];
}
else {
ruleset[rule] = options[rule];
}
}

return es.map(function(file, cb) {
var report = csslint.verify(String(file.contents), ruleset);
if (file.isNull()) return cb(null, file); // pass along
if (file.isStream()) return cb(new error('gulp-csslint: Streaming not supported'));

rcLoader.for(file.path, function (err, opts) {
if (err) return cb(err);

var str = file.contents.toString('utf8');

for (var rule in opts) {
if (!opts[rule]) {
// Remove rules that are turned off
delete ruleset[rule];
}
else {
ruleset[rule] = opts[rule];
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var report = csslint.verify(str, ruleset);

// send status down-stream
file.csslint = formatOutput(report, file, options);
// send status down-stream
file.csslint = formatOutput(report, file, ruleset);

cb(null, file);
cb(null, file);
});
});
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dependencies": {
"csslint": "^0.10.0",
"event-stream": "^3.3.0",
"gulp-util": "^3.0.4"
"gulp-util": "^3.0.4",
"rcloader": "^0.1.4"
},
"devDependencies": {
"mocha": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion test/csslintrc.json → test/.csslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"vendor-prefix": false
}
}
4 changes: 4 additions & 0 deletions test/fixtures/usingImportant.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* properties using important */
.mybox {
border: 1px solid black !important;
}
28 changes: 25 additions & 3 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ describe('gulp-csslint', function() {
it('should support options', function(done) {
var a = 0;

var file = getFile('fixtures/missingPrefixes.css');
var file = getFile('fixtures/usingImportant.css');

var stream = cssLintPlugin({
'vendor-prefix': false
important: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options should still work

});
stream.on('data', function(newFile) {
++a;
Expand All @@ -135,7 +135,29 @@ describe('gulp-csslint', function() {

var file = getFile('fixtures/missingPrefixes.css');

var stream = cssLintPlugin('test/csslintrc.json');
var stream = cssLintPlugin('test/.csslintrc');
stream.on('data', function(newFile) {
++a;
should.exist(newFile.csslint.success);
newFile.csslint.success.should.equal(true);
should.not.exist(newFile.csslint.results);
should.not.exist(newFile.csslint.opt);
});
stream.once('end', function() {
a.should.equal(1);
done();
});

stream.write(file);
stream.end();
});

it('should find csslintrc automatically', function(done) {
var a = 0;

var file = getFile('fixtures/missingPrefixes.css');

var stream = cssLintPlugin();
stream.on('data', function(newFile) {
++a;
should.exist(newFile.csslint.success);
Expand Down