EzDevInfo.com

jshint

JSHint is a tool that helps to detect errors and potential problems in your JavaScript code JSHint, a JavaScript Code Quality Tool

Is there a way to suppress JSHint warning for one given line?

I have a (single) case in my app were eval is used, and I would like to suppress JSHint warning only for this case.

Is there a way to achieve that? Configuration, magic comment, ...?


Source: (StackOverflow)

Repress "mixed spaces and tabs" warning in JSHint / JSLint or alternative service?

JSHint and JSLint are awesome tools.

However, the "mixed spaces and tabs" warning dominates the report. Is there a way to repress suppress these warnings, or is there a similar service that allows white space warnings to get supressed?


Source: (StackOverflow)

Advertisements

Turning off eslint rule for a specific line

In order to turn off linting rule for a particular line in JSHint we use the following rule:

/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */

I have been trying to locate the equivalent of the above for eslint. I didn't find it in eslint docs or by googling it.

I know that turning off the "capIsNew" flag will work in my case, but I don't want to turn the option off at project level.


Source: (StackOverflow)

grunt-contrib-jshint ignores has no effect

I would like to exclude libs directory from being lint'ed. However, ignores in options and planted .jshintignore file in project directory won't make libs to be excluded.

 jshint: {
  options: {
    smarttabs: true,
    ignores: ['public/js/libs/**/*.js']
  },

  all: [
        'Gruntfile.js', 
        'public/js/**/*.js'
      ]

},

grunt version:

 grunt-cli v0.1.11
 grunt v0.4.2
 grunt-contrib-jshint@0.7.2

What did I miss out?


Source: (StackOverflow)

JSHint strict mode and JQuery: '$' is not defined

The following JS:

(function() {
  "use strict";

  $("#target").click(function(){
    console.log("clicked");
  });

}());

Yields:

test.js: line 5, col 3, '$' is not defined.

When executed via JSHINT 0.5.5. Any ideas?


Source: (StackOverflow)

How to disable the warning 'define' is not defined using JSHint and RequireJS

I uses RequireJS AMD in my project. When i run jshint on my project, it throws error like

In AMD Scripts

 'define' is not defined.

In Mocha test cases

 'describe' is not defined.
 'it' is not defined.

How to remove this warning in jshint?


Source: (StackOverflow)

Ignore camelcase variable in JSHint

Having a bit of an issue with JShint and the following line of code.

$location.path('map-' + map.id + '/venue-' + map.attributes.default_venue.value);

I'm getting the error, Identifier 'default_venue' is not in camel case. This wouldn't be a problem normally but I don't have any control over the variable name - it's brought in via a JSON API.

Is there any way I could suppress this issue for either the affected variables or on the lines in which they appear?

Apologies if this has been asked before, I'm pretty sure it must have been but I can't find a solution.


Source: (StackOverflow)

Explanation of JSHint's Bad line breaking before '+' error

Can someone explain to me why JSHint complains about the following,

window.location.href = String1
    + '#'
    + Sting2
    + '='
    + String3;

With the error, Bad line breaking before '+' error

I understand that this error can be configured with the laxbreak option, which is described as

This option suppresses most of the warnings about possibly unsafe line breakings in your code. It doesn't suppress warnings about comma-first coding style. To suppress those you have to use laxcomma (see below).

This explanation is pretty terse and I am curious about why breaking lines this way is considered bad or lax in the first place.

Keep in mind I am not trying to start a holy war here, I am just looking for an objective answer about why the JSHint folks think this is bad, whether it is just a style preference they are injecting into their linter (I thought JSLint was the opinionated linter), or if there is something that can go wrong on certain interpreters when line breaking this way.


Source: (StackOverflow)

Should I use JSLint or JSHint JavaScript validation?

I am currently validating my JavaScript against JSLint and making progress on, it's assisting me to write better JavaScript - in particular in working with the JQuery library.

I have now come across JSHint, a fork of JSLint.
So I am wondering for web applications, which are very much JavaScript driven, which is the better or most applicable validation tool to work against :

  • JSLint or JSHint?

I want to decide now on a validation mechanism and moving forward, use this for client side validation.

And Difference between jshint and jslint? Please explain in single javascript example.

Links:

  1. jshint- http://www.jshint.com/

  2. jslint- http://jslint.com/


Source: (StackOverflow)

JSHint (r10): 'angular' is not defined

