@eslint/config-array
Advanced tools
Comparing version
@@ -78,11 +78,2 @@ export type PropertyDefinition = import("@eslint/object-schema").PropertyDefinition; | ||
/** | ||
* 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: string): boolean; | ||
/** | ||
* Returns the config object for a given file path and a status that can be used to determine why a file has no config. | ||
@@ -89,0 +80,0 @@ * @param {string} filePath The complete path of a file to get a config for. |
@@ -573,3 +573,3 @@ // @ts-self-types="./index.d.ts" | ||
// match both strings and functions | ||
const match = pattern => { | ||
function match(pattern) { | ||
if (isString(pattern)) { | ||
@@ -584,3 +584,3 @@ return doMatch(relativeFilePath, pattern); | ||
throw new TypeError(`Unexpected matcher type ${pattern}.`); | ||
}; | ||
} | ||
@@ -906,2 +906,4 @@ // check for all matches to config.files | ||
/* eslint-disable class-methods-use-this -- Desired as instance methods */ | ||
/** | ||
@@ -930,50 +932,4 @@ * Finalizes the state of a config before being cached and returned by | ||
/** | ||
* 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); | ||
/* eslint-enable class-methods-use-this -- Desired as instance methods */ | ||
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 (shouldIgnorePath(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; | ||
} | ||
/** | ||
@@ -1032,3 +988,3 @@ * Returns the config object for a given file path and a status that can be used to determine why a file has no config. | ||
let matchFound = false; | ||
const universalPattern = /\/\*{1,2}$/; | ||
const universalPattern = /^\*$|\/\*{1,2}$/u; | ||
@@ -1058,4 +1014,4 @@ this.forEach((config, index) => { | ||
/* | ||
* If a config has a files pattern ending in /** or /*, and the | ||
* filePath only matches those patterns, then the config is only | ||
* If a config has a files pattern * or patterns ending in /** or /*, | ||
* and the filePath only matches those patterns, then the config is only | ||
* applied if there is another config where the filePath matches | ||
@@ -1113,3 +1069,2 @@ * a file with a specific extensions such as *.js. | ||
matchFound = true; | ||
return; | ||
} | ||
@@ -1140,2 +1095,3 @@ }); | ||
// eslint-disable-next-line array-callback-return, consistent-return -- rethrowConfigError always throws an error | ||
let finalConfig = matchingConfigIndices.reduce((result, index) => { | ||
@@ -1221,3 +1177,3 @@ try { | ||
.relative(this.basePath, directoryPath) | ||
.replace(/\\/g, "/"); | ||
.replace(/\\/gu, "/"); | ||
@@ -1237,3 +1193,3 @@ if (relativeDirectoryPath.startsWith("..")) { | ||
let relativeDirectoryToCheck = ""; | ||
let result = false; | ||
let result; | ||
@@ -1250,3 +1206,3 @@ /* | ||
do { | ||
relativeDirectoryToCheck += directoryParts.shift() + "/"; | ||
relativeDirectoryToCheck += `${directoryParts.shift()}/`; | ||
@@ -1253,0 +1209,0 @@ result = shouldIgnorePath( |
{ | ||
"name": "@eslint/config-array", | ||
"version": "0.15.1", | ||
"version": "0.16.0", | ||
"description": "General purpose glob-based configuration matching.", | ||
"author": "Nicholas C. Zakas", | ||
"type": "module", | ||
"main": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"exports": { | ||
@@ -37,3 +39,4 @@ "require": { | ||
"pretest": "npm run build", | ||
"test": "mocha tests/" | ||
"test": "mocha tests/", | ||
"test:coverage": "c8 npm test" | ||
}, | ||
@@ -47,3 +50,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@eslint/object-schema": "^2.1.3", | ||
"@eslint/object-schema": "^2.1.4", | ||
"debug": "^4.3.1", | ||
@@ -54,2 +57,3 @@ "minimatch": "^3.0.5" | ||
"@types/minimatch": "^3.0.5", | ||
"c8": "^9.1.0", | ||
"mocha": "^10.4.0", | ||
@@ -56,0 +60,0 @@ "rollup": "^4.16.2", |
@@ -289,3 +289,3 @@ # Config Array | ||
- The config array caches configs, so subsequent calls to `getConfig()` with the same filename will return in a fast lookup rather than another calculation. | ||
- A config will only be generated if the filename matches an entry in a `files` key. A config will not be generated without matching a `files` key (configs without a `files` key are only applied when another config with a `files` key is applied; configs without `files` are never applied on their own). Any config with a `files` key entry ending with `/**` or `/*` will only be applied if another entry in the same `files` key matches or another config matches. | ||
- A config will only be generated if the filename matches an entry in a `files` key. A config will not be generated without matching a `files` key (configs without a `files` key are only applied when another config with a `files` key is applied; configs without `files` are never applied on their own). Any config with a `files` key entry that is `*` or ends with `/**` or `/*` will only be applied if another entry in the same `files` key matches or another config matches. | ||
@@ -342,1 +342,14 @@ ## Determining Ignored Paths | ||
Apache 2.0 | ||
## Sponsors | ||
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate) to get your logo on our README and website. | ||
<!-- NOTE: This section is autogenerated. Do not manually edit.--> | ||
<!--sponsorsstart--> | ||
<h3>Platinum Sponsors</h3> | ||
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3> | ||
<p><a href="#"><img src="https://images.opencollective.com/guest-bf377e88/avatar.png" alt="Eli Schleifer" height="96"></a> <a href="https://engineering.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a></p><h3>Silver Sponsors</h3> | ||
<p><a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="64"></a> <a href="https://www.workleap.com"><img src="https://avatars.githubusercontent.com/u/53535748?u=d1e55d7661d724bf2281c1bfd33cb8f99fe2465f&v=4" alt="Workleap" height="64"></a></p><h3>Bronze Sponsors</h3> | ||
<p><a href="https://www.notion.so"><img src="https://images.opencollective.com/notion/bf3b117/logo.png" alt="notion" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Ignition" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104?v=4" alt="Nx" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774?v=4" alt="HeroCoders" height="32"></a></p> | ||
<!--sponsorsend--> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
354
3.81%112055
-0.28%6
20%2271
-3.36%Updated