gruntjsjshintgrunt-contrib-jshint

grunt jshint config not working


Having trouble setting up jshint options for grunt

Here is my gruntfile.js

grunt.initConfig( {
    jshint : {
        options: { 

            curly: false,
            asi: true,
            eqeqeq: false,
            maxparams: 5,
            undef: false,
            unused: false,
            eqnull: true,
            browser: true,
            devel: true,
            expr: true,
            jquery: true ,
            evil : true 
        },
        files : { 
            src : [ 
                'dev/*.js', 'dev/**/*.js' ,  
                'files-lib/*.js', 'files-lib/**/*.js' ]
        },
    }, 

still getting the errors

71 | return (this.optional(element) && value=="") || re.test(value); ^ Use '===' to compare with ''.

Thanks for helping


Solution

  • short answer: There's nothing else you can do in your options configuration to avoid this.

    longer answer: Although you have the eqeqeq property set to false in your options configuration, (which assumes instances of the double equals == should not throw an error), jshint in this instance I believe is correctly reporting this as an error.

    The value=="" part in the code being validated is what is throwing the error (i.e. it's ignoring the eqeqeq: false option). This is for good reason!

    The == operator will compare for equality after doing any necessary type conversions, which can lead to really quirky results in Javascript. For example:

    0 == ""     // true
    false == "" // true
    

    Whilst I appreciate double equals yields the correct result for many comparison scenarios, this value=="" example is certainly a scenario whereby triple equals should be used, or if you're a double equals only person, then you could replace value=="" with value.length == 0

    Additional info regarding triple equals and double equals operators, and it's various quirks, can be found in the answer to this post