spalger / gulp-jshint

JSHint plugin for gulp
MIT License
419 stars 65 forks source link

JSHint default values not being utilized (must be explicitly set) #141

Closed DerekFoulk closed 8 years ago

DerekFoulk commented 8 years ago

I am using JSHint 2.9.2 (installed globally via NPM) with gulp-jshint 2.0.0.

Here is the relevant task from my Gulpfile.js:

gulp.task('scripts', function() {
    var scriptsSource = gulp.src([
            dir.src + '/js/**/*.js'
        ])
        .pipe( plugins.sourcemaps.init() )
        .pipe( plugins.wrap('\n//<%= file.path %>\n<%= contents %>\n') )
        .pipe( plugins.concat('scripts.js') );

    var scriptsPipe1 = scriptsSource.pipe( plugins.clone() )
        .pipe( plugins.header( banner, { pkg : pkg } ) )
        .pipe( plugins.sourcemaps.write('.') )
        .pipe( gulp.dest( dir.dist + '/js' ) );

    var scriptsPipe2 = scriptsSource.pipe( plugins.clone() )
        .pipe( plugins.rename({
            suffix: '.min'
        }) )
        .pipe( plugins.uglify() )
        .pipe( plugins.header( banner, { pkg : pkg } ) )
        .pipe( plugins.sourcemaps.write('.') )
        .pipe( gulp.dest( dir.dist + '/js' ) );

        return plugins.mergeStream( scriptsPipe1, scriptsPipe2 );
});

Here is my .jshintrc file:

{
    "jquery": true
}

Here is the JS file to be linted:

$(document).ready( function() {
    "use strict";

    var i = 0;

    consuela.log('Welcome to NWCA.com! This site is currently in development, so any activities conducted here will be discarded. Enjoy!');
});

What should happen:

JSHint should detect 2 errors in the code:

src\js\_welcome.js
  line 5  col 9  'i' is defined but never used.
  line 7  col 5  'consuela' is not defined.

  ‼  2 warnings

What actually happens:

No errors are detected, and the gulp build finishes without any JSHint notifications.

How I remedied the issue:

1) Copy the entire example .jshintrc file provided by JSHint 2) Paste those options into a .jshintrc file in my repo's root 3) Change "jquery": false to "jquery": true 4) Run gulp again

The errors in the file are detected after adding all of the default rules to my .jshintrc file.

Basically, it seems that the default options are not used by JSHint unless they are explicitly specified inline or in a .jshintrc file.

Note: I have not confirmed that all options are being overlooked, or if it is just an option that is necessary to detect the errors in my file.

spalger commented 8 years ago

How are you configuring gulp-jshint? I don't see it in the portion of your Gulpfile that you shared.

DerekFoulk commented 8 years ago

@spalger - So sorry, I grabbed the wrong task... Here is my JSHint task:

gulp.task('jshint', function() {
    return gulp.src([
        dir.js + '/**/*.js'
    ])
        .pipe( plugins.jshint() )
        .pipe( plugins.jshint.reporter('jshint-stylish') )
        .pipe( plugins.notify( function (file) {
            if ( file.jshint.success ) {
                // Don't show something if success 
                return false;
            }

            var errors = file.jshint.results.map( function (data) {
                if ( data.error ) {
                    return "(Line " + data.error.line + ' : Col ' + data.error.character + ') ' + data.error.reason;
                }
            }).join('\n');

            return file.relative + " (" + file.jshint.results.length + " errors)\n" + errors;
        }))
        .pipe( plugins.jshint.reporter('fail') );
});
spalger commented 8 years ago

Welp, I'm seeing the same behavior as you originally reported. I'm closing this though because this the also what the CLI does -- my ultimate benchmark is parity with the features of the jshint cli.

Sorry it didn't work as you would expect, but the file you linked must not be the shipping defaults. The comment at the top makes it sound like that, but maybe they just mean it's the default for http://jshint.com/?

reproduction: https://github.com/spalger/reproduce-issues/tree/master/gulp-jshint-141

DerekFoulk commented 8 years ago

If the defaults listed in the sample file may not be the actual defaults, then that would explain this behavior absolutely! Maybe I was just looking at this the wrong way. Thank you for your time. If I come across any further issues with this, I will report the issue on JSHint's tracker instead. Thank you for the quick responses and assistance!