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

new-parens.js « rules « lib « eslint « tools - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec6106647af25dfed0a5097c8971dc036259250c (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
/**
 * @fileoverview Rule to flag when using constructor without parentheses
 * @author Ilya Volodin
 */

"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
    meta: {
        docs: {
            description: "require parentheses when invoking a constructor with no arguments",
            category: "Stylistic Issues",
            recommended: false
        },

        schema: []
    },

    create: function(context) {
        var sourceCode = context.getSourceCode();

        return {

            NewExpression: function(node) {
                var tokens = sourceCode.getTokens(node);
                var prenticesTokens = tokens.filter(function(token) {
                    return token.value === "(" || token.value === ")";
                });

                if (prenticesTokens.length < 2) {
                    context.report(node, "Missing '()' invoking a constructor");
                }
            }
        };

    }
};