Welcome to mirror list, hosted at ThFree Co, Russian Federation.

space-after-function-name.js « rules « lib « eslint « tools - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15d2286a2ad552f6760805390dea2821a8a2e06e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * @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"]
    }
];