diff options
Diffstat (limited to 'tools/node_modules/eslint/lib/rules/no-new-symbol.js')
-rw-r--r-- | tools/node_modules/eslint/lib/rules/no-new-symbol.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/lib/rules/no-new-symbol.js b/tools/node_modules/eslint/lib/rules/no-new-symbol.js new file mode 100644 index 0000000000..5743a4748a --- /dev/null +++ b/tools/node_modules/eslint/lib/rules/no-new-symbol.js @@ -0,0 +1,43 @@ +/** + * @fileoverview Rule to disallow use of the new operator with the `Symbol` object + * @author Alberto RodrÃguez + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + meta: { + docs: { + description: "disallow `new` operators with the `Symbol` object", + category: "ECMAScript 6", + recommended: true + }, + + schema: [] + }, + + 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; + + if (node.parent && node.parent.type === "NewExpression") { + context.report({ node, message: "`Symbol` cannot be called as a constructor." }); + } + }); + } + } + }; + + } +}; |