mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 07:50:07 +00:00

PR-URL: https://github.com/nodejs/io.js/pull/2072 Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com> Reviewed-by: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alex Kocharin <alex@kocharin.ru>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 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.");
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
module.exports.schema = [
|
|
{
|
|
"enum": ["declaration", "expression"]
|
|
}
|
|
];
|