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

rules.jshint.W034.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 "Unnecessary 'use strict'" error (and the alternative "Unnecessary directive '{a}'" error) is thrown when JSLint, JSHint or ESLint encounters a "use strict" directive in code that is already running in strict mode. The following example features a factory function that runs in strict mode and returns another function that has its own strict mode directive:

x
 
1
function factory() {
2
    "use strict";
3
    return function () {
4
        "use strict";
5
        return true;
6
    };
7
}
8
JSLint found 1 errorVersion 2015-09-23
Line 3:Unexpected expression 'use strict' in statement position.

Why do I get this error?

This error is raised to highlight a completely pointless piece of code. The "use strict" directive applies to the scope in which it appears, and any descendant execution contexts. Here's what the ECMAScript 5 specification tells us about strict mode and functions (ES5 §10.1.1):

Function code that is part of a FunctionDeclaration, FunctionExpression, or accessor PropertyAssignment is strict function code if its FunctionDeclaration, FunctionExpression, or PropertyAssignment is contained in strict mode code or if the function code begins with a Directive Prologue that contains a Use Strict Directive.

If you're receiving this error you can safely remove the highlighted instances of the "use strict" directive and be sure that the function in question will still run in strict mode:

7
 
1
function factory() {
2
    "use strict";
3
    return function () {
4
        return true;
5
    };
6
}
7
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 W034. This means you can tell JSHint to not issue this warning with the /*jshint -W034 */ directive.

In ESLint the rule that generates this warning is named no-extra-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