Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2024-08-26 17:13:37 +00:00
parent fa428daf9c
commit b3bf514df4
216 changed files with 4342 additions and 1611 deletions

View file

@ -2,10 +2,6 @@
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "lcov", "text", "html", "json"],
"require": [
"babel-register"
],
"sourceMap": true,
"instrument": false,
"exclude": [
"coverage",

View file

@ -5,6 +5,25 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
## Unreleased
## v2.8.2 - 2024-08-25
### Fixed
- `parse`: also delete `parserOptions.projectService` ([#3039], thanks [@Mysak0CZ])
### Changed
- [types] use shared config (thanks [@ljharb])
- [meta] add `exports`, `main`
- [meta] add `repository.directory` field
- [refactor] avoid hoisting
## v2.8.1 - 2024-02-26
### Fixed
- `parse`: also delete `parserOptions.EXPERIMENTAL_useProjectService` ([#2963], thanks [@JoshuaKGoldberg])
### Changed
- add types (thanks [@ljharb])
## v2.8.0 - 2023-04-14
### New
@ -131,6 +150,8 @@ Yanked due to critical issue with cache key resulting from #839.
### Fixed
- `unambiguous.test()` regex is now properly in multiline mode
[#3039]: https://github.com/import-js/eslint-plugin-import/pull/3039
[#2963]: https://github.com/import-js/eslint-plugin-import/pull/2963
[#2755]: https://github.com/import-js/eslint-plugin-import/pull/2755
[#2714]: https://github.com/import-js/eslint-plugin-import/pull/2714
[#2523]: https://github.com/import-js/eslint-plugin-import/pull/2523
@ -169,12 +190,14 @@ Yanked due to critical issue with cache key resulting from #839.
[@hulkish]: https://github.com/hulkish
[@Hypnosphi]: https://github.com/Hypnosphi
[@iamnapo]: https://github.com/iamnapo
[@JoshuaKGoldberg]: https://github.com/JoshuaKGoldberg
[@JounQin]: https://github.com/JounQin
[@kaiyoma]: https://github.com/kaiyoma
[@leipert]: https://github.com/leipert
[@manuth]: https://github.com/manuth
[@maxkomarychev]: https://github.com/maxkomarychev
[@mgwalker]: https://github.com/mgwalker
[@Mysak0CZ]: https://github.com/Mysak0CZ
[@nicolo-ribaudo]: https://github.com/nicolo-ribaudo
[@pmcelhaney]: https://github.com/pmcelhaney
[@sergei-startsev]: https://github.com/sergei-startsev

22
node_modules/eslint-module-utils/ModuleCache.d.ts generated vendored Normal file
View file

@ -0,0 +1,22 @@
import type { ESLintSettings } from "./types";
export type CacheKey = unknown;
export type CacheObject = {
result: unknown;
lastSeen: ReturnType<typeof process.hrtime>;
};
declare class ModuleCache {
map: Map<CacheKey, CacheObject>;
constructor(map?: Map<CacheKey, CacheObject>);
get<T>(cacheKey: CacheKey, settings: ESLintSettings): T | undefined;
set<T>(cacheKey: CacheKey, result: T): T;
static getSettings(settings: ESLintSettings): { lifetime: number } & Omit<ESLintSettings['import/cache'], 'lifetime'>;
}
export default ModuleCache;
export type { ModuleCache }

View file

@ -4,26 +4,26 @@ exports.__esModule = true;
const log = require('debug')('eslint-module-utils:ModuleCache');
/** @type {import('./ModuleCache').ModuleCache} */
class ModuleCache {
/** @param {typeof import('./ModuleCache').ModuleCache.prototype.map} map */
constructor(map) {
this.map = map || new Map();
this.map = map || /** @type {{typeof import('./ModuleCache').ModuleCache.prototype.map} */ new Map();
}
/**
* returns value for returning inline
* @param {[type]} cacheKey [description]
* @param {[type]} result [description]
*/
/** @type {typeof import('./ModuleCache').ModuleCache.prototype.set} */
set(cacheKey, result) {
this.map.set(cacheKey, { result, lastSeen: process.hrtime() });
log('setting entry for', cacheKey);
return result;
}
/** @type {typeof import('./ModuleCache').ModuleCache.prototype.get} */
get(cacheKey, settings) {
if (this.map.has(cacheKey)) {
const f = this.map.get(cacheKey);
// check freshness
// @ts-expect-error TS can't narrow properly from `has` and `get`
if (process.hrtime(f.lastSeen)[0] < settings.lifetime) { return f.result; }
} else {
log('cache miss for', cacheKey);
@ -32,19 +32,21 @@ class ModuleCache {
return undefined;
}
/** @type {typeof import('./ModuleCache').ModuleCache.getSettings} */
static getSettings(settings) {
/** @type {ReturnType<typeof ModuleCache.getSettings>} */
const cacheSettings = Object.assign({
lifetime: 30, // seconds
}, settings['import/cache']);
// parse infinity
// @ts-expect-error the lack of type overlap is because we're abusing `cacheSettings` as a temporary object
if (cacheSettings.lifetime === '∞' || cacheSettings.lifetime === 'Infinity') {
cacheSettings.lifetime = Infinity;
}
return cacheSettings;
}
}
ModuleCache.getSettings = function (settings) {
const cacheSettings = Object.assign({
lifetime: 30, // seconds
}, settings['import/cache']);
// parse infinity
if (cacheSettings.lifetime === '∞' || cacheSettings.lifetime === 'Infinity') {
cacheSettings.lifetime = Infinity;
}
return cacheSettings;
};
exports.default = ModuleCache;

8
node_modules/eslint-module-utils/declaredScope.d.ts generated vendored Normal file
View file

@ -0,0 +1,8 @@
import { Rule, Scope } from 'eslint';
declare function declaredScope(
context: Rule.RuleContext,
name: string
): Scope.Scope['type'] | undefined;
export default declaredScope;

View file

@ -2,9 +2,10 @@
exports.__esModule = true;
/** @type {import('./declaredScope').default} */
exports.default = function declaredScope(context, name) {
const references = context.getScope().references;
const reference = references.find((x) => x.identifier.name === name);
if (!reference) { return undefined; }
if (!reference || !reference.resolved) { return undefined; }
return reference.resolved.scope.type;
};

14
node_modules/eslint-module-utils/hash.d.ts generated vendored Normal file
View file

@ -0,0 +1,14 @@
import type { Hash } from 'crypto';
declare function hashArray(value: Array<unknown>, hash?: Hash): Hash;
declare function hashObject<T extends object>(value: T, hash?: Hash): Hash;
declare function hashify(
value: Array<unknown> | object | unknown,
hash?: Hash,
): Hash;
export default hashify;
export { hashArray, hashObject };

View file

@ -11,6 +11,7 @@ const createHash = require('crypto').createHash;
const stringify = JSON.stringify;
/** @type {import('./hash').default} */
function hashify(value, hash) {
if (!hash) { hash = createHash('sha256'); }
@ -26,6 +27,7 @@ function hashify(value, hash) {
}
exports.default = hashify;
/** @type {import('./hash').hashArray} */
function hashArray(array, hash) {
if (!hash) { hash = createHash('sha256'); }
@ -41,13 +43,15 @@ function hashArray(array, hash) {
hashify.array = hashArray;
exports.hashArray = hashArray;
function hashObject(object, hash) {
if (!hash) { hash = createHash('sha256'); }
/** @type {import('./hash').hashObject} */
function hashObject(object, optionalHash) {
const hash = optionalHash || createHash('sha256');
hash.update('{');
Object.keys(object).sort().forEach((key) => {
hash.update(stringify(key));
hash.update(':');
// @ts-expect-error the key is guaranteed to exist on the object here
hashify(object[key], hash);
hash.update(',');
});

12
node_modules/eslint-module-utils/ignore.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
import { Rule } from 'eslint';
import type { ESLintSettings, Extension } from './types';
declare function ignore(path: string, context: Rule.RuleContext): boolean;
declare function getFileExtensions(settings: ESLintSettings): Set<Extension>;
declare function hasValidExtension(path: string, context: Rule.RuleContext): path is `${string}${Extension}`;
export default ignore;
export { getFileExtensions, hasValidExtension }

View file

@ -7,20 +7,14 @@ const extname = require('path').extname;
const log = require('debug')('eslint-plugin-import:utils:ignore');
// one-shot memoized
let cachedSet; let lastSettings;
function validExtensions(context) {
if (cachedSet && context.settings === lastSettings) {
return cachedSet;
}
lastSettings = context.settings;
cachedSet = makeValidExtensionSet(context.settings);
return cachedSet;
}
/** @type {Set<import('./types').Extension>} */ let cachedSet;
/** @type {import('./types').ESLintSettings} */ let lastSettings;
/** @type {import('./ignore').getFileExtensions} */
function makeValidExtensionSet(settings) {
// start with explicit JS-parsed extensions
const exts = new Set(settings['import/extensions'] || [ '.js' ]);
/** @type {Set<import('./types').Extension>} */
const exts = new Set(settings['import/extensions'] || ['.js']);
// all alternate parser extensions are also valid
if ('import/parsers' in settings) {
@ -37,6 +31,25 @@ function makeValidExtensionSet(settings) {
}
exports.getFileExtensions = makeValidExtensionSet;
/** @type {(context: import('eslint').Rule.RuleContext) => Set<import('./types').Extension>} */
function validExtensions(context) {
if (cachedSet && context.settings === lastSettings) {
return cachedSet;
}
lastSettings = context.settings;
cachedSet = makeValidExtensionSet(context.settings);
return cachedSet;
}
/** @type {import('./ignore').hasValidExtension} */
function hasValidExtension(path, context) {
// eslint-disable-next-line no-extra-parens
return validExtensions(context).has(/** @type {import('./types').Extension} */ (extname(path)));
}
exports.hasValidExtension = hasValidExtension;
/** @type {import('./ignore').default} */
exports.default = function ignore(path, context) {
// check extension whitelist first (cheap)
if (!hasValidExtension(path, context)) { return true; }
@ -54,8 +67,3 @@ exports.default = function ignore(path, context) {
return false;
};
function hasValidExtension(path, context) {
return validExtensions(context).has(extname(path));
}
exports.hasValidExtension = hasValidExtension;

3
node_modules/eslint-module-utils/module-require.d.ts generated vendored Normal file
View file

@ -0,0 +1,3 @@
declare function moduleRequire<T>(p: string): T;
export default moduleRequire;

View file

@ -6,23 +6,28 @@ const Module = require('module');
const path = require('path');
// borrowed from babel-eslint
/** @type {(filename: string) => Module} */
function createModule(filename) {
const mod = new Module(filename);
mod.filename = filename;
// @ts-expect-error _nodeModulesPaths are undocumented
mod.paths = Module._nodeModulePaths(path.dirname(filename));
return mod;
}
/** @type {import('./module-require').default} */
exports.default = function moduleRequire(p) {
try {
// attempt to get espree relative to eslint
const eslintPath = require.resolve('eslint');
const eslintModule = createModule(eslintPath);
// @ts-expect-error _resolveFilename is undocumented
return require(Module._resolveFilename(p, eslintModule));
} catch (err) { /* ignore */ }
try {
// try relative to entry point
// @ts-expect-error TODO: figure out what this is
return require.main.require(p);
} catch (err) { /* ignore */ }

26
node_modules/eslint-module-utils/moduleVisitor.d.ts generated vendored Normal file
View file

@ -0,0 +1,26 @@
import type { Rule } from 'eslint';
import type { Node } from 'estree';
type Visitor = (source: Node, importer: unknown) => any;
type Options = {
amd?: boolean;
commonjs?: boolean;
esmodule?: boolean;
ignore?: string[];
};
declare function moduleVisitor(
visitor: Visitor,
options?: Options,
): object;
export default moduleVisitor;
export type Schema = NonNullable<Rule.RuleModule['schema']>;
declare function makeOptionsSchema(additionalProperties?: Partial<Schema>): Schema
declare const optionsSchema: Schema;
export { makeOptionsSchema, optionsSchema };

View file

@ -2,50 +2,58 @@
exports.__esModule = true;
/** @typedef {import('estree').Node} Node */
/** @typedef {{ arguments: import('estree').CallExpression['arguments'], callee: Node }} Call */
/** @typedef {import('estree').ImportDeclaration | import('estree').ExportNamedDeclaration | import('estree').ExportAllDeclaration} Declaration */
/**
* Returns an object of node visitors that will call
* 'visitor' with every discovered module path.
*
* todo: correct function prototype for visitor
* @param {Function(String)} visitor [description]
* @param {[type]} options [description]
* @return {object}
* @type {(import('./moduleVisitor').default)}
*/
exports.default = function visitModules(visitor, options) {
const ignore = options && options.ignore;
const amd = !!(options && options.amd);
const commonjs = !!(options && options.commonjs);
// if esmodule is not explicitly disabled, it is assumed to be enabled
options = Object.assign({ esmodule: true }, options);
const esmodule = !!Object.assign({ esmodule: true }, options).esmodule;
let ignoreRegExps = [];
if (options.ignore != null) {
ignoreRegExps = options.ignore.map((p) => new RegExp(p));
}
const ignoreRegExps = ignore == null ? [] : ignore.map((p) => new RegExp(p));
/** @type {(source: undefined | null | import('estree').Literal, importer: Parameters<typeof visitor>[1]) => void} */
function checkSourceValue(source, importer) {
if (source == null) { return; } //?
// handle ignore
if (ignoreRegExps.some((re) => re.test(source.value))) { return; }
if (ignoreRegExps.some((re) => re.test(String(source.value)))) { return; }
// fire visitor
visitor(source, importer);
}
// for import-y declarations
/** @type {(node: Declaration) => void} */
function checkSource(node) {
checkSourceValue(node.source, node);
}
// for esmodule dynamic `import()` calls
/** @type {(node: import('estree').ImportExpression | import('estree').CallExpression) => void} */
function checkImportCall(node) {
/** @type {import('estree').Expression | import('estree').Literal | import('estree').CallExpression['arguments'][0]} */
let modulePath;
// refs https://github.com/estree/estree/blob/HEAD/es2020.md#importexpression
if (node.type === 'ImportExpression') {
modulePath = node.source;
} else if (node.type === 'CallExpression') {
// @ts-expect-error this structure is from an older version of eslint
if (node.callee.type !== 'Import') { return; }
if (node.arguments.length !== 1) { return; }
modulePath = node.arguments[0];
} else {
throw new TypeError('this should be unreachable');
}
if (modulePath.type !== 'Literal') { return; }
@ -56,6 +64,7 @@ exports.default = function visitModules(visitor, options) {
// for CommonJS `require` calls
// adapted from @mctep: https://git.io/v4rAu
/** @type {(call: Call) => void} */
function checkCommon(call) {
if (call.callee.type !== 'Identifier') { return; }
if (call.callee.name !== 'require') { return; }
@ -68,6 +77,7 @@ exports.default = function visitModules(visitor, options) {
checkSourceValue(modulePath, call);
}
/** @type {(call: Call) => void} */
function checkAMD(call) {
if (call.callee.type !== 'Identifier') { return; }
if (call.callee.name !== 'require' && call.callee.name !== 'define') { return; }
@ -77,6 +87,7 @@ exports.default = function visitModules(visitor, options) {
if (modules.type !== 'ArrayExpression') { return; }
for (const element of modules.elements) {
if (!element) { continue; }
if (element.type !== 'Literal') { continue; }
if (typeof element.value !== 'string') { continue; }
@ -92,7 +103,7 @@ exports.default = function visitModules(visitor, options) {
}
const visitors = {};
if (options.esmodule) {
if (esmodule) {
Object.assign(visitors, {
ImportDeclaration: checkSource,
ExportNamedDeclaration: checkSource,
@ -102,12 +113,12 @@ exports.default = function visitModules(visitor, options) {
});
}
if (options.commonjs || options.amd) {
if (commonjs || amd) {
const currentCallExpression = visitors.CallExpression;
visitors.CallExpression = function (call) {
visitors.CallExpression = /** @type {(call: Call) => void} */ function (call) {
if (currentCallExpression) { currentCallExpression(call); }
if (options.commonjs) { checkCommon(call); }
if (options.amd) { checkAMD(call); }
if (commonjs) { checkCommon(call); }
if (amd) { checkAMD(call); }
};
}
@ -115,10 +126,11 @@ exports.default = function visitModules(visitor, options) {
};
/**
* make an options schema for the module visitor, optionally
* adding extra fields.
* make an options schema for the module visitor, optionally adding extra fields.
* @type {import('./moduleVisitor').makeOptionsSchema}
*/
function makeOptionsSchema(additionalProperties) {
/** @type {import('./moduleVisitor').Schema} */
const base = {
type: 'object',
properties: {
@ -137,6 +149,7 @@ function makeOptionsSchema(additionalProperties) {
if (additionalProperties) {
for (const key in additionalProperties) {
// @ts-expect-error TS always has trouble with arbitrary object assignment/mutation
base.properties[key] = additionalProperties[key];
}
}
@ -146,8 +159,6 @@ function makeOptionsSchema(additionalProperties) {
exports.makeOptionsSchema = makeOptionsSchema;
/**
* json schema object for options parameter. can be used to build
* rule options schema object.
* @type {Object}
* json schema object for options parameter. can be used to build rule options schema object.
*/
exports.optionsSchema = makeOptionsSchema();

View file

@ -1,17 +1,50 @@
{
"name": "eslint-module-utils",
"version": "2.8.0",
"version": "2.8.2",
"description": "Core utilities to support eslint-plugin-import and other module-related plugins.",
"engines": {
"node": ">=4"
},
"main": false,
"exports": {
"./ModuleCache": "./ModuleCache.js",
"./ModuleCache.js": "./ModuleCache.js",
"./declaredScope": "./declaredScope.js",
"./declaredScope.js": "./declaredScope.js",
"./hash": "./hash.js",
"./hash.js": "./hash.js",
"./ignore": "./ignore.js",
"./ignore.js": "./ignore.js",
"./module-require": "./module-require.js",
"./module-require.js": "./module-require.js",
"./moduleVisitor": "./moduleVisitor.js",
"./moduleVisitor.js": "./moduleVisitor.js",
"./parse": "./parse.js",
"./parse.js": "./parse.js",
"./pkgDir": "./pkgDir.js",
"./pkgDir.js": "./pkgDir.js",
"./pkgUp": "./pkgUp.js",
"./pkgUp.js": "./pkgUp.js",
"./readPkgUp": "./readPkgUp.js",
"./readPkgUp.js": "./readPkgUp.js",
"./resolve": "./resolve.js",
"./resolve.js": "./resolve.js",
"./unambiguous": "./unambiguous.js",
"./unambiguous.js": "./unambiguous.js",
"./visit": "./visit.js",
"./visit.js": "./visit.js",
"./package.json": "./package.json"
},
"scripts": {
"prepublishOnly": "cp ../{LICENSE,.npmrc} ./",
"tsc": "tsc -p .",
"posttsc": "attw -P .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/import-js/eslint-plugin-import.git"
"url": "git+https://github.com/import-js/eslint-plugin-import.git",
"directory": "utils"
},
"keywords": [
"eslint-plugin-import",
@ -28,9 +61,22 @@
"dependencies": {
"debug": "^3.2.7"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.4",
"@ljharb/tsconfig": "^0.2.0",
"@types/debug": "^4.1.12",
"@types/eslint": "^8.56.3",
"@types/node": "^20.11.20",
"typescript": "next"
},
"peerDependenciesMeta": {
"eslint": {
"optional": true
}
},
"publishConfig": {
"ignore": [
".attw.json"
]
}
}

11
node_modules/eslint-module-utils/parse.d.ts generated vendored Normal file
View file

@ -0,0 +1,11 @@
import { AST, Rule } from 'eslint';
declare function parse(
path: string,
content: string,
context: Rule.RuleContext
): AST.Program | null | undefined;
export default parse;

View file

@ -2,12 +2,16 @@
exports.__esModule = true;
/** @typedef {`.${string}`} Extension */
/** @typedef {NonNullable<import('eslint').Rule.RuleContext['settings']> & { 'import/extensions'?: Extension[], 'import/parsers'?: { [k: string]: Extension[] }, 'import/cache'?: { lifetime: number | '∞' | 'Infinity' } }} ESLintSettings */
const moduleRequire = require('./module-require').default;
const extname = require('path').extname;
const fs = require('fs');
const log = require('debug')('eslint-plugin-import:parse');
/** @type {(parserPath: NonNullable<import('eslint').Rule.RuleContext['parserPath']>) => unknown} */
function getBabelEslintVisitorKeys(parserPath) {
if (parserPath.endsWith('index.js')) {
const hypotheticalLocation = parserPath.replace('index.js', 'visitor-keys.js');
@ -19,6 +23,7 @@ function getBabelEslintVisitorKeys(parserPath) {
return null;
}
/** @type {(parserPath: import('eslint').Rule.RuleContext['parserPath'], parserInstance: { VisitorKeys: unknown }, parsedResult?: { visitorKeys?: unknown }) => unknown} */
function keysFromParser(parserPath, parserInstance, parsedResult) {
// Exposed by @typescript-eslint/parser and @babel/eslint-parser
if (parsedResult && parsedResult.visitorKeys) {
@ -35,22 +40,69 @@ function keysFromParser(parserPath, parserInstance, parsedResult) {
// this exists to smooth over the unintentional breaking change in v2.7.
// TODO, semver-major: avoid mutating `ast` and return a plain object instead.
/** @type {<T extends import('eslint').AST.Program>(ast: T, visitorKeys: unknown) => T} */
function makeParseReturn(ast, visitorKeys) {
if (ast) {
// @ts-expect-error see TODO
ast.visitorKeys = visitorKeys;
// @ts-expect-error see TODO
ast.ast = ast;
}
return ast;
}
/** @type {(text: string) => string} */
function stripUnicodeBOM(text) {
return text.charCodeAt(0) === 0xFEFF ? text.slice(1) : text;
}
/** @type {(text: string) => string} */
function transformHashbang(text) {
return text.replace(/^#!([^\r\n]+)/u, (_, captured) => `//${captured}`);
}
/** @type {(path: string, context: import('eslint').Rule.RuleContext & { settings?: ESLintSettings }) => import('eslint').Rule.RuleContext['parserPath']} */
function getParserPath(path, context) {
const parsers = context.settings['import/parsers'];
if (parsers != null) {
// eslint-disable-next-line no-extra-parens
const extension = /** @type {Extension} */ (extname(path));
for (const parserPath in parsers) {
if (parsers[parserPath].indexOf(extension) > -1) {
// use this alternate parser
log('using alt parser:', parserPath);
return parserPath;
}
}
}
// default to use ESLint parser
return context.parserPath;
}
/** @type {(path: string, context: import('eslint').Rule.RuleContext) => string | null | (import('eslint').Linter.ParserModule)} */
function getParser(path, context) {
const parserPath = getParserPath(path, context);
if (parserPath) {
return parserPath;
}
if (
!!context.languageOptions
&& !!context.languageOptions.parser
&& typeof context.languageOptions.parser !== 'string'
&& (
// @ts-expect-error TODO: figure out a better type
typeof context.languageOptions.parser.parse === 'function'
// @ts-expect-error TODO: figure out a better type
|| typeof context.languageOptions.parser.parseForESLint === 'function'
)
) {
return context.languageOptions.parser;
}
return null;
}
/** @type {import('./parse').default} */
exports.default = function parse(path, content, context) {
if (context == null) { throw new Error('need context to parse properly'); }
@ -81,6 +133,8 @@ exports.default = function parse(path, content, context) {
// "project" or "projects" in parserOptions. Removing these options means the parser will
// only parse one file in isolate mode, which is much, much faster.
// https://github.com/import-js/eslint-plugin-import/issues/1408#issuecomment-509298962
delete parserOptions.EXPERIMENTAL_useProjectService;
delete parserOptions.projectService;
delete parserOptions.project;
delete parserOptions.projects;
@ -96,10 +150,12 @@ exports.default = function parse(path, content, context) {
try {
const parserRaw = parser.parseForESLint(content, parserOptions);
ast = parserRaw.ast;
// @ts-expect-error TODO: FIXME
return makeParseReturn(ast, keysFromParser(parserOrPath, parser, parserRaw));
} catch (e) {
console.warn();
console.warn('Error while parsing ' + parserOptions.filePath);
// @ts-expect-error e is almost certainly an Error here
console.warn('Line ' + e.lineNumber + ', column ' + e.column + ': ' + e.message);
}
if (!ast || typeof ast !== 'object') {
@ -108,42 +164,12 @@ exports.default = function parse(path, content, context) {
'`parseForESLint` from parser `' + (typeof parserOrPath === 'string' ? parserOrPath : '`context.languageOptions.parser`') + '` is invalid and will just be ignored'
);
} else {
// @ts-expect-error TODO: FIXME
return makeParseReturn(ast, keysFromParser(parserOrPath, parser, undefined));
}
}
const ast = parser.parse(content, parserOptions);
// @ts-expect-error TODO: FIXME
return makeParseReturn(ast, keysFromParser(parserOrPath, parser, undefined));
};
function getParser(path, context) {
const parserPath = getParserPath(path, context);
if (parserPath) {
return parserPath;
}
const isFlat = context.languageOptions
&& context.languageOptions.parser
&& typeof context.languageOptions.parser !== 'string'
&& (
typeof context.languageOptions.parser.parse === 'function'
|| typeof context.languageOptions.parser.parseForESLint === 'function'
);
return isFlat ? context.languageOptions.parser : null;
}
function getParserPath(path, context) {
const parsers = context.settings['import/parsers'];
if (parsers != null) {
const extension = extname(path);
for (const parserPath in parsers) {
if (parsers[parserPath].indexOf(extension) > -1) {
// use this alternate parser
log('using alt parser:', parserPath);
return parserPath;
}
}
}
// default to use ESLint parser
return context.parserPath;
}

3
node_modules/eslint-module-utils/pkgDir.d.ts generated vendored Normal file
View file

@ -0,0 +1,3 @@
declare function pkgDir(cwd: string): string | null;
export default pkgDir;

View file

@ -5,6 +5,7 @@ const pkgUp = require('./pkgUp').default;
exports.__esModule = true;
/** @type {import('./pkgDir').default} */
exports.default = function (cwd) {
const fp = pkgUp({ cwd });
return fp ? path.dirname(fp) : null;

3
node_modules/eslint-module-utils/pkgUp.d.ts generated vendored Normal file
View file

@ -0,0 +1,3 @@
declare function pkgUp(opts?: { cwd?: string }): string | null;
export default pkgUp;

View file

@ -31,10 +31,13 @@ const path = require('path');
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/** @type {(filename: string | string[], cwd?: string) => string | null} */
function findUp(filename, cwd) {
let dir = path.resolve(cwd || '');
const root = path.parse(dir).root;
/** @type {string[]} */ // @ts-expect-error TS sucks with concat
const filenames = [].concat(filename);
// eslint-disable-next-line no-constant-condition
@ -52,6 +55,7 @@ function findUp(filename, cwd) {
}
}
/** @type {import('./pkgUp').default} */
exports.default = function pkgUp(opts) {
return findUp('package.json', opts && opts.cwd);
};

5
node_modules/eslint-module-utils/readPkgUp.d.ts generated vendored Normal file
View file

@ -0,0 +1,5 @@
import pkgUp from './pkgUp';
declare function readPkgUp(opts?: Parameters<typeof pkgUp>[0]): {} | { pkg: string, path: string };
export default readPkgUp;

View file

@ -5,6 +5,7 @@ exports.__esModule = true;
const fs = require('fs');
const pkgUp = require('./pkgUp').default;
/** @type {(str: string) => string} */
function stripBOM(str) {
return str.replace(/^\uFEFF/, '');
}
@ -35,6 +36,7 @@ function stripBOM(str) {
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/** @type {import('./readPkgUp').default} */
exports.default = function readPkgUp(opts) {
const fp = pkgUp(opts);

30
node_modules/eslint-module-utils/resolve.d.ts generated vendored Normal file
View file

@ -0,0 +1,30 @@
import type { Rule } from 'eslint';
import type ModuleCache from './ModuleCache';
import type { ESLintSettings } from './types';
export type ResultNotFound = { found: false, path?: undefined };
export type ResultFound = { found: true, path: string | null };
export type ResolvedResult = ResultNotFound | ResultFound;
export type ResolverResolve = (modulePath: string, sourceFile:string, config: unknown) => ResolvedResult;
export type ResolverResolveImport = (modulePath: string, sourceFile:string, config: unknown) => string | undefined;
export type Resolver = { interfaceVersion?: 1 | 2, resolve: ResolverResolve, resolveImport: ResolverResolveImport };
declare function resolve(
p: string,
context: Rule.RuleContext,
): ResolvedResult['path'];
export default resolve;
declare function fileExistsWithCaseSync(
filepath: string | null,
cacheSettings: ESLintSettings,
strict: boolean
): boolean | ReturnType<typeof ModuleCache.prototype.get>;
declare function relative(modulePath: string, sourceFile: string, settings: ESLintSettings): ResolvedResult['path'];
export { fileExistsWithCaseSync, relative };

View file

@ -19,16 +19,30 @@ const fileExistsCache = new ModuleCache();
// Polyfill Node's `Module.createRequireFromPath` if not present (added in Node v10.12.0)
// Use `Module.createRequire` if available (added in Node v12.2.0)
const createRequire = Module.createRequire || Module.createRequireFromPath || function (filename) {
const mod = new Module(filename, null);
mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename));
const createRequire = Module.createRequire
// @ts-expect-error this only exists in older node
|| Module.createRequireFromPath
|| /** @type {(filename: string) => unknown} */ function (filename) {
const mod = new Module(filename, void null);
mod.filename = filename;
// @ts-expect-error _nodeModulePaths is undocumented
mod.paths = Module._nodeModulePaths(path.dirname(filename));
mod._compile(`module.exports = require;`, filename);
// @ts-expect-error _compile is undocumented
mod._compile(`module.exports = require;`, filename);
return mod.exports;
};
return mod.exports;
};
/** @type {(resolver: object) => resolver is import('./resolve').Resolver} */
function isResolverValid(resolver) {
if ('interfaceVersion' in resolver && resolver.interfaceVersion === 2) {
return 'resolve' in resolver && !!resolver.resolve && typeof resolver.resolve === 'function';
}
return 'resolveImport' in resolver && !!resolver.resolveImport && typeof resolver.resolveImport === 'function';
}
/** @type {<T extends string>(target: T, sourceFile?: string | null | undefined) => undefined | ReturnType<typeof require>} */
function tryRequire(target, sourceFile) {
let resolved;
try {
@ -51,7 +65,58 @@ function tryRequire(target, sourceFile) {
return require(resolved);
}
/** @type {<T extends Map<string, unknown>>(resolvers: string[] | string | { [k: string]: string }, map: T) => T} */
function resolverReducer(resolvers, map) {
if (Array.isArray(resolvers)) {
resolvers.forEach((r) => resolverReducer(r, map));
return map;
}
if (typeof resolvers === 'string') {
map.set(resolvers, null);
return map;
}
if (typeof resolvers === 'object') {
for (const key in resolvers) {
map.set(key, resolvers[key]);
}
return map;
}
const err = new Error('invalid resolver config');
err.name = ERROR_NAME;
throw err;
}
/** @type {(sourceFile: string) => string} */
function getBaseDir(sourceFile) {
return pkgDir(sourceFile) || process.cwd();
}
/** @type {(name: string, sourceFile: string) => import('./resolve').Resolver} */
function requireResolver(name, sourceFile) {
// Try to resolve package with conventional name
const resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile)
|| tryRequire(name, sourceFile)
|| tryRequire(path.resolve(getBaseDir(sourceFile), name));
if (!resolver) {
const err = new Error(`unable to load resolver "${name}".`);
err.name = ERROR_NAME;
throw err;
}
if (!isResolverValid(resolver)) {
const err = new Error(`${name} with invalid interface loaded as resolver`);
err.name = ERROR_NAME;
throw err;
}
return resolver;
}
// https://stackoverflow.com/a/27382838
/** @type {import('./resolve').fileExistsWithCaseSync} */
exports.fileExistsWithCaseSync = function fileExistsWithCaseSync(filepath, cacheSettings, strict) {
// don't care if the FS is case-sensitive
if (CASE_SENSITIVE_FS) { return true; }
@ -80,12 +145,10 @@ exports.fileExistsWithCaseSync = function fileExistsWithCaseSync(filepath, cache
return result;
};
function relative(modulePath, sourceFile, settings) {
return fullResolve(modulePath, sourceFile, settings).path;
}
/** @type {import('./types').ESLintSettings | null} */
let prevSettings = null;
let memoizedHash = '';
/** @type {(modulePath: string, sourceFile: string, settings: import('./types').ESLintSettings) => import('./resolve').ResolvedResult} */
function fullResolve(modulePath, sourceFile, settings) {
// check if this is a bonus core module
const coreSet = new Set(settings['import/core-modules']);
@ -105,10 +168,12 @@ function fullResolve(modulePath, sourceFile, settings) {
const cachedPath = fileExistsCache.get(cacheKey, cacheSettings);
if (cachedPath !== undefined) { return { found: true, path: cachedPath }; }
/** @type {(resolvedPath: string | null) => void} */
function cache(resolvedPath) {
fileExistsCache.set(cacheKey, resolvedPath);
}
/** @type {(resolver: import('./resolve').Resolver, config: unknown) => import('./resolve').ResolvedResult} */
function withResolver(resolver, config) {
if (resolver.interfaceVersion === 2) {
return resolver.resolve(modulePath, sourceFile, config);
@ -145,71 +210,22 @@ function fullResolve(modulePath, sourceFile, settings) {
// cache(undefined)
return { found: false };
}
/** @type {import('./resolve').relative} */
function relative(modulePath, sourceFile, settings) {
return fullResolve(modulePath, sourceFile, settings).path;
}
exports.relative = relative;
function resolverReducer(resolvers, map) {
if (Array.isArray(resolvers)) {
resolvers.forEach((r) => resolverReducer(r, map));
return map;
}
if (typeof resolvers === 'string') {
map.set(resolvers, null);
return map;
}
if (typeof resolvers === 'object') {
for (const key in resolvers) {
map.set(key, resolvers[key]);
}
return map;
}
const err = new Error('invalid resolver config');
err.name = ERROR_NAME;
throw err;
}
function getBaseDir(sourceFile) {
return pkgDir(sourceFile) || process.cwd();
}
function requireResolver(name, sourceFile) {
// Try to resolve package with conventional name
const resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile)
|| tryRequire(name, sourceFile)
|| tryRequire(path.resolve(getBaseDir(sourceFile), name));
if (!resolver) {
const err = new Error(`unable to load resolver "${name}".`);
err.name = ERROR_NAME;
throw err;
}
if (!isResolverValid(resolver)) {
const err = new Error(`${name} with invalid interface loaded as resolver`);
err.name = ERROR_NAME;
throw err;
}
return resolver;
}
function isResolverValid(resolver) {
if (resolver.interfaceVersion === 2) {
return resolver.resolve && typeof resolver.resolve === 'function';
} else {
return resolver.resolveImport && typeof resolver.resolveImport === 'function';
}
}
/** @type {Set<import('eslint').Rule.RuleContext>} */
const erroredContexts = new Set();
/**
* Given
* @param {string} p - module path
* @param {object} context - ESLint context
* @return {string} - the full module filesystem path;
* null if package is core;
* undefined if not found
* @param p - module path
* @param context - ESLint context
* @return - the full module filesystem path; null if package is core; undefined if not found
* @type {import('./resolve').default}
*/
function resolve(p, context) {
try {
@ -218,8 +234,11 @@ function resolve(p, context) {
if (!erroredContexts.has(context)) {
// The `err.stack` string starts with `err.name` followed by colon and `err.message`.
// We're filtering out the default `err.name` because it adds little value to the message.
// @ts-expect-error this might be an Error
let errMessage = err.message;
// @ts-expect-error this might be an Error
if (err.name !== ERROR_NAME && err.stack) {
// @ts-expect-error this might be an Error
errMessage = err.stack.replace(/^Error: /, '');
}
context.report({

11
node_modules/eslint-module-utils/tsconfig.json generated vendored Normal file
View file

@ -0,0 +1,11 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "ES2017",
"moduleResolution": "node",
"maxNodeModuleJsDepth": 0,
},
"exclude": [
"coverage",
],
}

9
node_modules/eslint-module-utils/types.d.ts generated vendored Normal file
View file

@ -0,0 +1,9 @@
import type { Rule } from 'eslint';
export type Extension = `.${string}`;
export type ESLintSettings = NonNullable<Rule.RuleContext['settings']> & {
'import/extensions'?: Extension[];
'import/parsers'?: { [k: string]: Extension[] };
'import/cache'?: { lifetime: number | '∞' | 'Infinity' };
};

7
node_modules/eslint-module-utils/unambiguous.d.ts generated vendored Normal file
View file

@ -0,0 +1,7 @@
import type { AST } from 'eslint';
declare function isModule(ast: AST.Program): boolean;
declare function test(content: string): boolean;
export { isModule, test }

View file

@ -11,7 +11,7 @@ const pattern = /(^|;)\s*(export|import)((\s+\w)|(\s*[{*=]))|import\(/m;
*
* Not perfect, just a fast way to disqualify large non-ES6 modules and
* avoid a parse.
* @type {RegExp}
* @type {import('./unambiguous').test}
*/
exports.test = function isMaybeUnambiguousModule(content) {
return pattern.test(content);
@ -22,8 +22,7 @@ const unambiguousNodeType = /^(?:(?:Exp|Imp)ort.*Declaration|TSExportAssignment)
/**
* Given an AST, return true if the AST unambiguously represents a module.
* @param {Program node} ast
* @return {Boolean}
* @type {import('./unambiguous').isModule}
*/
exports.isModule = function isUnambiguousModule(ast) {
return ast.body && ast.body.some((node) => unambiguousNodeType.test(node.type));

9
node_modules/eslint-module-utils/visit.d.ts generated vendored Normal file
View file

@ -0,0 +1,9 @@
import type { Node } from 'estree';
declare function visit(
node: Node,
keys: { [k in Node['type']]?: (keyof Node)[] },
visitorSpec: { [k in Node['type'] | `${Node['type']}:Exit`]?: Function }
): void;
export default visit;

View file

@ -2,24 +2,29 @@
exports.__esModule = true;
/** @type {import('./visit').default} */
exports.default = function visit(node, keys, visitorSpec) {
if (!node || !keys) {
return;
}
const type = node.type;
if (typeof visitorSpec[type] === 'function') {
visitorSpec[type](node);
const visitor = visitorSpec[type];
if (typeof visitor === 'function') {
visitor(node);
}
const childFields = keys[type];
if (!childFields) {
return;
}
childFields.forEach((fieldName) => {
// @ts-expect-error TS sucks with concat
[].concat(node[fieldName]).forEach((item) => {
visit(item, keys, visitorSpec);
});
});
if (typeof visitorSpec[`${type}:Exit`] === 'function') {
visitorSpec[`${type}:Exit`](node);
const exit = visitorSpec[`${type}:Exit`];
if (typeof exit === 'function') {
exit(node);
}
};