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

Suggestion: Add Rule to Disallow Imports Between Certain Packages #11

Open
fabb opened this issue Sep 15, 2020 · 3 comments
Open

Suggestion: Add Rule to Disallow Imports Between Certain Packages #11

fabb opened this issue Sep 15, 2020 · 3 comments

Comments

@fabb
Copy link

fabb commented Sep 15, 2020

Our repo is structured into yarn workspaces like this:

  • applications/app1
  • applications/app2
  • common/c1
  • common/c2

The desired rule is that applications might import from packages common/c1 and common/c2, but never from another application. In other words, in app1 there must never be an import from app2.

Currently we use depencency-cruiser for such advanced checks. Sounds like a good use case for this plugin though.

@chin2km
Copy link

chin2km commented Apr 19, 2021

Was looking for the exact same feature :) Is this somehow possible using this package or any other lint plugin?

@thekip
Copy link

thekip commented Sep 6, 2021

assume your application package has an @Application prefix then, using standard eslint rule

"no-restricted-imports": ["error",
      {
        name: '@applications/*',
        message: 'Please don't import from another application. Extract common parts into separate package.'
      }
    ]

And you either can put this into your root .eslintrc.js or create a dedicated in a sub-package folder.

@AlonMiz
Copy link
Contributor

AlonMiz commented Nov 28, 2021

what about cases of importing a backend package from a frontend package?

"no-restricted-imports": ["error",
      {
        restrictImportOf: '@backend/*',
        restrictOnlyFrom:  '@frontend/*',
        message: 'Please don't import packages from backend to frontend code.'
      },
      {
        restrictImportOf: '@frontend/*',
        restrictOnlyFrom:  '@backend/*',
        message: 'Please don't import packages from frontend to backend code.'
      }
    ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants