Comments (11)
What gulp-watch version are you using? There are huge differences between 2.x, 3.x and 4.x.
from gulp-jscs.
"devDependencies": {
"gulp": "^3.8.10",
"gulp-jscs": "^1.4.0",
"gulp-jshint": "^1.9.0",
"gulp-watch": "^4.1.0",
"jshint-stylish": "^1.0.0",
"lazypipe": "^0.2.2"
}
from gulp-jscs.
Currently, gulp-jscs only emits errors when the readable stream that is being piped into it ends, and your code is using gulp-watch's "endless stream" mode. I believe the callback mode is more suited for your needs:
gulp.task('watch', function() {
return watch(paths.scripts, function(files) {
files
.pipe(jscsRunner)
.pipe(jshintRunner)
.pipe(jshint.reporter('default'));
});
});
from gulp-jscs.
@UltCombo Sounds good, but unfortunately doesn't work.
I think that is because files
(file
, really, in the callback there only ever is exactly one) is not a stream of vinyl
objects, it's a single object. However, jscs expects a stream and crashes when it gets a file.
from gulp-jscs.
Oh I see, my bad. I thought the argument was still a stream (as it was in 3.x) because in my real use cases I still use gulp-batch (which used to be part of gulp-watch prior to v4.x, and now must be explicitly included):
var batch = require('gulp-batch');
gulp.task('watch', function() {
return watch(paths.scripts, batch(function(files) {
return files
.pipe(jscsRunner)
.pipe(jshintRunner)
.pipe(jshint.reporter('default'));
}));
});
I've hastily adapted this code removing gulp-batch for the previous comment without knowing that the argument type has changed. The code with gulp-batch should work though. There are cleaner ways around this, of course -- I'll post one when I get home.
from gulp-jscs.
I'll wait. I've tried (and failed) to construct a single-object readable stream from the file, but my node experience so far is rather limited.
from gulp-jscs.
You can use stream-array (or event-stream's readArray
) to make things easier:
var streamify = require('stream-array');
gulp.task('watch', function() {
return watch(paths.scripts, function(file) {
streamify([file])
.pipe(jscsRunner)
.pipe(jshintRunner)
.pipe(jshint.reporter('default'));
});
});
from gulp-jscs.
Now we're getting somewhere.
Your suggestion still isn't complete, though. jscs throws errors when it finds style violations and these errors need to be handled or gulp will crash.
Here is what I use now.
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var watch = require('gulp-watch');
var lazypipe = require('lazypipe');
var streamify = require('stream-array');
var paths = {
scripts: ['./js/*.js']
};
var lintTasks = lazypipe()
.pipe(jshint, {
// ...
})
.pipe(jshint.reporter, 'jshint-stylish');
var jscsTasks = lazypipe()
.pipe(jscs, {
// ...
});
gulp.task('watch', function() {
return watch(paths.scripts, function(file) {
streamify([file])
.pipe(jscsTasks())
.on('error', function (error) {
console.log(error.toString());
})
.emit('end');
})
.pipe(lintTasks());
});
from gulp-jscs.
Oh yes, that's another detail I forgot -- gulp-batch wraps the callback in a domain so the error handler wouldn't be necessary if you were using gulp-batch.
Also should note that you won't need to use the callback style nor catch errors after #66 is merged.
from gulp-jscs.
Correction: if you were using gulp-batch the error would be suppressed by default, you'd need to supply an error handle to gulp-batch in order to log the error message as well.
from gulp-jscs.
Nice. For the moment I have something that works and I'll follow #66.
from gulp-jscs.
Related Issues (20)
- Incompatibility with harmony-reflect HOT 1
- Support values other than true/false HOT 1
- Stop .pipe() chain on linting error?
- Unclear error when .jscsrc is missing HOT 5
- Cannot read property 'tokTypes' of undefined - urgent
- Allow indented "break" in "switch" statement. HOT 2
- install broken due to downstream dependency left-pad being unpublished HOT 2
- JSCS errors getting swallowed somewhere HOT 6
- Cannot convert undefined or null to object HOT 5
- Update to JSCS 3.0 HOT 1
- file.jscs.errors is an object not an array
- How can I use fix:true with a watch?
- JSCS reporter compatibility HOT 2
- JSCS unreasonably complain about the beginning of a js file HOT 1
- Integration with Sonar rules
- jscs domain has expired
- editorconfig + jscs
- Replace deprecated dependency gulp-util
- Linting solution incompatible with 'engines' field in package.json
- TypeError: Cannot convert undefined or null to object at Function.keys HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-jscs.