Skip to content

Commit

Permalink
[Refactor] no-danger: use Object.fromEntries and Object.hasOwn inst…
Browse files Browse the repository at this point in the history
…ead of reduce
  • Loading branch information
ljharb committed Sep 20, 2021
1 parent d51bc61 commit ddff237
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/rules/no-danger.js
Expand Up @@ -5,6 +5,9 @@

'use strict';

const has = require('object.hasown/polyfill')();
const fromEntries = require('object.fromentries/polyfill')();

const docsUrl = require('../util/docsUrl');
const jsxUtil = require('../util/jsx');
const report = require('../util/report');
Expand All @@ -17,10 +20,7 @@ const DANGEROUS_PROPERTY_NAMES = [
'dangerouslySetInnerHTML'
];

const DANGEROUS_PROPERTIES = DANGEROUS_PROPERTY_NAMES.reduce((props, prop) => {
props[prop] = prop;
return props;
}, Object.create(null));
const DANGEROUS_PROPERTIES = fromEntries(DANGEROUS_PROPERTY_NAMES.map((prop) => [prop, prop]));

// ------------------------------------------------------------------------------
// Helpers
Expand All @@ -32,7 +32,7 @@ const DANGEROUS_PROPERTIES = DANGEROUS_PROPERTY_NAMES.reduce((props, prop) => {
* @returns {boolean} Whether or not the attribute is dnagerous.
*/
function isDangerous(name) {
return name in DANGEROUS_PROPERTIES;
return has(DANGEROUS_PROPERTIES, name);
}

// ------------------------------------------------------------------------------
Expand Down

0 comments on commit ddff237

Please sign in to comment.