Sha256: a37dc43bade71ef1775836f58dd81cb4cd58fd474b1b194f49ada9d65fc7c9fb

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

/**
 * @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" || (
                    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 = [];

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/lib/rules/radix.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/lib/rules/radix.js