mirror of
https://github.com/nodejs/node.git
synced 2025-05-18 22:53:45 +00:00

PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/**
|
|
* @fileoverview Rule to warn when a function expression does not have a name.
|
|
* @author Kyle T. Nunery
|
|
* @copyright 2015 Brandon Mills. All rights reserved.
|
|
* @copyright 2014 Kyle T. Nunery. All rights reserved.
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
/**
|
|
* Determines whether the current FunctionExpression node is a get, set, or
|
|
* shorthand method in an object literal or a class.
|
|
* @returns {boolean} True if the node is a get, set, or shorthand method.
|
|
*/
|
|
function isObjectOrClassMethod() {
|
|
var parent = context.getAncestors().pop();
|
|
|
|
return (parent.type === "MethodDefinition" || (
|
|
parent.type === "Property" && (
|
|
parent.method ||
|
|
parent.kind === "get" ||
|
|
parent.kind === "set"
|
|
)
|
|
));
|
|
}
|
|
|
|
return {
|
|
"FunctionExpression": function(node) {
|
|
|
|
var name = node.id && node.id.name;
|
|
|
|
if (!name && !isObjectOrClassMethod()) {
|
|
context.report(node, "Missing function expression name.");
|
|
}
|
|
}
|
|
};
|
|
};
|