All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rules.jshint.W066.html Maven / Gradle / Ivy

Go to download

Consume reports generated by jshint for code quality. Also consume reports for code duplication (either simian or cpd). Consumes the unit/integration tests reports (generated by Jasmin) coverage report (lcov generated by Istanbul). The information generated by reports are added in Sonar

There is a newer version: 2.1.0
Show newest version

    

History

This warning has existed in two forms across the three main linters. It was introduced in the original version of JSLint and has remained in all three tools ever since.

  • In JSLint and JSHint prior to version 1.0.0 the warning given is "Implied eval is evil. Pass a function instead of a string"

  • In JSHint 1.0.0 and above the message used is "Implied eval. Consider passing a function instead of a string"

  • In ESLint the message has always been "Implied eval. Consider passing a function instead of a string"

The situations that produce the warning have not changed despite changes to the text of the warning itself.

When do I get this error?

The "Implied eval is evil. Pass a function instead of a string" error (and the alternative "Implied eval. Consider passing a function instead of a string" error) is thrown when JSLint, JSHint and ESLint encounter a call to setTimeout or setInterval in which the first argument is a string. Here's an example that should pop up a browser alert after one second:

x
 
1
/*jslint browser: true */
2
setTimeout("alert('Hello!');", 1000);
3
JSLint found no errorsVersion 2015-09-23

Why do I get this error?

This error is raised to highlight a bad practice and a possible misunderstanding of the language. By passing a string to setTimeout or setInterval you are adding significant extra work for the engine. It has to parse that string as a complete program, akin to the eval function. For full details of why this is a problem see the article on the related message: "eval is evil".

You can fix this issue by simply passing a function to setTimeout or setInterval instead of a string. In a situation like that of the example above, you can achieve this by passing an anonymous function:

6
 
1
/*jslint browser: true, devel: true */
2
setTimeout(function () {
3
    "use strict";
4
    alert('Hello!');
5
}, 1000);
6
JSLint found no errorsVersion 2015-09-23

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W066. This means you can tell JSHint to not issue this warning with the /*jshint -W066 */ directive.

In ESLint the rule that generates this warning is named no-implied-eval. You can disable it by setting it to 0, or enable it by setting it to 1.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy