1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.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 | messages: {
|
26 | noConstructor: "Do not use {{fn}} as a constructor."
|
27 | }
|
28 | },
|
29 |
|
30 | create(context) {
|
31 |
|
32 | return {
|
33 |
|
34 | NewExpression(node) {
|
35 | const wrapperObjects = ["String", "Number", "Boolean"];
|
36 |
|
37 | if (wrapperObjects.indexOf(node.callee.name) > -1) {
|
38 | context.report({
|
39 | node,
|
40 | messageId: "noConstructor",
|
41 | data: { fn: node.callee.name }
|
42 | });
|
43 | }
|
44 | }
|
45 | };
|
46 |
|
47 | }
|
48 | };
|