Skip to content

Commit

Permalink
Merge pull request #15 from felipinas/fix/ignore-chain-in-update-coll…
Browse files Browse the repository at this point in the history
…ection-method

Fix: ignore chain in update collection method
  • Loading branch information
renanccastro authored Dec 3, 2024
2 parents 41fb151 + dd9799b commit 8bab265
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/no-sync-mongo-methods-on-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ module.exports = {
return;
}
}
if(node.object.type === 'MemberExpression'){
// this means it's a call chain like crypto.createHmac().update()
if(['MemberExpression', 'CallExpression'].includes(node.object.type) && node.type === 'MemberExpression'){
// we can ignore longer than 1 call chain
debug(
`Skipping ${invalidFunction} to be considered error because it was used in a longer than 1 call chain`,
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-sync-mongo-methods-on-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ ruleTester.run('no-sync-mongo-methods-on-server', rule, {
modules.fetch();
`,
},
{
code: `
crypto
.createHmac('sha256', secretIntercomKey)
.update(userId);
`,
},
],

invalid: [
Expand Down

0 comments on commit 8bab265

Please sign in to comment.