1 | /**
|
2 | * @fileoverview Rule to flag use of parseInt without a radix argument
|
3 | * @author James Allardice
|
4 | */
|
5 |
|
6 | //------------------------------------------------------------------------------
|
7 | // Rule Definition
|
8 | //------------------------------------------------------------------------------
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | ;
|
13 |
|
14 | return {
|
15 | "CallExpression": function(node) {
|
16 |
|
17 | var radix;
|
18 |
|
19 | if (node.callee.name === "parseInt") {
|
20 |
|
21 | if (node.arguments.length < 2) {
|
22 | context.report(node, "Missing radix parameter.");
|
23 | } else {
|
24 |
|
25 | radix = node.arguments[1];
|
26 |
|
27 | // don't allow non-numeric literals or undefined
|
28 | if ((radix.type === "Literal" && typeof radix.value !== "number") ||
|
29 | (radix.type === "Identifier" && radix.name === "undefined")
|
30 | ) {
|
31 | context.report(node, "Invalid radix parameter.");
|
32 | }
|
33 | }
|
34 |
|
35 | }
|
36 | }
|
37 | };
|
38 |
|
39 | };
|