2 * @fileoverview Rule to flag unnecessary strict directives.
3 * @author Ian Christian Myers
4 * @copyright 2014 Ian Christian Myers. All rights reserved.
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 module.exports = function(context) {
14 function directives(block) {
15 var ds = [], body = block.body, e, i, l;
18 for (i = 0, l = body.length; i < l; ++i) {
22 e.type === "ExpressionStatement" &&
23 e.expression.type === "Literal" &&
24 typeof e.expression.value === "string"
26 ds.push(e.expression);
36 function isStrict(directive) {
37 return directive.value === "use strict";
40 function checkForUnnecessaryUseStrict(node) {
41 var useStrictDirectives = directives(node).filter(isStrict),
45 switch (useStrictDirectives.length) {
50 scope = context.getScope();
53 if (upper && upper.functionExpressionScope) {
57 if (upper && upper.isStrict) {
58 context.report(useStrictDirectives[0], "Unnecessary 'use strict'.");
63 context.report(useStrictDirectives[1], "Multiple 'use strict' directives.");
69 "Program": checkForUnnecessaryUseStrict,
71 "ArrowFunctionExpression": function(node) {
72 checkForUnnecessaryUseStrict(node.body);
75 "FunctionExpression": function(node) {
76 checkForUnnecessaryUseStrict(node.body);
79 "FunctionDeclaration": function(node) {
80 checkForUnnecessaryUseStrict(node.body);