You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
1.3 KiB

/**
* @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"]
}
];