Skip to content

Commit

Permalink
update no-setter-return
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 17, 2020
1 parent d12b2be commit a31e04c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
13 changes: 5 additions & 8 deletions lib/rules/no-setter-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ function isGlobalReference(node, scope) {
* @returns {boolean} `true` if the node is argument at the given position.
*/
function isArgumentOfGlobalMethodCall(node, scope, objectName, methodName, index) {
const parent = node.parent;
const callNode = node.parent;

return parent.type === "CallExpression" &&
parent.arguments[index] === node &&
parent.callee.type === "MemberExpression" &&
astUtils.getStaticPropertyName(parent.callee) === methodName &&
parent.callee.object.type === "Identifier" &&
parent.callee.object.name === objectName &&
isGlobalReference(parent.callee.object, scope);
return callNode.type === "CallExpression" &&
callNode.arguments[index] === node &&
astUtils.isSpecificMemberAccess(callNode.callee, objectName, methodName) &&
isGlobalReference(astUtils.skipChainExpression(callNode.callee).object, scope);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion tests/lib/rules/no-setter-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function error(column, type = "ReturnStatement") {
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } });
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020 } });

ruleTester.run("no-setter-return", rule, {
valid: [
Expand Down Expand Up @@ -505,6 +505,18 @@ ruleTester.run("no-setter-return", rule, {
{
code: "Object.defineProperty(foo, 'bar', { set: function(Object) { return 1; } })",
errors: [error()]
},

// Optional chaining
{
code: "Object?.defineProperty(foo, 'bar', { set(val) { return 1; } })",
parserOptions: { ecmaVersion: 2020 },
errors: [error()]
},
{
code: "(Object?.defineProperty)(foo, 'bar', { set(val) { return 1; } })",
parserOptions: { ecmaVersion: 2020 },
errors: [error()]
}
]
});

0 comments on commit a31e04c

Please sign in to comment.