diff --git a/src/cli/expand-patterns.js b/src/cli/expand-patterns.js index 424f69aa7..d37ed34f5 100644 --- a/src/cli/expand-patterns.js +++ b/src/cli/expand-patterns.js @@ -55,9 +55,9 @@ function* expandPatternsInternal(context) { const globOptions = { dot: true, - ignore: Object.keys(silentlyIgnoredDirs) - .filter((dir) => silentlyIgnoredDirs[dir]) - .map((dir) => "**/" + dir), + ignore: Object.entries(silentlyIgnoredDirs) + .filter(([, ignored]) => ignored) + .map(([dir]) => "**/" + dir), }; let supportedFilesGlob; diff --git a/src/cli/option.js b/src/cli/option.js index b71726382..5533e9666 100644 --- a/src/cli/option.js +++ b/src/cli/option.js @@ -20,13 +20,14 @@ function getOptions(argv, detailedOptions) { } function cliifyOptions(object, apiDetailedOptionMap) { - return Object.keys(object || {}).reduce((output, key) => { - const apiOption = apiDetailedOptionMap[key]; - const cliKey = apiOption ? apiOption.name : key; + return fromPairs( + Object.entries(object || {}).map(([key, value]) => { + const apiOption = apiDetailedOptionMap[key]; + const cliKey = apiOption ? apiOption.name : key; - output[dashify(cliKey)] = object[key]; - return output; - }, {}); + return [dashify(cliKey), value]; + }) + ); } function createApiDetailedOptionMap(detailedOptions) { diff --git a/src/cli/usage.js b/src/cli/usage.js index 151de5a6a..2685b3bc6 100644 --- a/src/cli/usage.js +++ b/src/cli/usage.js @@ -176,11 +176,8 @@ function createDetailedUsage(context, flag) { const pluginDefaults = option.pluginDefaults && Object.keys(option.pluginDefaults).length > 0 - ? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map( - (key) => - `\n* ${key}: ${createDefaultValueDisplay( - option.pluginDefaults[key] - )}` + ? `\nPlugin defaults:${Object.entries(option.pluginDefaults).map( + ([key, value]) => `\n* ${key}: ${createDefaultValueDisplay(value)}` )}` : ""; return `${header}${description}${choices}${defaults}${pluginDefaults}`; diff --git a/src/language-html/ast.js b/src/language-html/ast.js index f612f67be..52b709ac6 100644 --- a/src/language-html/ast.js +++ b/src/language-html/ast.js @@ -1,5 +1,6 @@ "use strict"; +const fromPairs = require("lodash/fromPairs"); const { isNonEmptyArray } = require("../common/util"); const NODES_KEYS = { attrs: true, @@ -8,8 +9,7 @@ const NODES_KEYS = { class Node { constructor(props = {}) { - for (const key of Object.keys(props)) { - const value = props[key]; + for (const [key, value] of Object.entries(props)) { if (key in NODES_KEYS) { this._setNodes(key, value); } else { @@ -123,10 +123,13 @@ function cloneAndUpdateNodes(nodes, parent) { } function setNonEnumerableProperties(obj, props) { - const descriptors = Object.keys(props).reduce((reduced, key) => { - reduced[key] = { value: props[key], enumerable: false }; - return reduced; - }, {}); + const descriptors = fromPairs( + Object.entries(props).map(([key, value]) => [ + key, + { value, enumerable: false }, + ]) + ); + Object.defineProperties(obj, descriptors); } diff --git a/src/language-html/utils.js b/src/language-html/utils.js index e4ac2446f..06b85e362 100644 --- a/src/language-html/utils.js +++ b/src/language-html/utils.js @@ -46,8 +46,8 @@ function arrayToMap(array) { function mapObject(object, fn) { const newObject = Object.create(null); - for (const key of Object.keys(object)) { - newObject[key] = fn(object[key], key); + for (const [key, value] of Object.entries(object)) { + newObject[key] = fn(value, key); } return newObject; } diff --git a/src/language-js/utils.js b/src/language-js/utils.js index 56eceef21..744685678 100644 --- a/src/language-js/utils.js +++ b/src/language-js/utils.js @@ -87,7 +87,7 @@ function hasNode(node, fn) { const result = fn(node); return typeof result === "boolean" ? result - : Object.keys(node).some((key) => hasNode(node[key], fn)); + : Object.values(node).some((value) => hasNode(value, fn)); } /** diff --git a/src/main/comments.js b/src/main/comments.js index 0594d931e..45bd8abfd 100644 --- a/src/main/comments.js +++ b/src/main/comments.js @@ -50,16 +50,16 @@ function getSortedChildNodes(node, options, resultArray) { (printer.getCommentChildNodes && printer.getCommentChildNodes(node, options)) || (typeof node === "object" && - Object.keys(node) + Object.entries(node) .filter( - (n) => + ([n]) => n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode" && n !== "tokens" && n !== "comments" ) - .map((n) => node[n])); + .map(([, value]) => value)); if (!childNodes) { return; diff --git a/src/main/massage-ast.js b/src/main/massage-ast.js index f2ce7beb7..784b568e9 100644 --- a/src/main/massage-ast.js +++ b/src/main/massage-ast.js @@ -18,9 +18,9 @@ function massageAST(ast, options, parent) { } const newObj = {}; - for (const key of Object.keys(ast)) { - if (!ignoredProperties.has(key) && typeof ast[key] !== "function") { - newObj[key] = massageAST(ast[key], options, ast); + for (const [key, value] of Object.entries(ast)) { + if (!ignoredProperties.has(key) && typeof value !== "function") { + newObj[key] = massageAST(value, options, ast); } } diff --git a/src/main/options.js b/src/main/options.js index 544f31e26..fecf5834d 100644 --- a/src/main/options.js +++ b/src/main/options.js @@ -86,9 +86,9 @@ function normalize(options, opts) { const mixedDefaults = { ...defaults, ...pluginDefaults }; - for (const k of Object.keys(mixedDefaults)) { + for (const [k, value] of Object.entries(mixedDefaults)) { if (rawOptions[k] == null) { - rawOptions[k] = mixedDefaults[k]; + rawOptions[k] = value; } }