Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable warnings about 'this' and strict mode using JSHint?

I am writing a web app using AngularJS (v1.5) so I have some controllers, and in those controllers I am often declaring something like :

function myController($someDirectives, ...){
    var ctrl = this;
    // My code
}

The thing is when I JSHint my code, I get this warning message for all of my 'this' declared in controllers :

If a strict mode function is executed using function invocation, its 'this' value will be undefined.

I must precise that in my .jshintrc file, I set "strict":false. Does anyone know how to disable this message in particular?

Thanks in advance.

like image 505
NathanL Avatar asked Feb 20 '17 15:02

NathanL


People also ask

How do I ignore Jshint warning?

In October 2013 jshint added a way to ignore blocks of code like this: // Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */ // Code here will be linted with JSHint. Show activity on this post. Show activity on this post.

What does missing use strict statement mean?

The "Missing 'use strict' statement" error is thrown when JSLint, JSHint and ESLint encounter a function that does not contain the strict mode directive, and none of whose ancestor scopes contain the strict mode directive. JSHint will only raise this warning if the strict option is set to true .

What is Jshint library?

JSHint is a program that flags suspicious usage in programs written in JavaScript. The core project consists of a library itself as well as a CLI program distributed as a Node module.


2 Answers

set the configuration in .jshintrc file

{
  "validthis": true // Tolerate using this in a non-constructor 
}
like image 189
Parwat Kunwar Avatar answered Oct 11 '22 13:10

Parwat Kunwar


You can always override jshint options in the code-block ie.

/* jshint validthis: true */
like image 27
Cmag Avatar answered Oct 11 '22 13:10

Cmag