node/tools/eslint/lib/rules/radix.js
Roman Reiss d91e10b3bd tools: update eslint to 0.24.0
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>
2015-06-29 19:02:17 +02:00

41 lines
1.1 KiB
JavaScript

/**
* @fileoverview Rule to flag use of parseInt without a radix argument
* @author James Allardice
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
return {
"CallExpression": function(node) {
var radix;
if (node.callee.name === "parseInt") {
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 = [];