Skip to content

Commit ddff237

Browse files
committed
[Refactor] no-danger: use Object.fromEntries and Object.hasOwn instead of reduce
1 parent d51bc61 commit ddff237

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/rules/no-danger.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
'use strict';
77

8+
const has = require('object.hasown/polyfill')();
9+
const fromEntries = require('object.fromentries/polyfill')();
10+
811
const docsUrl = require('../util/docsUrl');
912
const jsxUtil = require('../util/jsx');
1013
const report = require('../util/report');
@@ -17,10 +20,7 @@ const DANGEROUS_PROPERTY_NAMES = [
1720
'dangerouslySetInnerHTML'
1821
];
1922

20-
const DANGEROUS_PROPERTIES = DANGEROUS_PROPERTY_NAMES.reduce((props, prop) => {
21-
props[prop] = prop;
22-
return props;
23-
}, Object.create(null));
23+
const DANGEROUS_PROPERTIES = fromEntries(DANGEROUS_PROPERTY_NAMES.map((prop) => [prop, prop]));
2424

2525
// ------------------------------------------------------------------------------
2626
// Helpers
@@ -32,7 +32,7 @@ const DANGEROUS_PROPERTIES = DANGEROUS_PROPERTY_NAMES.reduce((props, prop) => {
3232
* @returns {boolean} Whether or not the attribute is dnagerous.
3333
*/
3434
function isDangerous(name) {
35-
return name in DANGEROUS_PROPERTIES;
35+
return has(DANGEROUS_PROPERTIES, name);
3636
}
3737

3838
// ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)