Skip to content

Commit

Permalink
feat: add method isFileConfigured
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed May 8, 2024
1 parent ecdddcc commit 49f8c9a
Show file tree
Hide file tree
Showing 2 changed files with 1,766 additions and 1,255 deletions.
23 changes: 23 additions & 0 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ export const ConfigArraySymbol = {
// used to store calculate data for faster lookup
const dataCache = new WeakMap();

// A value indicating that a file has no matching configuration. Should be a unique object or symbol.
const NoMatchingConfig = {};

/**
* Represents an array of config objects and provides method for working with
* those config objects.
Expand Down Expand Up @@ -825,6 +828,16 @@ export class ConfigArray extends Array {
* @returns {Object} The config object for this file.
*/
getConfig(filePath) {
const config = this.getConfigOrNoMatch(filePath);
if (config !== NoMatchingConfig) return config;
}

/**
* Returns the config object for a given file path or a `NoMatchingConfig` indicator.
* @param {string} filePath The complete path of a file to get a config for.
* @returns {Object} The config object or `NoMatchingConfig` indicator for this file.
*/
getConfigOrNoMatch(filePath) {
assertNormalized(this);

const cache = this[ConfigArraySymbol.configCache];
Expand Down Expand Up @@ -950,6 +963,7 @@ export class ConfigArray extends Array {
debug(`No matching configs found for ${filePath}`);

// cache and return result - finalConfig is undefined at this point
finalConfig = NoMatchingConfig;
cache.set(filePath, finalConfig);
return finalConfig;
}
Expand Down Expand Up @@ -1004,6 +1018,15 @@ export class ConfigArray extends Array {
return this.getConfig(filePath) === undefined;
}

/**
* Determines if the given filepath has a matching config.
* @param {string} filePath The complete path of a file to check.
* @returns {boolean} True if the path has a matching config, false if not.
*/
isFileConfigured(filePath) {
return this.getConfigOrNoMatch(filePath) !== NoMatchingConfig;
}

/**
* Determines if the given directory is ignored based on the configs.
* This checks only default `ignores` that don't have `files` in the
Expand Down

0 comments on commit 49f8c9a

Please sign in to comment.