Changeset 0c6b92a for imaps-frontend/node_modules/eslint/lib/config
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint/lib/config/flat-config-array.js
rd565449 r0c6b92a 20 20 //----------------------------------------------------------------------------- 21 21 22 /** 23 * Fields that are considered metadata and not part of the config object. 24 */ 25 const META_FIELDS = new Set(["name"]); 26 22 27 const ruleValidator = new RuleValidator(); 23 28 … … 76 81 } 77 82 83 /** 84 * Wraps a config error with details about where the error occurred. 85 * @param {Error} error The original error. 86 * @param {number} originalLength The original length of the config array. 87 * @param {number} baseLength The length of the base config. 88 * @returns {TypeError} The new error with details. 89 */ 90 function wrapConfigErrorWithDetails(error, originalLength, baseLength) { 91 92 let location = "user-defined"; 93 let configIndex = error.index; 94 95 /* 96 * A config array is set up in this order: 97 * 1. Base config 98 * 2. Original configs 99 * 3. User-defined configs 100 * 4. CLI-defined configs 101 * 102 * So we need to adjust the index to account for the base config. 103 * 104 * - If the index is less than the base length, it's in the base config 105 * (as specified by `baseConfig` argument to `FlatConfigArray` constructor). 106 * - If the index is greater than the base length but less than the original 107 * length + base length, it's in the original config. The original config 108 * is passed to the `FlatConfigArray` constructor as the first argument. 109 * - Otherwise, it's in the user-defined config, which is loaded from the 110 * config file and merged with any command-line options. 111 */ 112 if (error.index < baseLength) { 113 location = "base"; 114 } else if (error.index < originalLength + baseLength) { 115 location = "original"; 116 configIndex = error.index - baseLength; 117 } else { 118 configIndex = error.index - originalLength - baseLength; 119 } 120 121 return new TypeError( 122 `${error.message.slice(0, -1)} at ${location} index ${configIndex}.`, 123 { cause: error } 124 ); 125 } 126 78 127 const originalBaseConfig = Symbol("originalBaseConfig"); 128 const originalLength = Symbol("originalLength"); 129 const baseLength = Symbol("baseLength"); 79 130 80 131 //----------------------------------------------------------------------------- … … 103 154 }); 104 155 156 /** 157 * The original length of the array before any modifications. 158 * @type {number} 159 */ 160 this[originalLength] = this.length; 161 105 162 if (baseConfig[Symbol.iterator]) { 106 163 this.unshift(...baseConfig); … … 108 165 this.unshift(baseConfig); 109 166 } 167 168 /** 169 * The length of the array after applying the base config. 170 * @type {number} 171 */ 172 this[baseLength] = this.length - this[originalLength]; 110 173 111 174 /** … … 126 189 } 127 190 191 /** 192 * Normalizes the array by calling the superclass method and catching/rethrowing 193 * any ConfigError exceptions with additional details. 194 * @param {any} [context] The context to use to normalize the array. 195 * @returns {Promise<FlatConfigArray>} A promise that resolves when the array is normalized. 196 */ 197 normalize(context) { 198 return super.normalize(context) 199 .catch(error => { 200 if (error.name === "ConfigError") { 201 throw wrapConfigErrorWithDetails(error, this[originalLength], this[baseLength]); 202 } 203 204 throw error; 205 206 }); 207 } 208 209 /** 210 * Normalizes the array by calling the superclass method and catching/rethrowing 211 * any ConfigError exceptions with additional details. 212 * @param {any} [context] The context to use to normalize the array. 213 * @returns {FlatConfigArray} The current instance. 214 * @throws {TypeError} If the config is invalid. 215 */ 216 normalizeSync(context) { 217 218 try { 219 220 return super.normalizeSync(context); 221 222 } catch (error) { 223 224 if (error.name === "ConfigError") { 225 throw wrapConfigErrorWithDetails(error, this[originalLength], this[baseLength]); 226 } 227 228 throw error; 229 230 } 231 232 } 233 128 234 /* eslint-disable class-methods-use-this -- Desired as instance method */ 129 235 /** … … 156 262 157 263 /* 158 * If `shouldIgnore` is false, we remove any ignore patterns specified159 * in the config so long as it's not a default config and it doesn't160 * have a `files` entry.264 * If a config object has `ignores` and no other non-meta fields, then it's an object 265 * for global ignores. If `shouldIgnore` is false, that object shouldn't apply, 266 * so we'll remove its `ignores`. 161 267 */ 162 268 if ( … … 164 270 !this[originalBaseConfig].includes(config) && 165 271 config.ignores && 166 !config.files272 Object.keys(config).filter(key => !META_FIELDS.has(key)).length === 1 167 273 ) { 168 274 /* eslint-disable-next-line no-unused-vars -- need to strip off other keys */
Note:
See TracChangeset
for help on using the changeset viewer.