Socket
Socket
Sign inDemoInstall

eslint-module-utils

Package Overview
Dependencies
2
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.7.4 to 2.8.0

14

CHANGELOG.md

@@ -8,2 +8,10 @@ # Change Log

## v2.8.0 - 2023-04-14
### New
- `parse`: support flat config ([#2714], thanks [@DMartens])
### Fixed
- Improve performance of `fullResolve` for large projects ([#2755], thanks [@leipert])
## v2.7.4 - 2022-08-11

@@ -20,3 +28,3 @@

### Fixed
- [Fix] `parse`: restore compatibility by making the return value `ast` again ([#2350], thanks [@ljharb])
- `parse`: restore compatibility by making the return value `ast` again ([#2350], thanks [@ljharb])

@@ -128,2 +136,4 @@ ## v2.7.2 - 2022-01-01

[#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

@@ -161,2 +171,3 @@ [#2431]: https://github.com/import-js/eslint-plugin-import/pull/2431

[@christophercurrie]: https://github.com/christophercurrie
[@DMartens]: https://github.com/DMartens
[@hulkish]: https://github.com/hulkish

@@ -167,2 +178,3 @@ [@Hypnosphi]: https://github.com/Hypnosphi

[@kaiyoma]: https://github.com/kaiyoma
[@leipert]: https://github.com/leipert
[@manuth]: https://github.com/manuth

@@ -169,0 +181,0 @@ [@maxkomarychev]: https://github.com/maxkomarychev

5

declaredScope.js
'use strict';
exports.__esModule = true;

@@ -6,5 +7,5 @@

const references = context.getScope().references;
const reference = references.find(x => x.identifier.name === name);
if (!reference) return undefined;
const reference = references.find((x) => x.identifier.name === name);
if (!reference) { return undefined; }
return reference.resolved.scope.type;
};

@@ -5,3 +5,5 @@ /**

*/
'use strict';
exports.__esModule = true;

@@ -14,3 +16,3 @@

function hashify(value, hash) {
if (!hash) hash = createHash('sha256');
if (!hash) { hash = createHash('sha256'); }

@@ -30,3 +32,3 @@ if (Array.isArray(value)) {

function hashArray(array, hash) {
if (!hash) hash = createHash('sha256');
if (!hash) { hash = createHash('sha256'); }

@@ -46,6 +48,6 @@ hash.update('[');

function hashObject(object, hash) {
if (!hash) hash = createHash('sha256');
if (!hash) { hash = createHash('sha256'); }
hash.update('{');
Object.keys(object).sort().forEach(key => {
Object.keys(object).sort().forEach((key) => {
hash.update(stringify(key));

@@ -63,2 +65,1 @@ hash.update(':');

'use strict';
exports.__esModule = true;

@@ -31,3 +32,3 @@

}
parserSettings.forEach(ext => exts.add(ext));
parserSettings.forEach((ext) => exts.add(ext));
}

@@ -42,5 +43,5 @@ }

// check extension whitelist first (cheap)
if (!hasValidExtension(path, context)) return true;
if (!hasValidExtension(path, context)) { return true; }
if (!('import/ignore' in context.settings)) return false;
if (!('import/ignore' in context.settings)) { return false; }
const ignoreStrings = context.settings['import/ignore'];

@@ -47,0 +48,0 @@

'use strict';
exports.__esModule = true;

@@ -3,0 +4,0 @@

'use strict';
exports.__esModule = true;

@@ -26,4 +27,6 @@

// check freshness
if (process.hrtime(f.lastSeen)[0] < settings.lifetime) return f.result;
} else log('cache miss for', cacheKey);
if (process.hrtime(f.lastSeen)[0] < settings.lifetime) { return f.result; }
} else {
log('cache miss for', cacheKey);
}
// cache miss

@@ -30,0 +33,0 @@ return undefined;

'use strict';
exports.__esModule = true;

@@ -19,10 +20,10 @@

if (options.ignore != null) {
ignoreRegExps = options.ignore.map(p => new RegExp(p));
ignoreRegExps = options.ignore.map((p) => new RegExp(p));
}
function checkSourceValue(source, importer) {
if (source == null) return; //?
if (source == null) { return; } //?
// handle ignore
if (ignoreRegExps.some(re => re.test(source.value))) return;
if (ignoreRegExps.some((re) => re.test(source.value))) { return; }

@@ -45,4 +46,4 @@ // fire visitor

} else if (node.type === 'CallExpression') {
if (node.callee.type !== 'Import') return;
if (node.arguments.length !== 1) return;
if (node.callee.type !== 'Import') { return; }
if (node.arguments.length !== 1) { return; }

@@ -52,4 +53,4 @@ modulePath = node.arguments[0];

if (modulePath.type !== 'Literal') return;
if (typeof modulePath.value !== 'string') return;
if (modulePath.type !== 'Literal') { return; }
if (typeof modulePath.value !== 'string') { return; }

@@ -62,9 +63,9 @@ checkSourceValue(modulePath, node);

function checkCommon(call) {
if (call.callee.type !== 'Identifier') return;
if (call.callee.name !== 'require') return;
if (call.arguments.length !== 1) return;
if (call.callee.type !== 'Identifier') { return; }
if (call.callee.name !== 'require') { return; }
if (call.arguments.length !== 1) { return; }
const modulePath = call.arguments[0];
if (modulePath.type !== 'Literal') return;
if (typeof modulePath.value !== 'string') return;
if (modulePath.type !== 'Literal') { return; }
if (typeof modulePath.value !== 'string') { return; }

@@ -75,16 +76,19 @@ checkSourceValue(modulePath, call);

function checkAMD(call) {
if (call.callee.type !== 'Identifier') return;
if (call.callee.name !== 'require' &&
call.callee.name !== 'define') return;
if (call.arguments.length !== 2) return;
if (call.callee.type !== 'Identifier') { return; }
if (call.callee.name !== 'require' && call.callee.name !== 'define') { return; }
if (call.arguments.length !== 2) { return; }
const modules = call.arguments[0];
if (modules.type !== 'ArrayExpression') return;
if (modules.type !== 'ArrayExpression') { return; }
for (const element of modules.elements) {
if (element.type !== 'Literal') continue;
if (typeof element.value !== 'string') continue;
if (element.type !== 'Literal') { continue; }
if (typeof element.value !== 'string') { continue; }
if (element.value === 'require' ||
element.value === 'exports') continue; // magic modules: https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#magic-modules
if (
element.value === 'require'
|| element.value === 'exports'
) {
continue; // magic modules: https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#magic-modules
}

@@ -98,7 +102,7 @@ checkSourceValue(element, element);

Object.assign(visitors, {
'ImportDeclaration': checkSource,
'ExportNamedDeclaration': checkSource,
'ExportAllDeclaration': checkSource,
'CallExpression': checkImportCall,
'ImportExpression': checkImportCall,
ImportDeclaration: checkSource,
ExportNamedDeclaration: checkSource,
ExportAllDeclaration: checkSource,
CallExpression: checkImportCall,
ImportExpression: checkImportCall,
});

@@ -108,7 +112,7 @@ }

if (options.commonjs || options.amd) {
const currentCallExpression = visitors['CallExpression'];
visitors['CallExpression'] = function (call) {
if (currentCallExpression) currentCallExpression(call);
if (options.commonjs) checkCommon(call);
if (options.amd) checkAMD(call);
const currentCallExpression = visitors.CallExpression;
visitors.CallExpression = function (call) {
if (currentCallExpression) { currentCallExpression(call); }
if (options.commonjs) { checkCommon(call); }
if (options.amd) { checkAMD(call); }
};

@@ -126,15 +130,15 @@ }

const base = {
'type': 'object',
'properties': {
'commonjs': { 'type': 'boolean' },
'amd': { 'type': 'boolean' },
'esmodule': { 'type': 'boolean' },
'ignore': {
'type': 'array',
'minItems': 1,
'items': { 'type': 'string' },
'uniqueItems': true,
type: 'object',
properties: {
commonjs: { type: 'boolean' },
amd: { type: 'boolean' },
esmodule: { type: 'boolean' },
ignore: {
type: 'array',
minItems: 1,
items: { type: 'string' },
uniqueItems: true,
},
},
'additionalProperties': false,
additionalProperties: false,
};

@@ -141,0 +145,0 @@

{
"name": "eslint-module-utils",
"version": "2.7.4",
"version": "2.8.0",
"description": "Core utilities to support eslint-plugin-import and other module-related plugins.",

@@ -5,0 +5,0 @@ "engines": {

'use strict';
exports.__esModule = true;

@@ -26,6 +27,6 @@

}
if (/.*espree.*/.test(parserPath)) {
if (typeof parserPath === 'string' && (/.*espree.*/).test(parserPath)) {
return parserInstance.VisitorKeys;
}
if (/.*babel-eslint.*/.test(parserPath)) {
if (typeof parserPath === 'string' && (/.*babel-eslint.*/).test(parserPath)) {
return getBabelEslintVisitorKeys(parserPath);

@@ -55,10 +56,10 @@ }

exports.default = function parse(path, content, context) {
if (context == null) { throw new Error('need context to parse properly'); }
if (context == null) throw new Error('need context to parse properly');
// ESLint in "flat" mode only sets context.languageOptions.parserOptions
let parserOptions = context.languageOptions && context.languageOptions.parserOptions || context.parserOptions;
const parserOrPath = getParser(path, context);
let parserOptions = context.parserOptions;
const parserPath = getParserPath(path, context);
if (!parserOrPath) { throw new Error('parserPath or languageOptions.parser is required!'); }
if (!parserPath) throw new Error('parserPath is required!');
// hack: espree blows up with frozen options

@@ -89,3 +90,3 @@ parserOptions = Object.assign({}, parserOptions);

// require the parser relative to the main module (i.e., ESLint)
const parser = moduleRequire(parserPath);
const parser = typeof parserOrPath === 'string' ? moduleRequire(parserOrPath) : parserOrPath;

@@ -101,3 +102,3 @@ // replicate bom strip and hashbang transform of ESLint

ast = parserRaw.ast;
return makeParseReturn(ast, keysFromParser(parserPath, parser, parserRaw));
return makeParseReturn(ast, keysFromParser(parserOrPath, parser, parserRaw));
} catch (e) {

@@ -110,8 +111,7 @@ console.warn();

console.warn(
'`parseForESLint` from parser `' +
parserPath +
'` is invalid and will just be ignored'
// Can only be invalid for custom parser per imports/parser
'`parseForESLint` from parser `' + (typeof parserOrPath === 'string' ? parserOrPath : '`context.languageOptions.parser`') + '` is invalid and will just be ignored'
);
} else {
return makeParseReturn(ast, keysFromParser(parserPath, parser, undefined));
return makeParseReturn(ast, keysFromParser(parserOrPath, parser, undefined));
}

@@ -121,5 +121,21 @@ }

const ast = parser.parse(content, parserOptions);
return makeParseReturn(ast, keysFromParser(parserPath, parser, undefined));
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) {

@@ -126,0 +142,0 @@ const parsers = context.settings['import/parsers'];

'use strict';
exports.__esModule = true;

@@ -9,3 +10,3 @@

* Derived significantly from package find-up@2.0.0. See license below.
*
*
* @copyright Sindre Sorhus

@@ -15,3 +16,3 @@ * MIT License

* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy

@@ -23,6 +24,6 @@ * of this software and associated documentation files (the "Software"), to deal

* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

@@ -29,0 +30,0 @@ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

'use strict';
exports.__esModule = true;

@@ -13,3 +14,3 @@

* Derived significantly from read-pkg-up@2.0.0. See license below.
*
*
* @copyright Sindre Sorhus

@@ -19,3 +20,3 @@ * MIT License

* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy

@@ -27,6 +28,6 @@ * of this software and associated documentation files (the "Software"), to deal

* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

@@ -33,0 +34,0 @@ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

'use strict';
exports.__esModule = true;

@@ -56,7 +57,7 @@

// don't care if the FS is case-sensitive
if (CASE_SENSITIVE_FS) return true;
if (CASE_SENSITIVE_FS) { return true; }
// null means it resolved to a builtin
if (filepath === null) return true;
if (filepath.toLowerCase() === process.cwd().toLowerCase() && !strict) return true;
if (filepath === null) { return true; }
if (filepath.toLowerCase() === process.cwd().toLowerCase() && !strict) { return true; }
const parsedPath = path.parse(filepath);

@@ -66,3 +67,3 @@ const dir = parsedPath.dir;

let result = fileExistsCache.get(filepath, cacheSettings);
if (result != null) return result;
if (result != null) { return result; }

@@ -88,14 +89,22 @@ // base case

let prevSettings = null;
let memoizedHash = '';
function fullResolve(modulePath, sourceFile, settings) {
// check if this is a bonus core module
const coreSet = new Set(settings['import/core-modules']);
if (coreSet.has(modulePath)) return { found: true, path: null };
if (coreSet.has(modulePath)) { return { found: true, path: null }; }
const sourceDir = path.dirname(sourceFile);
const cacheKey = sourceDir + hashObject(settings).digest('hex') + modulePath;
if (prevSettings !== settings) {
memoizedHash = hashObject(settings).digest('hex');
prevSettings = settings;
}
const cacheKey = sourceDir + memoizedHash + modulePath;
const cacheSettings = ModuleCache.getSettings(settings);
const cachedPath = fileExistsCache.get(cacheKey, cacheSettings);
if (cachedPath !== undefined) return { found: true, path: cachedPath };
if (cachedPath !== undefined) { return { found: true, path: cachedPath }; }

@@ -107,29 +116,17 @@ function cache(resolvedPath) {

function withResolver(resolver, config) {
function v1() {
try {
const resolved = resolver.resolveImport(modulePath, sourceFile, config);
if (resolved === undefined) return { found: false };
return { found: true, path: resolved };
} catch (err) {
return { found: false };
}
}
function v2() {
if (resolver.interfaceVersion === 2) {
return resolver.resolve(modulePath, sourceFile, config);
}
switch (resolver.interfaceVersion) {
case 2:
return v2();
default:
case 1:
return v1();
try {
const resolved = resolver.resolveImport(modulePath, sourceFile, config);
if (resolved === undefined) { return { found: false }; }
return { found: true, path: resolved };
} catch (err) {
return { found: false };
}
}
const configResolvers = (settings['import/resolver']
|| { 'node': settings['import/resolve'] }); // backward compatibility
const configResolvers = settings['import/resolver']
|| { node: settings['import/resolve'] }; // backward compatibility

@@ -144,3 +141,3 @@ const resolvers = resolverReducer(configResolvers, new Map());

if (!resolved.found) continue;
if (!resolved.found) { continue; }

@@ -160,3 +157,3 @@ // else, counts

if (Array.isArray(resolvers)) {
resolvers.forEach(r => resolverReducer(r, map));
resolvers.forEach((r) => resolverReducer(r, map));
return map;

@@ -187,5 +184,5 @@ }

// Try to resolve package with conventional name
const resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile) ||
tryRequire(name, sourceFile) ||
tryRequire(path.resolve(getBaseDir(sourceFile), name));
const resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile)
|| tryRequire(name, sourceFile)
|| tryRequire(path.resolve(getBaseDir(sourceFile), name));

@@ -192,0 +189,0 @@ if (!resolver) {

'use strict';
exports.__esModule = true;

@@ -28,3 +29,3 @@

exports.isModule = function isUnambiguousModule(ast) {
return ast.body && ast.body.some(node => unambiguousNodeType.test(node.type));
return ast.body && ast.body.some((node) => unambiguousNodeType.test(node.type));
};
'use strict';
exports.__esModule = true;

@@ -3,0 +4,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc