UNPKG

957 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when using constructor for wrapper objects
3 * @author Ilya Volodin
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
16 category: "Best Practices",
17 recommended: false
18 },
19
20 schema: []
21 },
22
23 create(context) {
24
25 return {
26
27 NewExpression(node) {
28 const wrapperObjects = ["String", "Number", "Boolean", "Math", "JSON"];
29
30 if (wrapperObjects.indexOf(node.callee.name) > -1) {
31 context.report(node, "Do not use {{fn}} as a constructor.", { fn: node.callee.name });
32 }
33 }
34 };
35
36 }
37};