Sha256: f1926754b70470a12ce6bd0ca7705210077e8b98f8ece5b2d3f2ece35d6b889a
Contents?: true
Size: 1.97 KB
Versions: 2
Compression:
Stored size: 1.97 KB
Contents
/** * @fileoverview Rule to flag consistent return values * @author Nicholas C. Zakas */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = function(context) { var functions = []; //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- /** * Marks entrance into a function by pushing a new object onto the functions * stack. * @returns {void} * @private */ function enterFunction() { functions.push({}); } /** * Marks exit of a function by popping off the functions stack. * @returns {void} * @private */ function exitFunction() { functions.pop(); } //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- return { "Program": enterFunction, "FunctionDeclaration": enterFunction, "FunctionExpression": enterFunction, "ArrowFunctionExpression": enterFunction, "Program:exit": exitFunction, "FunctionDeclaration:exit": exitFunction, "FunctionExpression:exit": exitFunction, "ArrowFunctionExpression:exit": exitFunction, "ReturnStatement": function(node) { var returnInfo = functions[functions.length - 1], returnTypeDefined = "type" in returnInfo; if (returnTypeDefined) { if (returnInfo.type !== !!node.argument) { context.report(node, "Expected " + (returnInfo.type ? "a" : "no") + " return value."); } } else { returnInfo.type = !!node.argument; } } }; }; 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/consistent-return.js |
eslint_node_modules-1.6.0 | vendor/node_modules/eslint/lib/rules/consistent-return.js |