Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: no-new-symbol false positive with Symbol as an argument #13337

Merged
merged 1 commit into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rules/no-new-symbol.js
Expand Up @@ -37,8 +37,9 @@ module.exports = {
if (variable && variable.defs.length === 0) {
variable.references.forEach(ref => {
const node = ref.identifier;
const parent = node.parent;

if (node.parent && node.parent.type === "NewExpression") {
if (parent && parent.type === "NewExpression" && parent.callee === node) {
context.report({
node,
messageId: "noNewSymbol"
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/rules/no-new-symbol.js
Expand Up @@ -22,7 +22,9 @@ ruleTester.run("no-new-symbol", rule, {
valid: [
"var foo = Symbol('foo');",
"function bar(Symbol) { var baz = new Symbol('baz');}",
"function Symbol() {} new Symbol();"
"function Symbol() {} new Symbol();",
"new foo(Symbol);",
"new foo(bar, Symbol);"
],
invalid: [
{
Expand Down