eslint-plugin-workspaces
Advanced tools
Comparing version
@@ -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 }, | ||
}); | ||
} | ||
}); | ||
}); | ||
}; |
{ | ||
"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" |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
14145
13.08%10
11.11%268
15.52%