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>
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/**
|
|
* @fileoverview Rule to enforce consistent spacing after function names
|
|
* @author Roberto Vidal
|
|
* @copyright 2014 Roberto Vidal. All rights reserved.
|
|
*/
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
var requiresSpace = context.options[0] === "always";
|
|
|
|
/**
|
|
* Reports if the give named function node has the correct spacing after its name
|
|
*
|
|
* @param {ASTNode} node The node to which the potential problem belongs.
|
|
* @returns {void}
|
|
*/
|
|
function check(node) {
|
|
var tokens = context.getFirstTokens(node, 3),
|
|
hasSpace = tokens[1].range[1] < tokens[2].range[0];
|
|
|
|
if (hasSpace !== requiresSpace) {
|
|
context.report(node, "Function name \"{{name}}\" must {{not}}be followed by whitespace.", {
|
|
name: node.id.name,
|
|
not: requiresSpace ? "" : "not "
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
"FunctionDeclaration": check,
|
|
"FunctionExpression": function (node) {
|
|
if (node.id) {
|
|
check(node);
|
|
}
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
module.exports.schema = [
|
|
{
|
|
"enum": ["always", "never"]
|
|
}
|
|
];
|