UNPKG

1.07 kBJavaScriptView 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 type: "suggestion",
15
16 docs: {
17 description: "disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
18 category: "Best Practices",
19 recommended: false,
20 url: "https://eslint.org/docs/rules/no-new-wrappers"
21 },
22
23 schema: []
24 },
25
26 create(context) {
27
28 return {
29
30 NewExpression(node) {
31 const wrapperObjects = ["String", "Number", "Boolean", "Math", "JSON"];
32
33 if (wrapperObjects.indexOf(node.callee.name) > -1) {
34 context.report({ node, message: "Do not use {{fn}} as a constructor.", data: { fn: node.callee.name } });
35 }
36 }
37 };
38
39 }
40};