webhook-action/node_modules/eslint/lib/rules/no-new-wrappers.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* @fileoverview Rule to flag when using constructor for wrapper objects
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
2022-11-10 10:43:16 +00:00
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
2022-11-10 10:43:16 +00:00
description: "Disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-wrappers"
},
schema: [],
messages: {
noConstructor: "Do not use {{fn}} as a constructor."
}
},
create(context) {
return {
NewExpression(node) {
const wrapperObjects = ["String", "Number", "Boolean"];
2022-11-10 10:43:16 +00:00
if (wrapperObjects.includes(node.callee.name)) {
context.report({
node,
messageId: "noConstructor",
data: { fn: node.callee.name }
});
}
}
};
}
};