Custom formatter #29

Merged
merged 2 commits into from Aug 11, 2016

Projects

None yet

4 participants

@SimenB
Contributor
SimenB commented May 28, 2015

This PR adds the ability to register custom reporters (or formatters as they're called in CSSLint). I'll add tests and documentation soon (in the next couple of days).
This drops support for custom formatter/reporter that's not a valid CSSLint formatter.
Breakage galore!

This allows us to use for instance https://github.com/SimenB/csslint-stylish with this plugin.

Usage:

var csslint = require('gulp-csslint');

csslint.addFormatter('csslint-stylish');  // Change to reporter?

gulp.task('lint', function() {
  gulp.files('lib/*.css')
    .pipe(csslint())
    .pipe(csslint.reporter('csslint-stylish'))
});

Formatters also takes options, which is an object passed as a second param to reporter.

@SimenB SimenB referenced this pull request May 28, 2015
Merged

Built in formatters #21

@coveralls

Coverage Status

Coverage increased (+11.5%) to 77.63% when pulling cfbdf20 on SimenB:custom-formatter into c8e3464 on lazd:master.

@lazd
Owner
lazd commented Aug 17, 2015

@SimenB is this still relevant?

@SimenB
Contributor
SimenB commented Aug 17, 2015

@lazd Documentation added, just needs a test or two now 😄

@SimenB SimenB referenced this pull request Sep 10, 2015
Closed

What is wrong with v0.2.0? #35

@lazd lazd and 1 other commented on an outdated diff Sep 13, 2015
});
```
+You can also provide an object with the following contract to implement your own reporter:
+
+```js
+{
+ id: 'string', // Name passed to csslint.reporter
+ startFormat: function() {}, // Called before parsing any files, should return a string
+ startFormat: function() {}, // Called after parsing all files, should return a string
+ formatResult: function (results, filename, options) {} // Called with a results-object per file linted. Optionally called with a filename, and options passed to csslint.reporter(*reporter*, *options*)
+}
+```
@lazd
lazd Sep 13, 2015 Owner

If this is mentioned in the CSSLint docs, let's link to it.

@SimenB
SimenB Sep 13, 2015 Contributor

I can't find it explicitly stated, this is just pulled out from my understanding after looking at all of the existing formatters: https://github.com/CSSLint/csslint/tree/master/src/formatters

@lazd
Owner
lazd commented Sep 13, 2015

Looking good, let me know when this one is ready for merge!

@SimenB
Contributor
SimenB commented Sep 13, 2015

I'm going to rewrite this to mimic gulp-jshint's approach with trying to require it if it's not found.

@lazd
Owner
lazd commented Sep 13, 2015

Sounds like a plan, thanks @SimenB!

@obuckley-kenzan

This seems like a great feature @SimenB! Any updates available on this?

@SimenB
Contributor
SimenB commented Nov 14, 2015

I've been super busy the last couple of months, so I haven't gotten around to getting this done. It should work as is, though (so you can install it using npm install simenb/gulp-csslint#custom-formatter).

Missing is that I'd like for it to more closely match gulp-jshint as mentioned. This means taking both an object, string or function, not just string

@coveralls

Coverage Status

Coverage decreased (-3.5%) to 81.034% when pulling 572ddfe on SimenB:custom-formatter into 1a2ccb9 on lazd:master.

@coveralls
coveralls commented May 11, 2016 edited

Coverage Status

Coverage decreased (-3.5%) to 81.034% when pulling aa85d1a on SimenB:custom-formatter into 1350804 on lazd:master.

@SimenB SimenB Rename `reporter` to `formatter` to match CSSLint
17d99d6
@SimenB
Contributor
SimenB commented Jul 22, 2016 edited

I'll try to wrap this up this coming week. Includes #53 for now 😄 I think this just misses tests and docs now

@coveralls
coveralls commented Jul 22, 2016 edited

Coverage Status

Coverage decreased (-9.1%) to 75.385% when pulling 5506fd0 on SimenB:custom-formatter into 15e16e0 on lazd:master.

@coveralls
coveralls commented Jul 23, 2016 edited

Coverage Status

Coverage decreased (-10.5%) to 73.973% when pulling 1f88319 on SimenB:custom-formatter into 15e16e0 on lazd:master.

@lazd
Owner
lazd commented Jul 23, 2016

@SimenB sweet! Looking forward to it :D

@SimenB
Contributor
SimenB commented Jul 29, 2016 edited

@lazd Tests added, should finally be good to go! Only took 14 months...
I recommend merging #53 separately to easier review this PR 😄

@coveralls
coveralls commented Jul 29, 2016 edited

Coverage Status

Coverage increased (+12.8%) to 97.297% when pulling 42efb9a on SimenB:custom-formatter into 15e16e0 on lazd:master.

@coveralls
coveralls commented Jul 29, 2016 edited

Coverage Status

Coverage increased (+12.8%) to 97.297% when pulling 7c25bbf on SimenB:custom-formatter into 15e16e0 on lazd:master.

@coveralls
coveralls commented Jul 29, 2016 edited

Coverage Status

Coverage increased (+12.8%) to 97.297% when pulling 7c25bbf on SimenB:custom-formatter into 15e16e0 on lazd:master.

@SimenB SimenB commented on the diff Jul 30, 2016
test/main.js
+ }
+ });
+
+ it('should throw on unknown parameter', function(done) {
+ try {
+ cssLintPlugin.formatter(true);
+ }
+ catch (e) {
+ e.message.should.equal('Invalid custom formatter passed, please pass `null` or `undefined` if you want to pass options while using default formatter.');
+ done();
+ }
+ });
+ });
+
+ describe('cssLintPlugin.addFormatter()', function() {
+ afterEach(function() {
@SimenB
SimenB Jul 30, 2016 Contributor

A bit hackish, but I need to reset some global state in csslint

@SimenB SimenB Allow registering custom formatter
16f810f
@coveralls
coveralls commented Jul 30, 2016 edited

Coverage Status

Coverage increased (+12.8%) to 97.297% when pulling 16f810f on SimenB:custom-formatter into 15e16e0 on lazd:master.

@SimenB
Contributor
SimenB commented Aug 11, 2016

@lazd ping

@lazd lazd merged commit 3cfacb3 into lazd:master Aug 11, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+12.8%) to 97.297%
Details
@lazd
Owner
lazd commented Aug 11, 2016

Awesome stuff, thanks @SimenB!

What else are we waiting on for 1.0?

@SimenB SimenB deleted the SimenB:custom-formatter branch Aug 11, 2016
@SimenB
Contributor
SimenB commented Aug 11, 2016

@lazd only thing is the two dep updating PRs, IMO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment