@nx/eslint-plugin 23.2.0-rc.0 → 23.2.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -114,7 +114,7 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl
|
|
|
114
114
|
noImportsOfLazyLoadedLibraries: `Static imports of lazy-loaded libraries are forbidden.\n\nLibrary "{{targetProjectName}}" is lazy-loaded in these files:\n{{filePaths}}`,
|
|
115
115
|
projectWithoutTagsCannotHaveDependencies: `A project without tags matching at least one constraint cannot depend on any libraries`,
|
|
116
116
|
bannedExternalImportsViolation: `A project tagged with "{{sourceTag}}" is not allowed to import "{{imp}}"`,
|
|
117
|
-
nestedBannedExternalImportsViolation: `A project tagged with "{{sourceTag}}" is not allowed to import "{{imp}}". Nested import found at {{childProjectName}}`,
|
|
117
|
+
nestedBannedExternalImportsViolation: `A project tagged with "{{sourceTag}}" is not allowed to import "{{imp}}". Nested import of "{{packageName}}" found at {{childProjectName}}`,
|
|
118
118
|
noTransitiveDependencies: `Only packages defined in the "package.json" can be imported. Transitive or unresolvable dependencies are not allowed.`,
|
|
119
119
|
onlyTagsConstraintViolation: `A project tagged with "{{sourceTag}}" can only depend on libs tagged with {{tags}}`,
|
|
120
120
|
emptyOnlyTagsConstraintViolation: 'A project tagged with "{{sourceTag}}" cannot depend on any libs with tags',
|
|
@@ -485,9 +485,9 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl
|
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
if (checkNestedExternalImports &&
|
|
488
|
-
constraint.bannedExternalImports
|
|
489
|
-
|
|
490
|
-
const matches = (0, runtime_lint_utils_1.hasBannedDependencies)(transitiveExternalDeps, projectGraph, constraint
|
|
488
|
+
(constraint.bannedExternalImports?.length ||
|
|
489
|
+
constraint.allowedExternalImports)) {
|
|
490
|
+
const matches = (0, runtime_lint_utils_1.hasBannedDependencies)(transitiveExternalDeps, projectGraph, constraint);
|
|
491
491
|
if (matches.length > 0) {
|
|
492
492
|
matches.forEach(([target, violatingSource, constraint]) => {
|
|
493
493
|
context.report({
|
|
@@ -497,6 +497,7 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => `https://github.com/nrwl
|
|
|
497
497
|
sourceTag: (0, runtime_lint_utils_1.isComboDepConstraint)(constraint)
|
|
498
498
|
? constraint.allSourceTags.join('" and "')
|
|
499
499
|
: constraint.sourceTag,
|
|
500
|
+
packageName: target.data.packageName,
|
|
500
501
|
childProjectName: violatingSource.name,
|
|
501
502
|
imp,
|
|
502
503
|
},
|
|
@@ -57,7 +57,7 @@ export declare function findTransitiveExternalDependencies(graph: ProjectGraph,
|
|
|
57
57
|
* @param depConstraint
|
|
58
58
|
* @returns
|
|
59
59
|
*/
|
|
60
|
-
export declare function hasBannedDependencies(externalDependencies: ProjectGraphDependency[], graph: ProjectGraph, depConstraint: DepConstraint
|
|
60
|
+
export declare function hasBannedDependencies(externalDependencies: ProjectGraphDependency[], graph: ProjectGraph, depConstraint: DepConstraint): Array<[ProjectGraphExternalNode, ProjectGraphProjectNode, DepConstraint]> | undefined;
|
|
61
61
|
export declare function isDirectDependency(source: ProjectGraphProjectNode, target: ProjectGraphExternalNode): boolean;
|
|
62
62
|
/**
|
|
63
63
|
* Verifies whether the given node has a builder target
|
|
@@ -171,19 +171,20 @@ function getSourceFilePath(sourceFileName, projectPath) {
|
|
|
171
171
|
* @param depConstraints
|
|
172
172
|
* @returns
|
|
173
173
|
*/
|
|
174
|
-
function isConstraintBanningProject(externalProject, constraint,
|
|
174
|
+
function isConstraintBanningProject(externalProject, constraint, importSpecifier) {
|
|
175
175
|
const { allowedExternalImports, bannedExternalImports } = constraint;
|
|
176
176
|
const { packageName } = externalProject.data;
|
|
177
|
-
if (
|
|
177
|
+
if (importSpecifier !== packageName &&
|
|
178
|
+
!importSpecifier.startsWith(`${packageName}/`)) {
|
|
178
179
|
return false;
|
|
179
180
|
}
|
|
180
181
|
/* Check if import is banned... */
|
|
181
|
-
if (bannedExternalImports?.some((importDefinition) => mapGlobToRegExp(importDefinition).test(
|
|
182
|
+
if (bannedExternalImports?.some((importDefinition) => mapGlobToRegExp(importDefinition).test(importSpecifier))) {
|
|
182
183
|
return true;
|
|
183
184
|
}
|
|
184
185
|
/* ... then check if there is a whitelist and if there is a match in the whitelist. */
|
|
185
|
-
return allowedExternalImports?.every((importDefinition) => !
|
|
186
|
-
!mapGlobToRegExp(importDefinition).test(
|
|
186
|
+
return allowedExternalImports?.every((importDefinition) => !importSpecifier.startsWith(packageName) ||
|
|
187
|
+
!mapGlobToRegExp(importDefinition).test(importSpecifier));
|
|
187
188
|
}
|
|
188
189
|
function hasBannedImport(source, target, depConstraints, imp) {
|
|
189
190
|
// return those constraints that match source project
|
|
@@ -217,13 +218,18 @@ function findTransitiveExternalDependencies(graph, source) {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
const externalDependencies = [];
|
|
221
|
+
const seen = new Set();
|
|
220
222
|
for (let i = 0; i < allReachableProjects.length; i++) {
|
|
221
223
|
const dependencies = graph.dependencies[allReachableProjects[i]];
|
|
222
224
|
if (dependencies) {
|
|
223
225
|
for (let d = 0; d < dependencies.length; d++) {
|
|
224
226
|
const dependency = dependencies[d];
|
|
225
227
|
if (graph.externalNodes[dependency.target]) {
|
|
226
|
-
|
|
228
|
+
const key = `${dependency.source}|${graph.externalNodes[dependency.target].data.packageName}`;
|
|
229
|
+
if (!seen.has(key)) {
|
|
230
|
+
seen.add(key);
|
|
231
|
+
externalDependencies.push(dependency);
|
|
232
|
+
}
|
|
227
233
|
}
|
|
228
234
|
}
|
|
229
235
|
}
|
|
@@ -237,9 +243,9 @@ function findTransitiveExternalDependencies(graph, source) {
|
|
|
237
243
|
* @param depConstraint
|
|
238
244
|
* @returns
|
|
239
245
|
*/
|
|
240
|
-
function hasBannedDependencies(externalDependencies, graph, depConstraint
|
|
246
|
+
function hasBannedDependencies(externalDependencies, graph, depConstraint) {
|
|
241
247
|
return externalDependencies
|
|
242
|
-
.filter((dependency) => isConstraintBanningProject(graph.externalNodes[dependency.target], depConstraint,
|
|
248
|
+
.filter((dependency) => isConstraintBanningProject(graph.externalNodes[dependency.target], depConstraint, graph.externalNodes[dependency.target].data.packageName))
|
|
243
249
|
.map((dep) => [
|
|
244
250
|
graph.externalNodes[dep.target],
|
|
245
251
|
graph.nodes[dep.source],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint-plugin",
|
|
3
|
-
"version": "23.2.0-rc.
|
|
3
|
+
"version": "23.2.0-rc.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
"picocolors": "^1.1.0",
|
|
110
110
|
"semver": "^7.6.3",
|
|
111
111
|
"tslib": "^2.3.0",
|
|
112
|
-
"@nx/devkit": "23.2.0-rc.
|
|
113
|
-
"@nx/js": "23.2.0-rc.
|
|
112
|
+
"@nx/devkit": "23.2.0-rc.2",
|
|
113
|
+
"@nx/js": "23.2.0-rc.2"
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
116
|
-
"nx": "23.2.0-rc.
|
|
116
|
+
"nx": "23.2.0-rc.2"
|
|
117
117
|
},
|
|
118
118
|
"publishConfig": {
|
|
119
119
|
"access": "public"
|