twreporter-react
Version:
React-Redux site for The Reporter Foundation in Taiwan
48 lines (35 loc) • 1.32 kB
JavaScript
/**
* @fileoverview Rule to flag use of parseInt without a radix argument
* @author James Allardice
*/
;
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
return {
"CallExpression": function(node) {
var radix;
if (!(node.callee.name === "parseInt" || (
node.callee.type === "MemberExpression" &&
node.callee.object.name === "Number" &&
node.callee.property.name === "parseInt"
)
)) {
return;
}
if (node.arguments.length < 2) {
context.report(node, "Missing radix parameter.");
} else {
radix = node.arguments[1];
// don't allow non-numeric literals or undefined
if ((radix.type === "Literal" && typeof radix.value !== "number") ||
(radix.type === "Identifier" && radix.name === "undefined")
) {
context.report(node, "Invalid radix parameter.");
}
}
}
};
};
module.exports.schema = [];