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

rules.jshint.E007.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

    

When do I get this error?

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. Here's an example of a function that does not run in strict mode:

x
 
1
/*jshint strict: true */
2
function example() {
3
    return true;
4
}
5
JSLint found 1 errorVersion 2013-04-29
Line 3:Missing 'use strict' statement.

Why do I get this error?

This error is raised to highlight a lack of convention. However, as JavaScript engines move forward, this error will increasingly be helpful as it should highlight areas of code that may not work as you expect them to, or may even cause fatal JavaScript errors.

A "use strict" statement is an example of a directive, which can appear as the first statement of a program or a function (ES5 §14.1):

A Directive Prologue is the longest sequence of ExpressionStatement productions occurring as the initial SourceElement productions of a Program or FunctionBody and where each ExpressionStatement in the sequence consists entirely of a StringLiteral token followed a semicolon. The semicolon may appear explicitly or may be inserted by automatic semicolon insertion. A Directive Prologue may be an empty sequence.

The "use strict" directive can be used to force the engine to conform to a strict subset of the language, as defined in ES5 Annex C. It has become something of a convention to run all JavaScript code in strict mode, to avoid falling into traps that are apparent in the non-strict language. See the previous link or the corresponding MDN article for the details of the differences in strict mode. You can fix this error by simply adding a "use strict" directive to the function, or to an ancestor function:

6
 
1
/*jshint strict: true */
2
function example() {
3
    "use strict";
4
    return true;
5
}
6
JSLint found no errorsVersion 2013-04-29

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. This message is treated as an error by JSHint which means you are unable to prevent it from being issued by ID.

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy