PR-URL: https://github.com/nodejs/io.js/pull/2072 Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com> Reviewed-by: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alex Kocharin <alex@kocharin.ru>
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/**
|
|
* @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"]
|
|
}
|
|
];
|