@nx/eslint-plugin 17.2.5 → 17.2.7

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/README.md CHANGED
@@ -1,9 +1,4 @@
1
- <p style="text-align: center;">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
- <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
- </picture>
6
- </p>
1
+ <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
7
2
 
8
3
  <div style="text-align: center;">
9
4
 
@@ -20,9 +15,9 @@
20
15
 
21
16
  <hr>
22
17
 
23
- # Nx: Smart Monorepos · Fast CI
18
+ # Nx: Smart, Fast and Extensible Build System
24
19
 
25
- Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
20
+ Nx is a next generation build system with first class monorepo support and powerful integrations.
26
21
 
27
22
  This package is an ESLint plugin for Nx.
28
23
 
@@ -64,5 +59,5 @@ npx nx@latest init
64
59
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
65
60
 
66
61
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
67
- width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
62
+ width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
68
63
 
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": "v17.2.5",
3
+ "version": "17.2.7",
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": {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "homepage": "https://nx.dev",
26
26
  "peerDependencies": {
27
- "@typescript-eslint/parser": "^6.13.2",
27
+ "@typescript-eslint/parser": "^6.9.1",
28
28
  "eslint-config-prettier": "^9.0.0"
29
29
  },
30
30
  "peerDependenciesMeta": {
@@ -33,16 +33,16 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@nx/devkit": "v17.2.5",
37
- "@nx/js": "v17.2.5",
38
- "@typescript-eslint/type-utils": "^6.13.2",
39
- "@typescript-eslint/utils": "^6.13.2",
36
+ "@nx/devkit": "17.2.7",
37
+ "@nx/js": "17.2.7",
38
+ "@typescript-eslint/type-utils": "^6.9.1",
39
+ "@typescript-eslint/utils": "^6.9.1",
40
40
  "chalk": "^4.1.0",
41
41
  "confusing-browser-globals": "^1.0.9",
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": "v17.2.5"
45
+ "@nrwl/eslint-plugin-nx": "17.2.7"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"
@@ -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/foo": "error"
11
+ * "@nx/workspace-foo": "error"
11
12
  */
12
- export declare const WORKSPACE_RULE_NAMESPACE = "workspace";
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.WORKSPACE_RULE_NAMESPACE = exports.WORKSPACE_PLUGIN_DIR = void 0;
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.WORKSPACE_PLUGIN_DIR = (0, path_1.join)(devkit_1.workspaceRoot, 'tools/eslint-rules');
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/foo": "error"
16
+ * "@nx/workspace-foo": "error"
16
17
  */
17
- exports.WORKSPACE_RULE_NAMESPACE = 'workspace';
18
+ exports.WORKSPACE_RULE_PREFIX = 'workspace';
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function renameWorkspaceRule(tree: Tree): Promise<void>;
@@ -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.WORKSPACE_RULE_NAMESPACE}/${ruleName}`] = ruleConfig;
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.isAngularSecondaryEntrypoint)(imp, sourceFilePath, sourceProject.data.root)) {
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 import points to a secondary entry point in Angular project
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 isAngularSecondaryEntrypoint(importExpr: string, filePath: string, projectRoot: string): boolean;
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.isAngularSecondaryEntrypoint = 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;
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 import points to a secondary entry point in Angular project
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 isAngularSecondaryEntrypoint(importExpr, filePath, projectRoot) {
320
- const resolvedModule = (0, internal_1.resolveModuleByImport)(importExpr, filePath, (0, path_1.join)(devkit_1.workspaceRoot, (0, js_1.getRootTsConfigFileName)()));
321
- return (!!resolvedModule && fileIsSecondaryEntryPoint(resolvedModule, projectRoot));
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.isAngularSecondaryEntrypoint = isAngularSecondaryEntrypoint;
324
- function fileIsSecondaryEntryPoint(file, projectRoot) {
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 entryFile && file === (0, devkit_1.joinPathFragments)(parent, entryFile);
337
+ return (0, devkit_1.joinPathFragments)(parent, entryFile);
334
338
  }
335
339
  parent = (0, devkit_1.joinPathFragments)(parent, '../');
336
340
  }
337
- return false;
341
+ return undefined;
338
342
  }
339
343
  /**
340
344
  * Returns true if the given project contains MFE config with "exposes:" section