github-pages-deploy-action/node_modules/eslint/lib/rules/no-new-wrappers.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-03-07 11:45:40 +08:00
/**
* @fileoverview Rule to flag when using constructor for wrapper objects
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "disallow `new` operators with the `String`, `Number`, and `Boolean` objects",
category: "Best Practices",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-wrappers"
},
2020-05-15 05:33:08 +08:00
schema: [],
messages: {
noConstructor: "Do not use {{fn}} as a constructor."
}
2020-03-07 11:45:40 +08:00
},
create(context) {
return {
NewExpression(node) {
2020-05-15 05:33:08 +08:00
const wrapperObjects = ["String", "Number", "Boolean"];
2020-03-07 11:45:40 +08:00
if (wrapperObjects.indexOf(node.callee.name) > -1) {
2020-05-15 05:33:08 +08:00
context.report({
node,
messageId: "noConstructor",
data: { fn: node.callee.name }
});
2020-03-07 11:45:40 +08:00
}
}
};
}
};