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

58 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2020-03-07 11:45:40 +08:00
/**
* @fileoverview A rule to disallow calls to the Object constructor
* @author Matt DuVall <http://www.mattduvall.com/>
*/
"use strict";
2020-05-15 05:33:08 +08:00
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
2020-03-07 11:45:40 +08:00
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "disallow `Object` constructors",
category: "Stylistic Issues",
recommended: false,
url: "https://eslint.org/docs/rules/no-new-object"
},
2020-05-15 05:33:08 +08:00
schema: [],
messages: {
preferLiteral: "The object literal notation {} is preferrable."
}
2020-03-07 11:45:40 +08:00
},
create(context) {
return {
NewExpression(node) {
2020-05-15 05:33:08 +08:00
const variable = astUtils.getVariableByName(
context.getScope(),
node.callee.name
);
if (variable && variable.identifiers.length > 0) {
return;
}
2020-03-07 11:45:40 +08:00
if (node.callee.name === "Object") {
2020-05-15 05:33:08 +08:00
context.report({
node,
messageId: "preferLiteral"
});
2020-03-07 11:45:40 +08:00
}
}
};
}
};