I am new to gulp and so I put a simple script together to 1) learn how gulp works and 2) improve my development workflow.
The issue I am having is that if I set the runSequence task list to be in the order of jscs and then lint, the lint task does not get executed. However, if I reverse them, and run lint first, then jscs, both tasks execute successfully. After doing more tests, I'm certain that there is something about the way I am using jscs that is causing the problem, or there is an issue with jscs that prevents this from executing in this way.
Things I have checked:
- Dependencies have been installed globally.
- Dependencies have been setup in my package.json.
- All of the needed require statements at the top of my gulpfile.js are established.
- Checked that the .jshintrc file that I reference for jshint does in fact exist
- Checked that the .jscsrc file that I reference for jscs does in fact exist
gulpfile.js:
/* File: gulpfile.js */
/* grab the packages we will be using */
var gulp = require('gulp');
var gutil = require('gulp-util');
var jscs = require('gulp-jscs');
var jsHint = require('gulp-jshint');
var jsHintStylish = require('jshint-stylish');
var runSequence = require('run-sequence');
var console = require('better-console');
// configure the default task and add the watch task to it
gulp.task('default', ['watch']);
// configure the jscs task
gulp.task('jscs', function() {
return gulp.src('src/app/**/*.js')
.pipe(jscs('.jscsrc'));
});
// configure the lint task
gulp.task('lint', function() {
return gulp.src("src/app/**/*.js")
.pipe(jsHint('.jshintrc'))
.pipe(jsHint.reporter(jsHintStylish));
});
// configure the watch task - set up which files to watch and what tasks to use when those files change
gulp.task('watch',function() {
// Clear console
console.clear();
// setup a watch against the files that need to be checked on save
gulp.watch('src/app/**/*.js', function(){
// Clear console so only current issues are shown
console.clear();
// Execute tasks to check code for issues
runSequence('lint','jscs',function(){
gutil.log("Code Check Complete.");
});
});
});
package.json:
{
"name": "my project name",
"version": "0.1.0",
"author": {
"name": "my name",
"email": "myemail@domain.com"
},
"devDependencies": {
"better-console": "^0.2.4",
"gulp": "^3.8.11",
"gulp-jscs": "^1.6.0",
"gulp-jshint": "^1.11.0",
"gulp-util": "^3.0.4",
"jshint-stylish": "^1.0.2",
"run-sequence": "^1.1.0"
}
}
JavaScript file in the folder that is being watched. Notice the errors that I placed so that both jscs and lint will report issues:
(function() {
'use strict;
var x = ;
})();
Sample output when the run sequence task ordering is 'lint','jscs',function(){...}
:
[15:10:49] Starting 'lint'...
c:\Users\anatha\My Projects\Tracks\Tracks.Client\src\app\app.js
line 3 col 17 Unclosed string.
line 4 col 1 Unclosed string.
line 5 col 14 Unclosed string.
line 6 col 1 Unclosed string.
line 7 col 6 Unclosed string.
line 8 col 1 Unclosed string.
line 3 col 5 Unclosed string.
line 1 col 13 Missing semicolon.
line 8 col 1 Missing "use strict" statement.
line 1 col 13 Unmatched '{'.
line 1 col 1 Unmatched '('.
line 8 col 1 Expected an assignment or function call and instead saw an expression.
line 8 col 1 Missing semicolon.
× 4 errors
‼ 9 warnings
[15:10:49] Finished 'lint' after 104 ms
[15:10:49] Starting 'jscs'...
[15:10:49] 'jscs' errored after 157 ms
[15:10:49] Error in plugin 'gulp-jscs'
Message:
Unexpected token ILLEGAL at app.js :
1 |(function() {
2 |
3 | 'use strict;
-----------------------^
4 |
5 | var x = ;
[15:10:49] Code Check Complete.
Sample output when the run sequence task ordering is 'jscs','lint',function(){...}
(Notice that the lint statement is never executed):
[15:09:48] Starting 'jscs'...
[15:09:48] 'jscs' errored after 178 ms
[15:09:48] Error in plugin 'gulp-jscs'
Message:
Unexpected token ILLEGAL at app.js :
1 |(function() {
2 |
3 | 'use strict;
-----------------------^
4 |
5 | var x = ;
[15:09:48] Code Check Complete.