You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

eslint-plugin-workspaces

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-workspaces - npm Package Compare versions

Comparing version

to
0.6.0

CHANGELOG.md

65

lib/rules/no-cross-imports.js

@@ -29,2 +29,15 @@ 'use strict';

},
scopes: {
anyOf: [
{ type: 'boolean', additionalProperties: false },
{
type: 'object',
additionalProperties: false,
properties: {
enable: { type: 'boolean' },
folderName: { type: 'string' },
},
},
],
},
},

@@ -35,24 +48,50 @@ },

const filterSharedPackagesInCurrentScope = (
{ location: currentLocation },
scopedEnabled,
scopedSharingFolderName,
) => ({ location }) => {
if (!scopedEnabled) return true;
const locationArray = location.split('/');
const forbiddenPackageParent = locationArray.slice(0, -1).join('/');
if (!isSubPath(forbiddenPackageParent, currentLocation)) {
return true;
}
return locationArray[locationArray.length - 1] !== scopedSharingFolderName;
};
module.exports.create = (context) => {
const {
options: [{ allow = [] } = {}],
options: [{ allow = [], scopes = { enable: false } } = {}],
} = context;
const allowed = typeof allow === 'string' ? [allow] : allow;
const scopedEnabled = scopes === true || !!scopes.enable;
const scopedSharingFolderName = scopes.folderName || 'shared';
const forbidden = packages.filter(({ name }) => !allowed.includes(name));
return getImport(context, ({ node, value, path, currentPackage }) => {
forbidden.forEach(({ name, location }) => {
if (
name !== currentPackage.name &&
(isSubPath(name, value) || isSubPath(location, path))
) {
context.report({
node,
message: 'Import from package "{{name}}" is not allowed',
data: { name },
});
}
});
forbidden
.filter(
filterSharedPackagesInCurrentScope(
currentPackage,
scopedEnabled,
scopedSharingFolderName,
),
)
.forEach(({ name, location }) => {
if (
name !== currentPackage.name &&
(isSubPath(name, value) || isSubPath(location, path))
) {
context.report({
node,
message: 'Import from package "{{name}}" is not allowed',
data: { name },
});
}
});
});
};

3

package.json
{
"name": "eslint-plugin-workspaces",
"version": "0.5.5",
"version": "0.6.0",
"main": "lib/index.js",

@@ -19,2 +19,3 @@ "license": "MIT",

"lib/",
"CHANGELOG.md",
"README.md",

@@ -21,0 +22,0 @@ "LICENSE"