Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 4 tasks
Roozenboom opened this issue Nov 24, 2023 · 2 comments · Fixed by #20563
Closed
1 of 4 tasks

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

Roozenboom opened this issue Nov 24, 2023 · 2 comments · Fixed by #20563
Assignees
Labels
outdated scope: core core nx functionality scope: linter Issues related to Eslint support in Nx type: bug

Comments

@Roozenboom
Copy link
Contributor

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

@AgentEnder AgentEnder added the scope: linter Issues related to Eslint support in Nx label Dec 1, 2023
@meeroslav meeroslav self-assigned this Dec 4, 2023
@meeroslav meeroslav added the scope: core core nx functionality label Dec 4, 2023
@meeroslav
Copy link
Contributor

meeroslav commented Dec 4, 2023

Hmm... this is interesting. It's going beyond just the linter since the graph is effectively broken by marking that file as an npm dependency.

I will create the fix from the linter side but we need to follow up on this in the graph creation function.

@AgentEnder @FrozenPandaz do we have a way of marking non-npm external dependencies?

Copy link

github-actions bot commented Jan 5, 2024

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: core core nx functionality scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants