0

When I run "gulp style" from the command line, Gulp runs, and, subsequently, gulp-jscs runs, but the latter seems to be unable to detect the rules defined in the jscs config file (.jscsrc). But, if I run jscs from the command line, then jscs does detect the config file's rules. Any idea what the deal could be?

Here's my gulp file:

(function() {
    "use strict";

    var gulp = require("gulp");
    var jshint = require("gulp-jshint");
    var jscs = require("gulp-jscs");
    var jsFiles = ["*.js", "src/**/*.js"];

    gulp.task("style", function () {
        console.log("Running the style task.");
        return gulp.src(jsFiles)
            .pipe(jshint())
            .pipe(jshint.reporter("jshint-stylish", {
                verbose: true
            }))
            .pipe(jscs({configPath: "./.jscsrc"}));
    });
})();
Michael P.
  • 1,373
  • 3
  • 12
  • 33
  • ```'use strict'``` is not needed in ```node.js``` environment.Can you show us ```.jscsrc```? – edin-m Dec 25 '15 at 10:53

1 Answers1

2

You need a reporter (just like jshint has one):

var gulp = require("gulp");
var jshint = require("gulp-jshint");
var jscs = require("gulp-jscs");
var jsFiles = ["*.js", "src/**/*.js"];

gulp.task("style", function () {
    console.log("Running the style task.");
    return gulp.src(jsFiles)
        .pipe(jshint())
        .pipe(jshint.reporter("jshint-stylish", {
            verbose: true
        }))
        .pipe(jscs({configPath: "./.jscsrc"}))
        .pipe(jscs.reporter()); // << this line here
});

Other notes, (if you are running from cmd), Gulpfile.js you don't need to wrap it into anonymous function or use 'use strict'.

Example output:

[13:53:30] Using gulpfile C:\del\so\gulpjscs\Gulpfile.js
[13:53:30] Starting 'style'...
Running the style task.
[13:53:31] gulp-debug: Gulpfile.js
[13:53:31] gulp-debug: index.js
[13:53:31] gulp-debug: 2 items
Comments must start with a lowercase letter at C:\del\so\gulpjscs\index.js :
     1 |// Invalid
--------^
     2 |// valid
     3 |


1 code style error found.
[13:53:31] Finished 'style' after 187 ms

If you're not sure how will current path ./ be taken into account you can always use path module to resolve, for example:

var path = require('path');
var configPath = path.resolve(path.join(__dirname, '.jscsrc'))
edin-m
  • 3,021
  • 3
  • 17
  • 27
  • You are correct: it really just came down to piping the output to a jscs.reporter(). Thank you! As for the path-related stuff--I'm content to just not specify a path and thus to allow it to pick up the nearest .jscsrc, which happens in this case to be located in the root of my project's directory. As for the "use strict" rule--I added that because JSHint was griping about it. I don't know how to tell it to ignore certain files. – Michael P. Dec 26 '15 at 15:00
  • Glad to help. It's probably possible, take a look at [docs](http://jshint.com/docs/); Probably ```"node": true``` but I am not sure. – edin-m Dec 26 '15 at 15:03
  • Yes, I figured it out, I think. The path of least resistance seems to be placing the gulpfile's contents between the following comments: /* jshint ignore:start */ and /* jshint ignore:end */. – Michael P. Dec 26 '15 at 15:04