1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | module.exports = function(context) {
|
12 |
|
13 | function isPragma(expression, parent) {
|
14 |
|
15 | var isStrict = expression.type === "Literal" && expression.value === "use strict",
|
16 | isGlobalStrict = isStrict && (parent.type === "Program" && parent.body[0].expression === expression),
|
17 | isLocalStrict = isStrict && (parent.type === "BlockStatement" && parent.body[0].expression === expression);
|
18 |
|
19 | return isGlobalStrict || isLocalStrict;
|
20 | }
|
21 |
|
22 | return {
|
23 | "ExpressionStatement": function(node) {
|
24 |
|
25 | var type = node.expression.type,
|
26 | parent = context.getAncestors().pop();
|
27 |
|
28 |
|
29 | if (
|
30 | !/^(?:Assignment|Call|New|Update)Expression$/.test(type) &&
|
31 | (type !== "UnaryExpression" || ["delete", "void"].indexOf(node.expression.operator) < 0) &&
|
32 | !isPragma(node.expression, parent)
|
33 | ) {
|
34 | context.report(node, "Expected an assignment or function call and instead saw an expression.");
|
35 | }
|
36 | }
|
37 | };
|
38 |
|
39 | };
|