summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/new-parens.js
blob: 0509229bbb59de9945bacd1bc9c155d96587ca17 (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) {
        const sourceCode = context.getSourceCode();

        return {

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

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

    }
};