diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js | 94 |
1 files changed, 80 insertions, 14 deletions
diff --git a/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js b/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js index ae64dcc09f..4ffb4dc01b 100644 --- a/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js +++ b/tools/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js @@ -106,7 +106,7 @@ const baseSchema = Object.freeze({ const debug = createDebug('@hwc/config-array'); const MINIMATCH_OPTIONS = { - matchBase: true, + // matchBase: true, dot: true }; @@ -233,6 +233,11 @@ function normalizeSync(items, context, extraConfigTypes) { */ function shouldIgnoreFilePath(ignores, filePath, relativeFilePath) { + // all files outside of the basePath are ignored + if (relativeFilePath.startsWith('..')) { + return true; + } + let shouldIgnore = false; for (const matcher of ignores) { @@ -285,11 +290,6 @@ function shouldIgnoreFilePath(ignores, filePath, relativeFilePath) { */ function pathMatches(filePath, basePath, config) { - // a config without `files` field always match - if (!config.files) { - return true; - } - /* * For both files and ignores, functions are passed the absolute * file path while strings are compared against the relative @@ -399,8 +399,7 @@ class ConfigArray extends Array { * definitions to use for the ConfigArray schema. * @param {Array<string>} [options.configTypes] List of config types supported. */ - constructor(configs, - { + constructor(configs, { basePath = '', normalized = false, schema: customSchema, @@ -454,7 +453,7 @@ class ConfigArray extends Array { this[ConfigArraySymbol.configCache] = new Map(); // init cache - dataCache.set(this, {}); + dataCache.set(this, { explicitMatches: new Map() }); // load the configs into this array if (Array.isArray(configs)) { @@ -536,7 +535,13 @@ get ignores() { const result = []; for (const config of this) { - if (config.ignores && !config.files) { + + /* + * We only count ignores if there are no other keys in the object. + * In this case, it acts list a globally ignored pattern. If there + * are additional keys, then ignores act like exclusions. + */ + if (config.ignores && Object.keys(config).length === 1) { result.push(...config.ignores); } } @@ -588,7 +593,7 @@ normalizeSync(context = {}) { if (!this.isNormalized()) { const normalizedConfigs = normalizeSync(this, context, this.extraConfigTypes); this.length = 0; - this.push(...normalizedConfigs.map(this[ConfigArraySymbol.preprocessConfig])); + this.push(...normalizedConfigs.map(this[ConfigArraySymbol.preprocessConfig].bind(this))); this[ConfigArraySymbol.isNormalized] = true; // prevent further changes @@ -622,6 +627,56 @@ normalizeSync(context = {}) { } /** + * Determines if a given file path explicitly matches a `files` entry + * and also doesn't match an `ignores` entry. Configs that don't have + * a `files` property are not considered an explicit match. + * @param {string} filePath The complete path of a file to check. + * @returns {boolean} True if the file path matches a `files` entry + * or false if not. + */ +isExplicitMatch(filePath) { + + assertNormalized(this); + + const cache = dataCache.get(this); + + // first check the cache to avoid duplicate work + let result = cache.explicitMatches.get(filePath); + + if (typeof result == 'boolean') { + return result; + } + + // TODO: Maybe move elsewhere? Maybe combine with getConfig() logic? + const relativeFilePath = path.relative(this.basePath, filePath); + + if (shouldIgnoreFilePath(this.ignores, filePath, relativeFilePath)) { + debug(`Ignoring ${filePath}`); + + // cache and return result + cache.explicitMatches.set(filePath, false); + return false; + } + + // filePath isn't automatically ignored, so try to find a match + + for (const config of this) { + + if (!config.files) { + continue; + } + + if (pathMatches(filePath, this.basePath, config)) { + debug(`Matching config found for ${filePath}`); + cache.explicitMatches.set(filePath, true); + return true; + } + } + + return false; +} + +/** * Returns the config object for a given file path. * @param {string} filePath The complete path of a file to get a config for. * @returns {Object} The config object for this file. @@ -641,6 +696,7 @@ getConfig(filePath) { const relativeFilePath = path.relative(this.basePath, filePath); if (shouldIgnoreFilePath(this.ignores, filePath, relativeFilePath)) { + debug(`Ignoring ${filePath}`); // cache and return result - finalConfig is undefined at this point this[ConfigArraySymbol.configCache].set(filePath, finalConfig); @@ -650,18 +706,28 @@ getConfig(filePath) { // filePath isn't automatically ignored, so try to construct config const matchingConfigs = []; + let matchFound = false; for (const config of this) { + + if (!config.files) { + debug(`Universal config found for ${filePath}`); + matchingConfigs.push(config); + continue; + } + if (pathMatches(filePath, this.basePath, config)) { debug(`Matching config found for ${filePath}`); matchingConfigs.push(config); - } else { - debug(`No matching config found for ${filePath}`); + matchFound = true; + continue; } } // if matching both files and ignores, there will be no config to create - if (matchingConfigs.length === 0) { + if (!matchFound) { + debug(`No matching configs found for ${filePath}`); + // cache and return result - finalConfig is undefined at this point this[ConfigArraySymbol.configCache].set(filePath, finalConfig); return finalConfig; |