source: imaps-frontend/node_modules/eslint/lib/rules/no-new-wrappers.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1/**
2 * @fileoverview Rule to flag when using constructor for wrapper objects
3 * @author Ilya Volodin
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Requirements
10//------------------------------------------------------------------------------
11
12const { getVariableByName } = require("./utils/ast-utils");
13
14//------------------------------------------------------------------------------
15// Rule Definition
16//------------------------------------------------------------------------------
17
18/** @type {import('../shared/types').Rule} */
19module.exports = {
20 meta: {
21 type: "suggestion",
22
23 docs: {
24 description: "Disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
25 recommended: false,
26 url: "https://eslint.org/docs/latest/rules/no-new-wrappers"
27 },
28
29 schema: [],
30
31 messages: {
32 noConstructor: "Do not use {{fn}} as a constructor."
33 }
34 },
35
36 create(context) {
37 const { sourceCode } = context;
38
39 return {
40
41 NewExpression(node) {
42 const wrapperObjects = ["String", "Number", "Boolean"];
43 const { name } = node.callee;
44
45 if (wrapperObjects.includes(name)) {
46 const variable = getVariableByName(sourceCode.getScope(node), name);
47
48 if (variable && variable.identifiers.length === 0) {
49 context.report({
50 node,
51 messageId: "noConstructor",
52 data: { fn: name }
53 });
54 }
55 }
56 }
57 };
58
59 }
60};
Note: See TracBrowser for help on using the repository browser.