blob: 97980f6fed2364c0c4f4e362a4a0879e09008bdc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/**
* @fileoverview Rule to flag or require global strict mode.
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
var mode = context.options[0];
if (mode === "always") {
return {
"Program": function(node) {
if (node.body.length > 0) {
var statement = node.body[0];
if (!(statement.type === "ExpressionStatement" && statement.expression.value === "use strict")) {
context.report(node, "Use the global form of \"use strict\".");
}
}
}
};
} else { // mode = "never"
return {
"ExpressionStatement": function(node) {
var parent = context.getAncestors().pop();
if (node.expression.value === "use strict" && parent.type === "Program") {
context.report(node, "Use the function form of \"use strict\".");
}
}
};
}
};
module.exports.schema = [
{
"enum": ["always", "never"]
}
];
|