-
Notifications
You must be signed in to change notification settings - Fork 11
Automatically lookup .ccslintrc #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Auto detect text files and perform LF normalization | ||
| * text=auto |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| /node_modules | ||
| /*.log | ||
| .idea/ | ||
| *.iml | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are workstation-specific files that should be in your global
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, I can see that one. or |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,12 @@ gulp.task('css', function() { | |
| #### ruleConfiguration | ||
| Type: `Object` | ||
|
|
||
| If you pass `lookup: false`, the local .csslintrc is not looked up automatically. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that, if there is ever a CSSLint property called
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
|
@@ -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' }); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see |
||
|
|
||
| // 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]; | ||
| } | ||
| } | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we lose support for passing a rules configuration to the plugin as documented here. |
||
| 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); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "vendor-prefix": false | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* properties using important */ | ||
| .mybox { | ||
| border: 1px solid black !important; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Options should still work |
||
| }); | ||
| stream.on('data', function(newFile) { | ||
| ++a; | ||
|
|
@@ -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); | ||
|
|
||
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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...