Skip to content

No enforce boundaries lint error when importing a non project file Β #20408

@Roozenboom

Description

@Roozenboom

Current Behavior

When you import a file that is not part of a project by the relative path that goes outside of the current project root, the eslint rule @nx/enforce-module-boundaries is not throwing an error. When you do the same relative import for a file that belongs to a project it shows the error as expected.

Expected Behavior

We want to prevent any relative import outside the project root, it doesn't matter if the relative import is a project file or a non-project file. Currently the linting works for project files but not for non-project files which can cause unexpected behavior

GitHub Repo

nrwl/nx-examples#311

Steps to Reproduce

I created a reproduce-able scenario for this issue in nx-examples:

  1. I created 2 components, one as a project and the other one as a non-project
    a. non-project: libs/shared/product/components/non-project/index.ts
    b. project: libs/shared/product/components/project/project.json
  2. I added imports to both components in the product-home-page libs/products/home-page/src/lib/products-home-page.module.ts
  3. When you use relative imports, the project will show an eslint error, but the non-project import is ok.
    a. When you change the project component import to the npm scoped import this import is also ok.

Screenshot 2023-11-24 at 11 34 53

  1. When I analyse the file-deps.json I see that the non-project import is a npm dependency with the relative path to the file. But because it is marked as npm: the linting rule will not complain.

Screenshot 2023-11-24 at 11 34 12

Nx Report

Node   : 20.9.0
   OS     : darwin-arm64
   yarn   : 1.22.19
   
   nx                 : 17.1.3
   @nx/js             : 17.1.3
   @nx/jest           : 17.1.3
   @nx/linter         : 17.1.3
   @nx/eslint         : 17.1.3
   @nx/workspace      : 17.1.3
   @nx/angular        : 17.1.3
   @nx/cypress        : 17.1.3
   @nx/devkit         : 17.1.3
   @nx/eslint-plugin  : 17.1.3
   @nx/react          : 17.1.3
   @nrwl/tao          : 17.1.3
   @nx/web            : 17.1.3
   @nx/webpack        : 17.1.3
   typescript         : 5.2.2
   ---------------------------------------
   Community plugins:
   @ngrx/component-store : 16.0.0
   @ngrx/effects         : 16.0.0
   @ngrx/entity          : 16.0.0
   @ngrx/router-store    : 16.0.0
   @ngrx/store           : 16.0.0
   @ngrx/store-devtools  : 16.0.0

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions