Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/node_modules/eslint/lib/config/flat-config-array.js

    rd565449 r0c6b92a  
    2020//-----------------------------------------------------------------------------
    2121
     22/**
     23 * Fields that are considered metadata and not part of the config object.
     24 */
     25const META_FIELDS = new Set(["name"]);
     26
    2227const ruleValidator = new RuleValidator();
    2328
     
    7681}
    7782
     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 */
     90function 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
    78127const originalBaseConfig = Symbol("originalBaseConfig");
     128const originalLength = Symbol("originalLength");
     129const baseLength = Symbol("baseLength");
    79130
    80131//-----------------------------------------------------------------------------
     
    103154        });
    104155
     156        /**
     157         * The original length of the array before any modifications.
     158         * @type {number}
     159         */
     160        this[originalLength] = this.length;
     161
    105162        if (baseConfig[Symbol.iterator]) {
    106163            this.unshift(...baseConfig);
     
    108165            this.unshift(baseConfig);
    109166        }
     167
     168        /**
     169         * The length of the array after applying the base config.
     170         * @type {number}
     171         */
     172        this[baseLength] = this.length - this[originalLength];
    110173
    111174        /**
     
    126189    }
    127190
     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
    128234    /* eslint-disable class-methods-use-this -- Desired as instance method */
    129235    /**
     
    156262
    157263        /*
    158          * If `shouldIgnore` is false, we remove any ignore patterns specified
    159          * in the config so long as it's not a default config and it doesn't
    160          * 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`.
    161267         */
    162268        if (
     
    164270            !this[originalBaseConfig].includes(config) &&
    165271            config.ignores &&
    166             !config.files
     272            Object.keys(config).filter(key => !META_FIELDS.has(key)).length === 1
    167273        ) {
    168274            /* eslint-disable-next-line no-unused-vars -- need to strip off other keys */
Note: See TracChangeset for help on using the changeset viewer.