1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.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 | url: "https://eslint.org/docs/rules/no-new-wrappers"
|
19 | },
|
20 |
|
21 | schema: []
|
22 | },
|
23 |
|
24 | create(context) {
|
25 |
|
26 | return {
|
27 |
|
28 | NewExpression(node) {
|
29 | const wrapperObjects = ["String", "Number", "Boolean", "Math", "JSON"];
|
30 |
|
31 | if (wrapperObjects.indexOf(node.callee.name) > -1) {
|
32 | context.report({ node, message: "Do not use {{fn}} as a constructor.", data: { fn: node.callee.name } });
|
33 | }
|
34 | }
|
35 | };
|
36 |
|
37 | }
|
38 | };
|