Skip to content

Commit

Permalink
chore: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Dec 3, 2021
1 parent e14c304 commit b095205
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rules/prefer-object-has-own.js
@@ -1,6 +1,7 @@
/**
* @fileoverview Prefers Object.hasOwn instead of Object.prototype.hasOwnProperty
* @author Nitin Kumar, Gautam Arora
* @author Nitin Kumar
* @author Gautam Arora
*/

"use strict";
Expand All @@ -13,10 +14,10 @@ const astUtils = require("./utils/ast-utils");

/**
* Checks to see if a property name object exists in the subtree recursively.
* @param {node} node to evalutate.
* @param {ASTnode} node to evalutate.
* @returns {boolean} `true` if object property exists, `false` otherwise.
*/
function checkForObject(node) {
function hasLeftHandObject(node) {
if (!node.object) {
return false;
}
Expand All @@ -32,7 +33,7 @@ function checkForObject(node) {
const propertyName = astUtils.getStaticPropertyName(node.object);

if (propertyName === "hasOwnProperty" || propertyName === "prototype") {
return checkForObject(node.object);
return hasLeftHandObject(node.object);
}

return false;
Expand Down Expand Up @@ -63,7 +64,7 @@ module.exports = {
CallExpression(node) {
const calleePropertyName = astUtils.getStaticPropertyName(node.callee);
const objectPropertyName = astUtils.getStaticPropertyName(node.callee.object);
const isObject = checkForObject(node.callee);
const isObject = hasLeftHandObject(node.callee);

// check `Object` scope
const scope = context.getScope();
Expand Down

0 comments on commit b095205

Please sign in to comment.