]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
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 | ||
12 | module.exports = { | |
13 | meta: { | |
14 | type: "suggestion", | |
15 | ||
16 | docs: { | |
17 | description: "disallow `new` operators with the `String`, `Number`, and `Boolean` objects", | |
eb39fafa DC |
18 | recommended: false, |
19 | url: "https://eslint.org/docs/rules/no-new-wrappers" | |
20 | }, | |
21 | ||
22 | schema: [], | |
23 | ||
24 | messages: { | |
25 | noConstructor: "Do not use {{fn}} as a constructor." | |
26 | } | |
27 | }, | |
28 | ||
29 | create(context) { | |
30 | ||
31 | return { | |
32 | ||
33 | NewExpression(node) { | |
34 | const wrapperObjects = ["String", "Number", "Boolean"]; | |
35 | ||
36 | if (wrapperObjects.indexOf(node.callee.name) > -1) { | |
37 | context.report({ | |
38 | node, | |
39 | messageId: "noConstructor", | |
40 | data: { fn: node.callee.name } | |
41 | }); | |
42 | } | |
43 | } | |
44 | }; | |
45 | ||
46 | } | |
47 | }; |