I have the following:

angular.module('test')
    .controller('TestMenuController',
    [
        '$http',
        '$scope',
        '$resource',
        '$state',
        'os',
        'us',
    function (
        $http,
        $scope,
        $resource,
        $state,
        os,
        us) {

When I build this in VS2014 it gives me an error message saying:

JSHint (r10): 'angular' is not defined. 

Can someone tell me how I can avoid this message coming up?


Source: (StackOverflow)

JSHint Gulp to error window VS2015

How can I get the output from JSHint to show up in my Error List in Visual Studio 2015 when using Gulp, rather than just output to the Task Runner?

I've tried this package but that doesn't seem to do anything except format the Gulp output slightly differently.

This is my gulpfile.js:

gulp.task('default', function () {
    gulp.src(["Scripts/**/*.js"])
        .pipe(jshint(".jshintrc"))
        .pipe(jshint.reporter("jshint-visual-studio"));
});

Actual output (in Task Runner Window):

Actual output

Preferred output (in Error List):

Preferred output

Please Note: I'm using Visual Studio 2015, so Web Essentials is no longer an option for JSHint as the functionality has been removed.


Source: (StackOverflow)

Expressions in JavaScript Ternary Operator and JSLint

I recently received a comment on one of my blog posts about JSLint asking why JSLint threw an error with the following:

s === "test" ? MyFunc() : MyFunc2();

The error generated was:

"Expected an assignment or function call and instead saw an expression."

Clearly JSLint is expecting an assignment here, somthing more like:

var y = (s === "test") ? MyFunc() : MyFunc2();

But, I don't really see the problem with the first example. Is it really the case that ternary operators should only be used for assignments?

I couldn't see anything on JSLint.com, nor was there anything apparent in the book JavaScript: The Good Parts. And, the same error is also reported in the community fork JSHint.

Anyone?


Source: (StackOverflow)

jshint expects the new 'prefix' for functions

CSiginIn, CSignUp, CTryIt, CBlocks are all functions declared as such

function CSignIn(){//stuff here}

yet JSHint says that I am missing the 'new' 'prefix'. What can I do to fix this?

They are just functions inside the module pattern. Also, it is asking me to remove semicolons I had placed at the end of the function which I have done.

var Control = ( function () 
{

    /**
     *Publik
     */

    var publik = function ( page )
    {
        // page 1 initialization

        if( page == 1 )
        {
            CSignIn();
            CSignUp();
            CTryIt();
            CBlocks();
        }

Function Example...

function CTryIt()
{
    // pull elements

    var tryit_button = document.getElementById( 'tryit_button' );

    // initialize access to Model

    tryit_button.addEventListener( "click", function( )
    { 
        new AjaxRequest().invoke( 'ajax_type=ControlTryIt', 
        function( server_response_text ) 
        { 
            new AjaxResponse( server_response_text, 'page_change' ); 
        } ); 

    }, false );
}

Source: (StackOverflow)

Does anyone knows another way to tell JSLint / JSHint what global variables are already defined

In my project we have some global variables that work as containers:

MyProject.MyFreature.someFunction = function() { ... }

So then I use that script across the site and JSLint / JSHint complains about that:

'MyProject' is not defined

I know that I can go to every JS file and add the comment /*global MyProject*/ on top of it. But I'm looking a way to define that comment in some sort of config file so I don't have to go file by file adding this comment.

Some kind on option in the config/jshint.yml would be nice.


Source: (StackOverflow)

Why does JSHint argue against bitwise operators? How should I express this code?

I am using this bit of JavaScript to generate a UID:

(original:)

//If ID has not been defined then generate a new unique ID.
if(!id){
    id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); });
}

(formatted so it can be read:)

// If ID has not been defined then generate a new unique ID.
if (!id) {
    id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
        /[xy]/g, 
        function (c) { 
            var r = Math.random() * 16 | 0, 
                v = c == 'x' ? r : (r & 0x3 | 0x8); 
            return v.toString(16); 
        }
    );
}

JSHint does not like the use of bitwise OR and AND operators. I was wondering how I could rewrite this to be more 'standard friendly.'

EDIT: JSHint states:

Line 8: id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); Unexpected use of '|'.

Line 8: id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); Expected '===' and instead saw '=='.

Line 8: id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); Unexpected use of '&'.

Line 8: id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); Unexpected use of '|'.


Source: (StackOverflow)