material-extensions / material-icons-browser-extension

Browser Addon that enhances file browsers of version controls with material icons.
MIT License
499 stars 38 forks source link

fix: Replace property checking with `hasOwnProperty` wrapper #69

Closed csandman closed 11 months ago

csandman commented 1 year ago

closes #68

Shoot, well, I realized this problem is due to a change I made in my ESLint fix way back when haha. I switched from using .hasOwnProperty for all of the key checking to simply checking object[key]. This was to follow the no-prototype-builtins ESLint rule. The problem with this being that it includes prototype properties like constructor. Anyway, I made a little helper function to check if an object has a property without including prototypes that still obeys this ESLint rule:

/**
 * A helper function to check if an object has a key value, without including prooerties from the prototype chain.
 *
 * @see https://eslint.org/docs/latest/rules/no-prototype-builtins
 * @param {object} obj An object to check for a key.
 * @param {string} key A string represeing a key to find in the object.
 * @returns {boolean} Whether the object contains the key or not.
 */
function objectHas(obj, key) {
  return Object.prototype.hasOwnProperty.call(obj, key);
}

Also, I noticed that a bunch of files got slightly normalized by running prettier --write ., so I included them here as well, but I can remove those changes if you want me to.

Claudiohbsantos commented 11 months ago

thanks for catching this one! And no worries on the prettier updates, let's keep them