Socket
Socket
Sign inDemoInstall

eslint-plugin-module-resolver

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-module-resolver - npm Package Compare versions

Comparing version 0.14.0 to 0.15.0

dist/helpers/build-ignore-prefix.js

97

dist/rules/use-alias.js

@@ -17,4 +17,8 @@ "use strict";

var buildIgnorePrefix = require('../helpers/build-ignore-prefix');
var checkIgnoreDepth = require('../helpers/check-ignore-depth');
var findProjectRoot = require('../helpers/find-project-root');
var getProperties = require('../helpers/get-properties'); //------------------------------------------------------------------------------

@@ -50,7 +54,10 @@ // Rule Definition

},
projectRoot: {
type: 'string'
},
extensions: {
type: "array",
type: 'array',
uniqueItems: true,
items: {
type: "string",
type: 'string',
"enum": ['.ts', '.tsx', '.jsx']

@@ -64,24 +71,51 @@ }

create: function create(context) {
var _findBabelConfig$sync = findBabelConfig.sync('.'),
var filename = context.getFilename();
var filePath = path.dirname(filename); // Plugin options.
var options = getProperties(context.options);
var ignorePrefix = buildIgnorePrefix(options.ignoreDepth);
var projectRootAbsolutePath = findProjectRoot(filePath, options.projectRoot); // Find alias via babel-plugin-module-resolver config.
var alias = {};
var babelDir = projectRootAbsolutePath || '.';
var _findBabelConfig$sync = findBabelConfig.sync(babelDir),
config = _findBabelConfig$sync.config;
var options = context.options; // try/catch
// handle name collision with package.json
try {
var validPluginNames = new Set(['babel-plugin-module-resolver', 'module-resolver']);
var validPluginNames = new Set(['babel-plugin-module-resolver', 'module-resolver']);
var _config$plugins$filte = config.plugins.filter(function (plugins) {
if (Array.isArray(plugins) && validPluginNames.has(plugins[0])) {
return plugins;
}
}),
_config$plugins$filte2 = _slicedToArray(_config$plugins$filte, 1),
moduleResolver = _config$plugins$filte2[0];
var _config$plugins$filte = config.plugins.filter(function (plugins) {
if (Array.isArray(plugins) && validPluginNames.has(plugins[0])) {
return plugins;
}
}),
_config$plugins$filte2 = _slicedToArray(_config$plugins$filte, 1),
moduleResolver = _config$plugins$filte2[0];
alias = moduleResolver[1].alias;
} catch (error) {
var message = 'Unable to find config for babel-plugin-module-resolver';
return {
ImportDeclaration: function ImportDeclaration(node) {
context.report({
node: node,
message: message,
loc: node.source.loc
});
},
CallExpression: function CallExpression(node) {
context.report({
node: node,
message: message,
loc: node.arguments[0].loc
});
}
};
} // Build array of alias paths.
var _moduleResolver$ = moduleResolver[1],
_moduleResolver$$alia = _moduleResolver$.alias,
alias = _moduleResolver$$alia === void 0 ? {} : _moduleResolver$$alia,
root = _moduleResolver$.root;
var normalizedAliasArray = values(alias).map(function (a) {
return path.join(process.cwd(), a);
var cwd = projectRootAbsolutePath || process.cwd();
var aliasPaths = values(alias).map(function (a) {
return path.join(cwd, a);
});

@@ -92,16 +126,15 @@

var _getProperties = getProperties(options),
ignoreDepth = _getProperties.ignoreDepth,
extensions = _getProperties.extensions;
var ignoreDepth = options.ignoreDepth,
projectRoot = options.projectRoot,
extensions = options.extensions; // Ignore if directory depth matches options.
if (ignoreDepth) {
var ignorePrefix = Array(ignoreDepth).fill('../').join('');
if (checkIgnoreDepth({
ignorePrefix: ignorePrefix,
path: val
})) return;
if (ignoreDepth && checkIgnoreDepth({
ignorePrefix: ignorePrefix,
path: val
})) return; // Error if projectRoot option specified but cannot be resolved.
if (projectRoot && !projectRootAbsolutePath) {
return true;
}
var filename = context.getFilename();
var filePath = path.dirname(filename);
var resolvedPath = path.resolve(filePath, val);

@@ -117,4 +150,4 @@ var resolvedExt = path.extname(val) ? '' : '.js';

var isAliased = normalizedAliasArray.some(function (v) {
return resolvedPath.includes(v);
var isAliased = aliasPaths.some(function (aliasPath) {
return resolvedPath.includes(aliasPath);
});

@@ -121,0 +154,0 @@ return isAliased && pathExists && val.match(/\.\.\//); // matches, exists, and starts with ../

{
"name": "eslint-plugin-module-resolver",
"version": "0.14.0",
"version": "0.15.0",
"description": "Warn when using relative paths to modules aliased",

@@ -19,3 +19,3 @@ "repository": "HeroProtagonist/eslint-plugin-module-resolver",

"test:watch": "jest --watch",
"test:coverage": "COLLECT_COVERAGE=true jest",
"test:coverage": "jest --coverage",
"prebuild": "yarn clean",

@@ -22,0 +22,0 @@ "build": "babel lib --out-dir dist",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc