From a370da27a7957e2a5e038f75cd97c0951f8c4ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Sun, 10 Jun 2018 00:08:31 +0800 Subject: [PATCH] Chore: small opt to improve readability (#10241) * Chore: use Array.unshift(), to avoid Array.reverse() * Chore: fix misleading jsdoc param --- lib/config.js | 8 ++++---- lib/ignored-paths.js | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/config.js b/lib/config.js index 7ba5cd6e2d1..2eeaad1812a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -209,7 +209,7 @@ class Config { const localConfigHierarchyCache = this.configCache.getHierarchyLocalConfigs(localConfigDirectory); if (localConfigHierarchyCache) { - const localConfigHierarchy = localConfigHierarchyCache.concat(configs.reverse()); + const localConfigHierarchy = localConfigHierarchyCache.concat(configs); this.configCache.setHierarchyLocalConfigs(searched, localConfigHierarchy); return localConfigHierarchy; @@ -232,7 +232,7 @@ class Config { } debug(`Using ${localConfigFile}`); - configs.push(localConfig); + configs.unshift(localConfig); searched.push(localConfigDirectory); // Stop traversing if a config is found with the root flag set @@ -248,7 +248,7 @@ class Config { const personalConfig = this.getPersonalConfig(); if (personalConfig) { - configs.push(personalConfig); + configs.unshift(personalConfig); } else if (!hasRules(this.options) && !this.options.baseConfig) { // No config file, no manual configuration, and no rules, so error. @@ -265,7 +265,7 @@ class Config { } // Set the caches for the parent directories - this.configCache.setHierarchyLocalConfigs(searched, configs.reverse()); + this.configCache.setHierarchyLocalConfigs(searched, configs); return configs; } diff --git a/lib/ignored-paths.js b/lib/ignored-paths.js index 0371e5e109d..8134d6d32e4 100644 --- a/lib/ignored-paths.js +++ b/lib/ignored-paths.js @@ -236,7 +236,7 @@ class IgnoredPaths { /** * Determine whether a file path is included in the default or custom ignore patterns * @param {string} filepath Path to check - * @param {string} [category=null] check 'default', 'custom' or both (null) + * @param {string} [category=undefined] check 'default', 'custom' or both (undefined) * @returns {boolean} true if the file path matches one or more patterns, false otherwise */ contains(filepath, category) { @@ -245,12 +245,11 @@ class IgnoredPaths { const absolutePath = path.resolve(this.options.cwd, filepath); const relativePath = pathUtil.getRelativePath(absolutePath, this.baseDir); - if ((typeof category === "undefined") || (category === "default")) { - result = result || (this.ig.default.filter([relativePath]).length === 0); - } - - if ((typeof category === "undefined") || (category === "custom")) { - result = result || (this.ig.custom.filter([relativePath]).length === 0); + if (typeof category === "undefined") { + result = (this.ig.default.filter([relativePath]).length === 0) || + (this.ig.custom.filter([relativePath]).length === 0); + } else { + result = (this.ig[category].filter([relativePath]).length === 0); } return result;