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

55 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2020-03-07 11:45:40 +08:00
/**
* @fileoverview Rule to disallow use of the new operator with the `Symbol` object
* @author Alberto Rodríguez
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "problem",
docs: {
description: "disallow `new` operators with the `Symbol` object",
category: "ECMAScript 6",
recommended: true,
url: "https://eslint.org/docs/rules/no-new-symbol"
},
2020-05-15 05:33:08 +08:00
schema: [],
messages: {
noNewSymbol: "`Symbol` cannot be called as a constructor."
}
2020-03-07 11:45:40 +08:00
},
create(context) {
return {
"Program:exit"() {
const globalScope = context.getScope();
const variable = globalScope.set.get("Symbol");
if (variable && variable.defs.length === 0) {
variable.references.forEach(ref => {
const node = ref.identifier;
2020-06-06 22:11:37 +08:00
const parent = node.parent;
2020-03-07 11:45:40 +08:00
2020-06-06 22:11:37 +08:00
if (parent && parent.type === "NewExpression" && parent.callee === node) {
2020-05-15 05:33:08 +08:00
context.report({
node,
messageId: "noNewSymbol"
});
2020-03-07 11:45:40 +08:00
}
});
}
}
};
}
};