Skip to content

Commit

Permalink
Chore: small opt to improve readability (#10241)
Browse files Browse the repository at this point in the history
* Chore: use Array.unshift(), to avoid Array.reverse()

* Chore: fix misleading jsdoc param
  • Loading branch information
aladdin-add authored and kaicataldo committed Jun 9, 2018
1 parent 640bf07 commit a370da2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/config.js
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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;
}
Expand Down
13 changes: 6 additions & 7 deletions lib/ignored-paths.js
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit a370da2

Please sign in to comment.