2 * @fileoverview Rule to flag consistent return values
3 * @author Nicholas C. Zakas
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 module.exports = function(context) {
15 //--------------------------------------------------------------------------
17 //--------------------------------------------------------------------------
20 * Marks entrance into a function by pushing a new object onto the functions
25 function enterFunction() {
30 * Marks exit of a function by popping off the functions stack.
34 function exitFunction() {
39 //--------------------------------------------------------------------------
41 //--------------------------------------------------------------------------
45 "Program": enterFunction,
46 "FunctionDeclaration": enterFunction,
47 "FunctionExpression": enterFunction,
48 "ArrowFunctionExpression": enterFunction,
50 "Program:exit": exitFunction,
51 "FunctionDeclaration:exit": exitFunction,
52 "FunctionExpression:exit": exitFunction,
53 "ArrowFunctionExpression:exit": exitFunction,
55 "ReturnStatement": function(node) {
57 var returnInfo = functions[functions.length - 1],
58 returnTypeDefined = "type" in returnInfo;
60 if (returnTypeDefined) {
62 if (returnInfo.type !== !!node.argument) {
63 context.report(node, "Expected " + (returnInfo.type ? "a" : "no") + " return value.");
67 returnInfo.type = !!node.argument;