@nx/eslint-plugin 17.2.5 → 17.3.0-beta.1
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/migrations.json +6 -0
- package/package.json +4 -4
- package/src/constants.d.ts +3 -2
- package/src/constants.js +5 -4
- 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.js +3 -1
- package/src/rules/enforce-module-boundaries.js +1 -1
- package/src/utils/runtime-lint-utils.d.ts +2 -5
- package/src/utils/runtime-lint-utils.js +16 -12
package/migrations.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"version": "16.0.0-beta.1",
|
|
6
6
|
"description": "Replace @nrwl/eslint-plugin-nx with @nx/eslint-plugin",
|
|
7
7
|
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
8
|
+
},
|
|
9
|
+
"update-17-2-6-rename-workspace-rules": {
|
|
10
|
+
"cli": "nx",
|
|
11
|
+
"version": "17-2-6-beta.1",
|
|
12
|
+
"description": "Rename workspace rules from @nx/workspace/name to @nx/workspace-name",
|
|
13
|
+
"implementation": "./src/migrations/update-17-2-6-rename-workspace-rules/rename-workspace-rules"
|
|
8
14
|
}
|
|
9
15
|
},
|
|
10
16
|
"packageJsonUpdates": {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/eslint-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.3.0-beta.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The eslint-plugin package is an ESLint plugin that contains a collection of recommended ESLint rule configurations which you can extend from in your own ESLint configs, as well as an Nx-specific lint rule called enforce-module-boundaries.",
|
|
6
6
|
"repository": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nx/devkit": "
|
|
37
|
-
"@nx/js": "
|
|
36
|
+
"@nx/devkit": "17.3.0-beta.1",
|
|
37
|
+
"@nx/js": "17.3.0-beta.1",
|
|
38
38
|
"@typescript-eslint/type-utils": "^6.13.2",
|
|
39
39
|
"@typescript-eslint/utils": "^6.13.2",
|
|
40
40
|
"chalk": "^4.1.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"jsonc-eslint-parser": "^2.1.0",
|
|
43
43
|
"semver": "7.5.3",
|
|
44
44
|
"tslib": "^2.3.0",
|
|
45
|
-
"@nrwl/eslint-plugin-nx": "
|
|
45
|
+
"@nrwl/eslint-plugin-nx": "17.3.0-beta.1"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
package/src/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const WORKSPACE_RULES_PATH = "tools/eslint-rules";
|
|
1
2
|
export declare const WORKSPACE_PLUGIN_DIR: string;
|
|
2
3
|
/**
|
|
3
4
|
* We add a namespace so that we mitigate the risk of rule name collisions as much as
|
|
@@ -7,6 +8,6 @@ export declare const WORKSPACE_PLUGIN_DIR: string;
|
|
|
7
8
|
* E.g. if a user writes a rule called "foo", then they will include it in their ESLint
|
|
8
9
|
* config files as:
|
|
9
10
|
*
|
|
10
|
-
* "@nx/workspace
|
|
11
|
+
* "@nx/workspace-foo": "error"
|
|
11
12
|
*/
|
|
12
|
-
export declare const
|
|
13
|
+
export declare const WORKSPACE_RULE_PREFIX = "workspace";
|
package/src/constants.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WORKSPACE_RULE_PREFIX = exports.WORKSPACE_PLUGIN_DIR = exports.WORKSPACE_RULES_PATH = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
exports.
|
|
6
|
+
exports.WORKSPACE_RULES_PATH = 'tools/eslint-rules';
|
|
7
|
+
exports.WORKSPACE_PLUGIN_DIR = (0, path_1.join)(devkit_1.workspaceRoot, exports.WORKSPACE_RULES_PATH);
|
|
7
8
|
/**
|
|
8
9
|
* We add a namespace so that we mitigate the risk of rule name collisions as much as
|
|
9
10
|
* possible between what users might create in their workspaces and what we might want
|
|
@@ -12,6 +13,6 @@ exports.WORKSPACE_PLUGIN_DIR = (0, path_1.join)(devkit_1.workspaceRoot, 'tools/e
|
|
|
12
13
|
* E.g. if a user writes a rule called "foo", then they will include it in their ESLint
|
|
13
14
|
* config files as:
|
|
14
15
|
*
|
|
15
|
-
* "@nx/workspace
|
|
16
|
+
* "@nx/workspace-foo": "error"
|
|
16
17
|
*/
|
|
17
|
-
exports.
|
|
18
|
+
exports.WORKSPACE_RULE_PREFIX = 'workspace';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const binary_extensions_1 = require("@nx/devkit/src/utils/binary-extensions");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
async function renameWorkspaceRule(tree) {
|
|
7
|
+
if (!tree.exists(constants_1.WORKSPACE_RULES_PATH)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let ruleNames = [];
|
|
11
|
+
try {
|
|
12
|
+
ruleNames = Object.keys(require(constants_1.WORKSPACE_PLUGIN_DIR).rules);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '.', (path) => {
|
|
18
|
+
if ((0, binary_extensions_1.isBinaryPath)(path)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let contents = tree.read(path, 'utf-8');
|
|
22
|
+
ruleNames.forEach((ruleName) => {
|
|
23
|
+
contents = contents.replace(new RegExp(`@nx/workspace/${ruleName}`, 'g'), `@nx/workspace-${ruleName}`);
|
|
24
|
+
});
|
|
25
|
+
tree.write(path, contents);
|
|
26
|
+
});
|
|
27
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
28
|
+
}
|
|
29
|
+
exports.default = renameWorkspaceRule;
|
|
@@ -21,7 +21,9 @@ exports.workspaceRules = (() => {
|
|
|
21
21
|
// Apply the namespace to the resolved rules
|
|
22
22
|
const namespacedRules = {};
|
|
23
23
|
for (const [ruleName, ruleConfig] of Object.entries(rules)) {
|
|
24
|
-
namespacedRules[`${constants_1.
|
|
24
|
+
namespacedRules[`${constants_1.WORKSPACE_RULE_PREFIX}-${ruleName}`] = ruleConfig;
|
|
25
|
+
// keep the old namespaced rules for backwards compatibility
|
|
26
|
+
namespacedRules[`${constants_1.WORKSPACE_RULE_PREFIX}/${ruleName}`] = ruleConfig;
|
|
25
27
|
}
|
|
26
28
|
return namespacedRules;
|
|
27
29
|
}
|
|
@@ -225,7 +225,7 @@ exports.default = utils_2.ESLintUtils.RuleCreator(() => ``)({
|
|
|
225
225
|
if (sourceProject === targetProject) {
|
|
226
226
|
if (!allowCircularSelfDependency &&
|
|
227
227
|
!(0, fileutils_1.isRelativePath)(imp) &&
|
|
228
|
-
!(0, runtime_lint_utils_1.
|
|
228
|
+
!(0, runtime_lint_utils_1.belongsToDifferentNgEntryPoint)(imp, sourceFilePath, sourceProject.data.root)) {
|
|
229
229
|
context.report({
|
|
230
230
|
node,
|
|
231
231
|
messageId: 'noSelfCircularDependencies',
|
|
@@ -77,12 +77,9 @@ export declare function groupImports(importsToRemap: {
|
|
|
77
77
|
importPath: string;
|
|
78
78
|
}[]): string;
|
|
79
79
|
/**
|
|
80
|
-
* Checks if
|
|
81
|
-
* @param targetProjectLocator
|
|
82
|
-
* @param importExpr
|
|
83
|
-
* @returns
|
|
80
|
+
* Checks if source file belongs to a secondary entry point different than the import one
|
|
84
81
|
*/
|
|
85
|
-
export declare function
|
|
82
|
+
export declare function belongsToDifferentNgEntryPoint(importExpr: string, filePath: string, projectRoot: string): boolean;
|
|
86
83
|
/**
|
|
87
84
|
* Returns true if the given project contains MFE config with "exposes:" section
|
|
88
85
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appIsMFERemote = exports.
|
|
3
|
+
exports.appIsMFERemote = exports.belongsToDifferentNgEntryPoint = exports.groupImports = exports.isTerminalRun = exports.hasBuildExecutor = exports.isDirectDependency = exports.hasBannedDependencies = exports.findTransitiveExternalDependencies = exports.hasBannedImport = exports.getSourceFilePath = exports.onlyLoadChildren = exports.findConstraintsFor = exports.findProjectUsingImport = exports.isAbsoluteImportIntoAnotherProject = exports.findProject = exports.getTargetProjectBasedOnRelativeImport = exports.isRelative = exports.matchImportWithWildcard = exports.findDependenciesWithTags = exports.isComboDepConstraint = exports.hasNoneOfTheseTags = exports.stringifyTags = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -311,17 +311,21 @@ function groupImports(importsToRemap) {
|
|
|
311
311
|
}
|
|
312
312
|
exports.groupImports = groupImports;
|
|
313
313
|
/**
|
|
314
|
-
* Checks if
|
|
315
|
-
* @param targetProjectLocator
|
|
316
|
-
* @param importExpr
|
|
317
|
-
* @returns
|
|
314
|
+
* Checks if source file belongs to a secondary entry point different than the import one
|
|
318
315
|
*/
|
|
319
|
-
function
|
|
320
|
-
const
|
|
321
|
-
|
|
316
|
+
function belongsToDifferentNgEntryPoint(importExpr, filePath, projectRoot) {
|
|
317
|
+
const resolvedImportFile = (0, internal_1.resolveModuleByImport)(importExpr, filePath, // not strictly necessary, but speeds up resolution
|
|
318
|
+
(0, path_1.join)(devkit_1.workspaceRoot, (0, js_1.getRootTsConfigFileName)()));
|
|
319
|
+
if (!resolvedImportFile) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
const importEntryPoint = getAngularEntryPoint(resolvedImportFile, projectRoot);
|
|
323
|
+
const srcEntryPoint = getAngularEntryPoint(filePath, projectRoot);
|
|
324
|
+
// check if the entry point of import expression is different than the source file's entry point
|
|
325
|
+
return importEntryPoint !== srcEntryPoint;
|
|
322
326
|
}
|
|
323
|
-
exports.
|
|
324
|
-
function
|
|
327
|
+
exports.belongsToDifferentNgEntryPoint = belongsToDifferentNgEntryPoint;
|
|
328
|
+
function getAngularEntryPoint(file, projectRoot) {
|
|
325
329
|
let parent = (0, devkit_1.joinPathFragments)(file, '../');
|
|
326
330
|
while (parent !== `${projectRoot}/`) {
|
|
327
331
|
// we need to find closest existing ng-package.json
|
|
@@ -330,11 +334,11 @@ function fileIsSecondaryEntryPoint(file, projectRoot) {
|
|
|
330
334
|
if (ngPackageContent) {
|
|
331
335
|
// https://github.com/ng-packagr/ng-packagr/blob/23c718d04eea85e015b4c261310b7bd0c39e5311/src/ng-package.schema.json#L54
|
|
332
336
|
const entryFile = (0, devkit_1.parseJson)(ngPackageContent)?.lib?.entryFile;
|
|
333
|
-
return
|
|
337
|
+
return (0, devkit_1.joinPathFragments)(parent, entryFile);
|
|
334
338
|
}
|
|
335
339
|
parent = (0, devkit_1.joinPathFragments)(parent, '../');
|
|
336
340
|
}
|
|
337
|
-
return
|
|
341
|
+
return undefined;
|
|
338
342
|
}
|
|
339
343
|
/**
|
|
340
344
|
* Returns true if the given project contains MFE config with "exposes:" section
|