gulpjshintjscsgulp-jscsgulp-jshint

How to get gulp-jshint to ignore folders


I have the following folder structure within a solution that I have inherited

.\gulp.config.js
.\gulpfile.js
.\.jscsrc
.\.jshintrc
.\default.js
.\Resources\js\main.js
.\Resources\js\modules\   various user created js files
.\Resources\js\vendor\    various js files i.e jQuery

I have installed gulp-jscs and gulp-jshint.

The .jscsrc I have taken from https://github.com/johnpapa/pluralsight-gulp/blob/master/.jscsrc.

I have the following within gulpfile.js:

'use strict'

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');

gulp.task('verifyJS',function(){
    gulp.src([
        './Resources/**/*.js',
        './*.js'
    ])
    .pipe(jscs())
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish', { verbose: true }));
});

I am trying to update the excludeFiles within .jscsrc to exclude the following:

.\default.js 
.\resources\js\vendor

This is what I have tried:

 "excludeFiles": [
     "node_modules/**",
     "bower_components/**",
     "Resources/js/vendor/**", // vendor supplied files. ie jQuery
     "./Resources/js/vendor/**", 
     "default.js", 
     "/default.js", 
     "./default.js", 
 ],

I have included all the combinations that I have tried.

But when i run gulp verifyJS it is still including the files that I want to exclude.

How do I correctly set excludeFiles to exclude the file within the root of the project and the subfolder with all subsequent files and folders?


Solution

  • gulp-jshint doesn't care what's in your .jscsrc since that is the config file for gulp-jscs. You need a .jshintignore file instead.

    Here's how to ignore your vendor files in both gulp-jscs and gulp-jshint:

    .jscsrc

    "excludeFiles": [
      "node_modules/**",
      "bower_components/**",
      "Resources/js/vendor/**",
      "default.js", 
    ],
    

    .jshintignore

    node_modules/**
    bower_components/**
    Resources/js/vendor/**
    default.js
    

    gulpfile.js

    gulp.task('verifyJS', function(){
      return gulp.src([
        './Resources/**/*.js',
        './*.js'
      ])
      .pipe(jscs())
      .pipe(jscs.reporter()) // you forgot this
      .pipe(jshint())
      .pipe(jshint.reporter('jshint-stylish', { verbose: true }));
    });