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.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
/**
|
|
* @fileoverview Rule to enforce a particular function style
|
|
* @author Nicholas C. Zakas
|
|
* @copyright 2013 Nicholas C. Zakas. All rights reserved.
|
|
*/
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
var style = context.options[0],
|
|
enforceDeclarations = (style === "declaration");
|
|
|
|
return {
|
|
|
|
"FunctionDeclaration": function(node) {
|
|
if (!enforceDeclarations) {
|
|
context.report(node, "Expected a function expression.");
|
|
}
|
|
},
|
|
|
|
"FunctionExpression": function() {
|
|
var parent = context.getAncestors().pop();
|
|
|
|
if (enforceDeclarations && parent.type === "VariableDeclarator") {
|
|
context.report(parent, "Expected a function declaration.");
|
|
}
|
|
},
|
|
|
|
"ArrowFunctionExpression": function() {
|
|
var parent = context.getAncestors().pop();
|
|
|
|
if (enforceDeclarations && parent.type === "VariableDeclarator") {
|
|
context.report(parent, "Expected a function declaration.");
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
};
|