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

Pred finalna verzija

Location:
imaps-frontend/node_modules/eslint/lib
Files:
5 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 */
  • imaps-frontend/node_modules/eslint/lib/eslint/eslint-helpers.js

    rd565449 r0c6b92a  
    1616const hash = require("../cli-engine/hash");
    1717const minimatch = require("minimatch");
    18 const util = require("util");
    1918const fswalk = require("@nodelib/fs.walk");
    2019const globParent = require("glob-parent");
     
    2524//-----------------------------------------------------------------------------
    2625
    27 const doFsWalk = util.promisify(fswalk.walk);
    2826const Minimatch = minimatch.Minimatch;
    2927const MINIMATCH_OPTIONS = { dot: true };
     
    271269    const unmatchedPatterns = new Set([...relativeToPatterns.keys()]);
    272270
    273     const filePaths = (await doFsWalk(basePath, {
    274 
    275         deepFilter(entry) {
    276             const relativePath = normalizeToPosix(path.relative(basePath, entry.path));
    277             const matchesPattern = matchers.some(matcher => matcher.match(relativePath, true));
    278 
    279             return matchesPattern && !configs.isDirectoryIgnored(entry.path);
    280         },
    281         entryFilter(entry) {
    282             const relativePath = normalizeToPosix(path.relative(basePath, entry.path));
    283 
    284             // entries may be directories or files so filter out directories
    285             if (entry.dirent.isDirectory()) {
     271    const filePaths = (await new Promise((resolve, reject) => {
     272
     273        let promiseRejected = false;
     274
     275        /**
     276         * Wraps a boolean-returning filter function. The wrapped function will reject the promise if an error occurs.
     277         * @param {Function} filter A filter function to wrap.
     278         * @returns {Function} A function similar to the wrapped filter that rejects the promise if an error occurs.
     279         */
     280        function wrapFilter(filter) {
     281            return (...args) => {
     282
     283                // No need to run the filter if an error has been thrown.
     284                if (!promiseRejected) {
     285                    try {
     286                        return filter(...args);
     287                    } catch (error) {
     288                        promiseRejected = true;
     289                        reject(error);
     290                    }
     291                }
    286292                return false;
     293            };
     294        }
     295
     296        fswalk.walk(
     297            basePath,
     298            {
     299                deepFilter: wrapFilter(entry => {
     300                    const relativePath = normalizeToPosix(path.relative(basePath, entry.path));
     301                    const matchesPattern = matchers.some(matcher => matcher.match(relativePath, true));
     302
     303                    return matchesPattern && !configs.isDirectoryIgnored(entry.path);
     304                }),
     305                entryFilter: wrapFilter(entry => {
     306                    const relativePath = normalizeToPosix(path.relative(basePath, entry.path));
     307
     308                    // entries may be directories or files so filter out directories
     309                    if (entry.dirent.isDirectory()) {
     310                        return false;
     311                    }
     312
     313                    /*
     314                     * Optimization: We need to track when patterns are left unmatched
     315                     * and so we use `unmatchedPatterns` to do that. There is a bit of
     316                     * complexity here because the same file can be matched by more than
     317                     * one pattern. So, when we start, we actually need to test every
     318                     * pattern against every file. Once we know there are no remaining
     319                     * unmatched patterns, then we can switch to just looking for the
     320                     * first matching pattern for improved speed.
     321                     */
     322                    const matchesPattern = unmatchedPatterns.size > 0
     323                        ? matchers.reduce((previousValue, matcher) => {
     324                            const pathMatches = matcher.match(relativePath);
     325
     326                            /*
     327                             * We updated the unmatched patterns set only if the path
     328                             * matches and the file isn't ignored. If the file is
     329                             * ignored, that means there wasn't a match for the
     330                             * pattern so it should not be removed.
     331                             *
     332                             * Performance note: isFileIgnored() aggressively caches
     333                             * results so there is no performance penalty for calling
     334                             * it twice with the same argument.
     335                             */
     336                            if (pathMatches && !configs.isFileIgnored(entry.path)) {
     337                                unmatchedPatterns.delete(matcher.pattern);
     338                            }
     339
     340                            return pathMatches || previousValue;
     341                        }, false)
     342                        : matchers.some(matcher => matcher.match(relativePath));
     343
     344                    return matchesPattern && !configs.isFileIgnored(entry.path);
     345                })
     346            },
     347            (error, entries) => {
     348
     349                // If the promise is already rejected, calling `resolve` or `reject` will do nothing.
     350                if (error) {
     351                    reject(error);
     352                } else {
     353                    resolve(entries);
     354                }
    287355            }
    288 
    289             /*
    290              * Optimization: We need to track when patterns are left unmatched
    291              * and so we use `unmatchedPatterns` to do that. There is a bit of
    292              * complexity here because the same file can be matched by more than
    293              * one pattern. So, when we start, we actually need to test every
    294              * pattern against every file. Once we know there are no remaining
    295              * unmatched patterns, then we can switch to just looking for the
    296              * first matching pattern for improved speed.
    297              */
    298             const matchesPattern = unmatchedPatterns.size > 0
    299                 ? matchers.reduce((previousValue, matcher) => {
    300                     const pathMatches = matcher.match(relativePath);
    301 
    302                     /*
    303                      * We updated the unmatched patterns set only if the path
    304                      * matches and the file isn't ignored. If the file is
    305                      * ignored, that means there wasn't a match for the
    306                      * pattern so it should not be removed.
    307                      *
    308                      * Performance note: isFileIgnored() aggressively caches
    309                      * results so there is no performance penalty for calling
    310                      * it twice with the same argument.
    311                      */
    312                     if (pathMatches && !configs.isFileIgnored(entry.path)) {
    313                         unmatchedPatterns.delete(matcher.pattern);
    314                     }
    315 
    316                     return pathMatches || previousValue;
    317                 }, false)
    318                 : matchers.some(matcher => matcher.match(relativePath));
    319 
    320             return matchesPattern && !configs.isFileIgnored(entry.path);
    321         }
    322 
     356        );
    323357    })).map(entry => entry.path);
    324358
     
    451485    }
    452486
    453     return [...new Set(filePaths)];
     487    return filePaths;
    454488
    455489}
     
    500534            // files are added directly to the list
    501535            if (stat.isFile()) {
    502                 results.push({
    503                     filePath,
    504                     ignored: configs.isFileIgnored(filePath)
    505                 });
     536                results.push(filePath);
    506537            }
    507538
     
    561592
    562593    return [
    563         ...results,
    564         ...globbyResults.map(filePath => ({
    565             filePath: path.resolve(filePath),
    566             ignored: false
    567         }))
     594        ...new Set([
     595            ...results,
     596            ...globbyResults.map(filePath => path.resolve(filePath))
     597        ])
    568598    ];
    569599}
  • imaps-frontend/node_modules/eslint/lib/eslint/flat-eslint.js

    rd565449 r0c6b92a  
    490490             */
    491491            filterCodeBlock(blockFilename) {
    492                 return configs.isExplicitMatch(blockFilename);
     492                return configs.getConfig(blockFilename) !== void 0;
    493493            }
    494494        }
     
    540540function createExtraneousResultsError() {
    541541    return new TypeError("Results object was not created from this ESLint instance.");
     542}
     543
     544/**
     545 * Creates a fixer function based on the provided fix, fixTypesSet, and config.
     546 * @param {Function|boolean} fix The original fix option.
     547 * @param {Set<string>} fixTypesSet A set of fix types to filter messages for fixing.
     548 * @param {FlatConfig} config The config for the file that generated the message.
     549 * @returns {Function|boolean} The fixer function or the original fix value.
     550 */
     551function getFixerForFixTypes(fix, fixTypesSet, config) {
     552    if (!fix || !fixTypesSet) {
     553        return fix;
     554    }
     555
     556    const originalFix = (typeof fix === "function") ? fix : () => true;
     557
     558    return message => shouldMessageBeFixed(message, config, fixTypesSet) && originalFix(message);
    542559}
    543560
     
    791808        const results = await Promise.all(
    792809
    793             filePaths.map(({ filePath, ignored }) => {
     810            filePaths.map(filePath => {
     811
     812                const config = configs.getConfig(filePath);
    794813
    795814                /*
    796                  * If a filename was entered that matches an ignore
    797                  * pattern, then notify the user.
     815                 * If a filename was entered that cannot be matched
     816                 * to a config, then notify the user.
    798817                 */
    799                 if (ignored) {
     818                if (!config) {
    800819                    if (warnIgnored) {
    801820                        return createIgnoreResult(filePath, cwd);
    802821                    }
    803822
    804                     return void 0;
    805                 }
    806 
    807                 const config = configs.getConfig(filePath);
    808 
    809                 /*
    810                  * Sometimes a file found through a glob pattern will
    811                  * be ignored. In this case, `config` will be undefined
    812                  * and we just silently ignore the file.
    813                  */
    814                 if (!config) {
    815823                    return void 0;
    816824                }
     
    837845
    838846                // set up fixer for fixTypes if necessary
    839                 let fixer = fix;
    840 
    841                 if (fix && fixTypesSet) {
    842 
    843                     // save original value of options.fix in case it's a function
    844                     const originalFix = (typeof fix === "function")
    845                         ? fix : () => true;
    846 
    847                     fixer = message => shouldMessageBeFixed(message, config, fixTypesSet) && originalFix(message);
    848                 }
     847                const fixer = getFixerForFixTypes(fix, fixTypesSet, config);
    849848
    850849                return fs.readFile(filePath, "utf8")
     
    943942            cwd,
    944943            fix,
     944            fixTypes,
    945945            warnIgnored: constructorWarnIgnored
    946946        } = eslintOptions;
    947947        const results = [];
    948948        const startTime = Date.now();
     949        const fixTypesSet = fixTypes ? new Set(fixTypes) : null;
    949950        const resolvedFilename = path.resolve(cwd, filePath || "__placeholder__.js");
     951        const config = configs.getConfig(resolvedFilename);
     952
     953        const fixer = getFixerForFixTypes(fix, fixTypesSet, config);
    950954
    951955        // Clear the last used config arrays.
     
    964968                configs,
    965969                cwd,
    966                 fix,
     970                fix: fixer,
    967971                allowInlineConfig,
    968972                linter
  • imaps-frontend/node_modules/eslint/lib/linter/linter.js

    rd565449 r0c6b92a  
    734734function resolveGlobals(providedGlobals, enabledEnvironments) {
    735735    return Object.assign(
    736         {},
     736        Object.create(null),
    737737        ...enabledEnvironments.filter(env => env.globals).map(env => env.globals),
    738738        providedGlobals
  • imaps-frontend/node_modules/eslint/lib/source-code/source-code.js

    rd565449 r0c6b92a  
    935935         */
    936936        const configGlobals = Object.assign(
    937             {},
     937            Object.create(null), // https://github.com/eslint/eslint/issues/18363
    938938            getGlobalsForEcmaVersion(languageOptions.ecmaVersion),
    939939            languageOptions.sourceType === "commonjs" ? globals.commonjs : void 0,
Note: See TracChangeset for help on using the changeset viewer.