@nx/eslint-plugin 0.0.0-pr-22179-271588f
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.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/migrations.json +18 -0
- package/package.json +54 -0
- package/src/configs/angular-template.d.ts +20 -0
- package/src/configs/angular-template.js +21 -0
- package/src/configs/angular.d.ts +25 -0
- package/src/configs/angular.js +27 -0
- package/src/configs/javascript.d.ts +62 -0
- package/src/configs/javascript.js +70 -0
- package/src/configs/react-base.d.ts +112 -0
- package/src/configs/react-base.js +141 -0
- package/src/configs/react-jsx.d.ts +71 -0
- package/src/configs/react-jsx.js +64 -0
- package/src/configs/react-tmp.d.ts +12 -0
- package/src/configs/react-tmp.js +17 -0
- package/src/configs/react-typescript.d.ts +40 -0
- package/src/configs/react-typescript.js +54 -0
- package/src/configs/typescript.d.ts +44 -0
- package/src/configs/typescript.js +53 -0
- package/src/constants.d.ts +13 -0
- package/src/constants.js +18 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +34 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +43 -0
- package/src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules.d.ts +2 -0
- package/src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules.js +29 -0
- package/src/resolve-workspace-rules.d.ts +4 -0
- package/src/resolve-workspace-rules.js +38 -0
- package/src/rules/dependency-checks.d.ts +17 -0
- package/src/rules/dependency-checks.js +240 -0
- package/src/rules/enforce-module-boundaries.d.ts +18 -0
- package/src/rules/enforce-module-boundaries.js +480 -0
- package/src/rules/nx-plugin-checks.d.ts +21 -0
- package/src/rules/nx-plugin-checks.js +392 -0
- package/src/utils/ast-utils.d.ts +12 -0
- package/src/utils/ast-utils.js +220 -0
- package/src/utils/config-utils.d.ts +6 -0
- package/src/utils/config-utils.js +18 -0
- package/src/utils/graph-utils.d.ts +6 -0
- package/src/utils/graph-utils.js +129 -0
- package/src/utils/package-json-utils.d.ts +4 -0
- package/src/utils/package-json-utils.js +37 -0
- package/src/utils/project-graph-utils.d.ts +10 -0
- package/src/utils/project-graph-utils.js +53 -0
- package/src/utils/runtime-lint-utils.d.ts +88 -0
- package/src/utils/runtime-lint-utils.js +365 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findFilesWithDynamicImports = exports.findFilesInCircularPath = exports.checkCircularPath = exports.pathExists = exports.getPath = void 0;
|
|
4
|
+
const project_graph_1 = require("nx/src/config/project-graph");
|
|
5
|
+
const reach = {
|
|
6
|
+
graph: null,
|
|
7
|
+
matrix: null,
|
|
8
|
+
adjList: null,
|
|
9
|
+
};
|
|
10
|
+
function buildMatrix(graph) {
|
|
11
|
+
const nodes = Object.keys(graph.nodes);
|
|
12
|
+
const nodesLength = nodes.length;
|
|
13
|
+
const adjList = {};
|
|
14
|
+
const matrix = {};
|
|
15
|
+
// create matrix value set
|
|
16
|
+
for (let i = 0; i < nodesLength; i++) {
|
|
17
|
+
const v = nodes[i];
|
|
18
|
+
adjList[v] = [];
|
|
19
|
+
// meeroslav: turns out this is 10x faster than spreading the pre-generated initMatrixValues
|
|
20
|
+
matrix[v] = {};
|
|
21
|
+
}
|
|
22
|
+
const projectsWithDependencies = Object.keys(graph.dependencies);
|
|
23
|
+
for (let i = 0; i < projectsWithDependencies.length; i++) {
|
|
24
|
+
const dependencies = graph.dependencies[projectsWithDependencies[i]];
|
|
25
|
+
for (let j = 0; j < dependencies.length; j++) {
|
|
26
|
+
const dependency = dependencies[j];
|
|
27
|
+
if (graph.nodes[dependency.target]) {
|
|
28
|
+
adjList[dependency.source].push(dependency.target);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const traverse = (s, v) => {
|
|
33
|
+
matrix[s][v] = true;
|
|
34
|
+
const adjListLength = adjList[v].length;
|
|
35
|
+
for (let i = 0; i < adjListLength; i++) {
|
|
36
|
+
const adj = adjList[v][i];
|
|
37
|
+
if (!matrix[s][adj]) {
|
|
38
|
+
traverse(s, adj);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
for (let i = 0; i < nodesLength; i++) {
|
|
43
|
+
const v = nodes[i];
|
|
44
|
+
traverse(v, v);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
matrix,
|
|
48
|
+
adjList,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function getPath(graph, sourceProjectName, targetProjectName) {
|
|
52
|
+
if (sourceProjectName === targetProjectName)
|
|
53
|
+
return [];
|
|
54
|
+
if (reach.graph !== graph) {
|
|
55
|
+
const { matrix, adjList } = buildMatrix(graph);
|
|
56
|
+
reach.graph = graph;
|
|
57
|
+
reach.matrix = matrix;
|
|
58
|
+
reach.adjList = adjList;
|
|
59
|
+
}
|
|
60
|
+
const adjList = reach.adjList;
|
|
61
|
+
let path = [];
|
|
62
|
+
const queue = [[sourceProjectName, path]];
|
|
63
|
+
const visited = [sourceProjectName];
|
|
64
|
+
while (queue.length > 0) {
|
|
65
|
+
const [current, p] = queue.pop();
|
|
66
|
+
path = [...p, current];
|
|
67
|
+
if (current === targetProjectName)
|
|
68
|
+
break;
|
|
69
|
+
if (!adjList[current])
|
|
70
|
+
break;
|
|
71
|
+
adjList[current]
|
|
72
|
+
.filter((adj) => visited.indexOf(adj) === -1)
|
|
73
|
+
.filter((adj) => reach.matrix[adj][targetProjectName])
|
|
74
|
+
.forEach((adj) => {
|
|
75
|
+
visited.push(adj);
|
|
76
|
+
queue.push([adj, [...path]]);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (path.length > 1) {
|
|
80
|
+
return path.map((n) => graph.nodes[n]);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.getPath = getPath;
|
|
87
|
+
function pathExists(graph, sourceProjectName, targetProjectName) {
|
|
88
|
+
if (sourceProjectName === targetProjectName)
|
|
89
|
+
return true;
|
|
90
|
+
if (reach.graph !== graph) {
|
|
91
|
+
const { matrix, adjList } = buildMatrix(graph);
|
|
92
|
+
reach.graph = graph;
|
|
93
|
+
reach.matrix = matrix;
|
|
94
|
+
reach.adjList = adjList;
|
|
95
|
+
}
|
|
96
|
+
return !!reach.matrix[sourceProjectName][targetProjectName];
|
|
97
|
+
}
|
|
98
|
+
exports.pathExists = pathExists;
|
|
99
|
+
function checkCircularPath(graph, sourceProject, targetProject) {
|
|
100
|
+
if (!graph.nodes[targetProject.name])
|
|
101
|
+
return [];
|
|
102
|
+
return getPath(graph, targetProject.name, sourceProject.name);
|
|
103
|
+
}
|
|
104
|
+
exports.checkCircularPath = checkCircularPath;
|
|
105
|
+
function findFilesInCircularPath(projectFileMap, circularPath) {
|
|
106
|
+
const filePathChain = [];
|
|
107
|
+
for (let i = 0; i < circularPath.length - 1; i++) {
|
|
108
|
+
const next = circularPath[i + 1].name;
|
|
109
|
+
const files = projectFileMap[circularPath[i].name] || [];
|
|
110
|
+
filePathChain.push(files
|
|
111
|
+
.filter((file) => file.deps && file.deps.find((d) => (0, project_graph_1.fileDataDepTarget)(d) === next))
|
|
112
|
+
.map((file) => file.file));
|
|
113
|
+
}
|
|
114
|
+
return filePathChain;
|
|
115
|
+
}
|
|
116
|
+
exports.findFilesInCircularPath = findFilesInCircularPath;
|
|
117
|
+
function findFilesWithDynamicImports(projectFileMap, sourceProjectName, targetProjectName) {
|
|
118
|
+
const files = [];
|
|
119
|
+
projectFileMap[sourceProjectName].forEach((file) => {
|
|
120
|
+
if (!file.deps)
|
|
121
|
+
return;
|
|
122
|
+
if (file.deps.some((d) => (0, project_graph_1.fileDataDepTarget)(d) === targetProjectName &&
|
|
123
|
+
(0, project_graph_1.fileDataDepType)(d) === project_graph_1.DependencyType.dynamic)) {
|
|
124
|
+
files.push(file);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return files;
|
|
128
|
+
}
|
|
129
|
+
exports.findFilesWithDynamicImports = findFilesWithDynamicImports;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PackageJson } from 'nx/src/utils/package-json';
|
|
2
|
+
export declare function getAllDependencies(packageJson: PackageJson): Record<string, string>;
|
|
3
|
+
export declare function getProductionDependencies(packageJsonPath: string): Record<string, string>;
|
|
4
|
+
export declare function getPackageJson(path: string): PackageJson;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPackageJson = exports.getProductionDependencies = exports.getAllDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const runtime_lint_utils_1 = require("./runtime-lint-utils");
|
|
7
|
+
function getAllDependencies(packageJson) {
|
|
8
|
+
return {
|
|
9
|
+
...packageJson.dependencies,
|
|
10
|
+
...packageJson.devDependencies,
|
|
11
|
+
...packageJson.peerDependencies,
|
|
12
|
+
...packageJson.optionalDependencies,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.getAllDependencies = getAllDependencies;
|
|
16
|
+
function getProductionDependencies(packageJsonPath) {
|
|
17
|
+
if (!globalThis.projPackageJsonDeps ||
|
|
18
|
+
!globalThis.projPackageJsonDeps[packageJsonPath] ||
|
|
19
|
+
!(0, runtime_lint_utils_1.isTerminalRun)()) {
|
|
20
|
+
const packageJson = getPackageJson(packageJsonPath);
|
|
21
|
+
globalThis.projPackageJsonDeps = globalThis.projPackageJsonDeps || {};
|
|
22
|
+
globalThis.projPackageJsonDeps[packageJsonPath] = {
|
|
23
|
+
...packageJson.dependencies,
|
|
24
|
+
...packageJson.peerDependencies,
|
|
25
|
+
...packageJson.optionalDependencies,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return globalThis.projPackageJsonDeps[packageJsonPath];
|
|
29
|
+
}
|
|
30
|
+
exports.getProductionDependencies = getProductionDependencies;
|
|
31
|
+
function getPackageJson(path) {
|
|
32
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
33
|
+
return (0, devkit_1.readJsonFile)(path);
|
|
34
|
+
}
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
exports.getPackageJson = getPackageJson;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProjectFileMap, ProjectGraph } from '@nx/devkit';
|
|
2
|
+
import { ProjectRootMappings } from 'nx/src/project-graph/utils/find-project-for-path';
|
|
3
|
+
import { TargetProjectLocator } from '@nx/js/src/internal';
|
|
4
|
+
export declare function ensureGlobalProjectGraph(ruleName: string): void;
|
|
5
|
+
export declare function readProjectGraph(ruleName: string): {
|
|
6
|
+
projectGraph: ProjectGraph;
|
|
7
|
+
projectFileMap: ProjectFileMap;
|
|
8
|
+
projectRootMappings: ProjectRootMappings;
|
|
9
|
+
targetProjectLocator: TargetProjectLocator;
|
|
10
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readProjectGraph = exports.ensureGlobalProjectGraph = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const runtime_lint_utils_1 = require("./runtime-lint-utils");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path");
|
|
8
|
+
const configuration_1 = require("nx/src/config/configuration");
|
|
9
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
10
|
+
const nx_deps_cache_1 = require("nx/src/project-graph/nx-deps-cache");
|
|
11
|
+
function ensureGlobalProjectGraph(ruleName) {
|
|
12
|
+
/**
|
|
13
|
+
* Only reuse graph when running from terminal
|
|
14
|
+
* Enforce every IDE change to get a fresh nxdeps.json
|
|
15
|
+
*/
|
|
16
|
+
if (!globalThis.projectGraph ||
|
|
17
|
+
!globalThis.projectRootMappings ||
|
|
18
|
+
!globalThis.projectFileMap ||
|
|
19
|
+
!(0, runtime_lint_utils_1.isTerminalRun)()) {
|
|
20
|
+
const nxJson = (0, configuration_1.readNxJson)();
|
|
21
|
+
globalThis.workspaceLayout = nxJson.workspaceLayout;
|
|
22
|
+
/**
|
|
23
|
+
* Because there are a number of ways in which the rule can be invoked (executor vs ESLint CLI vs IDE Plugin),
|
|
24
|
+
* the ProjectGraph may or may not exist by the time the lint rule is invoked for the first time.
|
|
25
|
+
*/
|
|
26
|
+
try {
|
|
27
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
28
|
+
globalThis.projectGraph = projectGraph;
|
|
29
|
+
globalThis.projectRootMappings = (0, find_project_for_path_1.createProjectRootMappings)(projectGraph.nodes);
|
|
30
|
+
globalThis.projectFileMap = (0, nx_deps_cache_1.readFileMapCache)().fileMap.projectFileMap;
|
|
31
|
+
globalThis.targetProjectLocator = new internal_1.TargetProjectLocator(projectGraph.nodes, projectGraph.externalNodes);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
const WARNING_PREFIX = `${chalk.reset.keyword('orange')('warning')}`;
|
|
35
|
+
const RULE_NAME_SUFFIX = `${chalk.reset.dim(`@nx/${ruleName}`)}`;
|
|
36
|
+
process.stdout
|
|
37
|
+
.write(`${WARNING_PREFIX} No cached ProjectGraph is available. The rule will be skipped.
|
|
38
|
+
If you encounter this error as part of running standard \`nx\` commands then please open an issue on https://github.com/nrwl/nx
|
|
39
|
+
${RULE_NAME_SUFFIX}\n`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ensureGlobalProjectGraph = ensureGlobalProjectGraph;
|
|
44
|
+
function readProjectGraph(ruleName) {
|
|
45
|
+
ensureGlobalProjectGraph(ruleName);
|
|
46
|
+
return {
|
|
47
|
+
projectGraph: globalThis.projectGraph,
|
|
48
|
+
projectFileMap: globalThis.projectFileMap,
|
|
49
|
+
projectRootMappings: globalThis.projectRootMappings,
|
|
50
|
+
targetProjectLocator: globalThis.targetProjectLocator,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.readProjectGraph = readProjectGraph;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ProjectGraph, ProjectGraphDependency, ProjectGraphExternalNode, ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
|
+
import { ProjectRootMappings } from 'nx/src/project-graph/utils/find-project-for-path';
|
|
3
|
+
import { TargetProjectLocator } from '@nx/js/src/internal';
|
|
4
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
5
|
+
export type Deps = {
|
|
6
|
+
[projectName: string]: ProjectGraphDependency[];
|
|
7
|
+
};
|
|
8
|
+
type SingleSourceTagConstraint = {
|
|
9
|
+
sourceTag: string;
|
|
10
|
+
onlyDependOnLibsWithTags?: string[];
|
|
11
|
+
notDependOnLibsWithTags?: string[];
|
|
12
|
+
allowedExternalImports?: string[];
|
|
13
|
+
bannedExternalImports?: string[];
|
|
14
|
+
};
|
|
15
|
+
type ComboSourceTagConstraint = {
|
|
16
|
+
allSourceTags: string[];
|
|
17
|
+
onlyDependOnLibsWithTags?: string[];
|
|
18
|
+
notDependOnLibsWithTags?: string[];
|
|
19
|
+
allowedExternalImports?: string[];
|
|
20
|
+
bannedExternalImports?: string[];
|
|
21
|
+
};
|
|
22
|
+
export type DepConstraint = SingleSourceTagConstraint | ComboSourceTagConstraint;
|
|
23
|
+
export declare function stringifyTags(tags: string[]): string;
|
|
24
|
+
export declare function hasNoneOfTheseTags(proj: ProjectGraphProjectNode, tags: string[]): boolean;
|
|
25
|
+
export declare function isComboDepConstraint(depConstraint: DepConstraint): depConstraint is ComboSourceTagConstraint;
|
|
26
|
+
/**
|
|
27
|
+
* Check if any of the given tags is included in the project
|
|
28
|
+
* @param proj ProjectGraphProjectNode
|
|
29
|
+
* @param tags
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function findDependenciesWithTags(targetProject: ProjectGraphProjectNode, tags: string[], graph: ProjectGraph): ProjectGraphProjectNode[][];
|
|
33
|
+
export declare function matchImportWithWildcard(allowableImport: string, extractedImport: string): boolean;
|
|
34
|
+
export declare function isRelative(s: string): boolean;
|
|
35
|
+
export declare function getTargetProjectBasedOnRelativeImport(imp: string, projectPath: string, projectGraph: ProjectGraph, projectRootMappings: ProjectRootMappings, sourceFilePath: string): ProjectGraphProjectNode | undefined;
|
|
36
|
+
export declare function findProject(projectGraph: ProjectGraph, projectRootMappings: ProjectRootMappings, sourceFilePath: string): ProjectGraphProjectNode;
|
|
37
|
+
export declare function isAbsoluteImportIntoAnotherProject(imp: string, workspaceLayout?: {
|
|
38
|
+
libsDir: string;
|
|
39
|
+
appsDir: string;
|
|
40
|
+
}): boolean;
|
|
41
|
+
export declare function findProjectUsingImport(projectGraph: ProjectGraph, targetProjectLocator: TargetProjectLocator, filePath: string, imp: string): ProjectGraphProjectNode | ProjectGraphExternalNode;
|
|
42
|
+
export declare function findConstraintsFor(depConstraints: DepConstraint[], sourceProject: ProjectGraphProjectNode): DepConstraint[];
|
|
43
|
+
export declare function hasStaticImportOfDynamicResource(node: TSESTree.ImportDeclaration | TSESTree.ImportExpression | TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration, graph: ProjectGraph, sourceProjectName: string, targetProjectName: string): boolean;
|
|
44
|
+
export declare function getSourceFilePath(sourceFileName: string, projectPath: string): string;
|
|
45
|
+
export declare function hasBannedImport(source: ProjectGraphProjectNode, target: ProjectGraphExternalNode, depConstraints: DepConstraint[], imp: string): DepConstraint | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Find all unique (transitive) external dependencies of given project
|
|
48
|
+
* @param graph
|
|
49
|
+
* @param source
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export declare function findTransitiveExternalDependencies(graph: ProjectGraph, source: ProjectGraphProjectNode): ProjectGraphDependency[];
|
|
53
|
+
/**
|
|
54
|
+
* Check if
|
|
55
|
+
* @param externalDependencies
|
|
56
|
+
* @param graph
|
|
57
|
+
* @param depConstraint
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export declare function hasBannedDependencies(externalDependencies: ProjectGraphDependency[], graph: ProjectGraph, depConstraint: DepConstraint, imp: string): Array<[ProjectGraphExternalNode, ProjectGraphProjectNode, DepConstraint]> | undefined;
|
|
61
|
+
export declare function isDirectDependency(source: ProjectGraphProjectNode, target: ProjectGraphExternalNode): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Verifies whether the given node has a builder target
|
|
64
|
+
* @param projectGraph the node to verify
|
|
65
|
+
* @param buildTargets the list of targets to check for
|
|
66
|
+
*/
|
|
67
|
+
export declare function hasBuildExecutor(projectGraph: ProjectGraphProjectNode, buildTargets?: string[]): boolean;
|
|
68
|
+
export declare function isTerminalRun(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Takes an array of imports and tries to group them, so rather than having
|
|
71
|
+
* `import { A } from './some-location'` and `import { B } from './some-location'` you get
|
|
72
|
+
* `import { A, B } from './some-location'`
|
|
73
|
+
* @param importsToRemap
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
export declare function groupImports(importsToRemap: {
|
|
77
|
+
member: string;
|
|
78
|
+
importPath: string;
|
|
79
|
+
}[]): string;
|
|
80
|
+
/**
|
|
81
|
+
* Checks if source file belongs to a secondary entry point different than the import one
|
|
82
|
+
*/
|
|
83
|
+
export declare function belongsToDifferentNgEntryPoint(importExpr: string, filePath: string, projectRoot: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Returns true if the given project contains MFE config with "exposes:" section
|
|
86
|
+
*/
|
|
87
|
+
export declare function appIsMFERemote(project: ProjectGraphProjectNode): boolean;
|
|
88
|
+
export {};
|