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

Allow imports from a given nested folder #328

Open
Igorkowalski94 opened this issue Apr 11, 2024 · 3 comments
Open

Allow imports from a given nested folder #328

Igorkowalski94 opened this issue Apr 11, 2024 · 3 comments
Assignees
Labels
stage: needs information Not enough info to reproduce the issue

Comments

@Igorkowalski94
Copy link

Igorkowalski94 commented Apr 11, 2024

Hello,

Is it possible to write such a rule?

  • Feature cannot import files from other features unless they are in the features/shared folder.

I tried this configuration but unfortunately it doesn't work.

 "settings": {
        "boundaries/elements": [
            {
                "type": "features",
                "pattern": "features/*",
                "mode": "folder"
            },
            {
                "type": "featuresShared",
                "pattern": "features/shared/*",
                "mode": "folder"
            }
        ],
        "import/resolver": {
            "typescript": {
                "alwaysTryTypes": true
            }
        }
    },
    "rules": {
        "boundaries/element-types": [
            2,
            {
                "default": "disallow",
                "rules": [
                    {
                        "from": "features",
                        "allow": [
                            "featuresShared"
                        ]
                    }
                ]
            }
        ],
    }
.
├── ...
└── 📂 src
    └── 📂 features
        ├── 📂 shared
        ├── 📂 Feature1
        └── 📂 Feature2
 
@Igorkowalski94 Igorkowalski94 changed the title Independent folder from other children Allow imports from a given nested folder Apr 11, 2024
@javierbrea
Copy link
Owner

Hi @Igorkowalski94 , could you please provide more details? You can enable the debug mode in order to see which element type the plugin is assigning to each file by using the ESLINT_PLUGIN_BOUNDARIES_DEBUG environment variable.

ESLINT_PLUGIN_BOUNDARIES_DEBUG=1 npm run lint

@javierbrea javierbrea self-assigned this Apr 12, 2024
@javierbrea javierbrea added the stage: needs information Not enough info to reproduce the issue label Apr 12, 2024
@Igorkowalski94
Copy link
Author

Igorkowalski94 commented Apr 12, 2024

I have the following structure:

.
├── ...
└── 📂 src
    ├── ...
    └── 📂 features
        ├── ...
        ├── 📂 Feature1
        │   ├── 📄 Feature1.tsx
        │   ├── 📄 feature1.types.ts   
        │   ├── 📂 helpers             // Helpers only for Feature1 folder
        │   └── 📂 components          // Components only for Feature1 folder
        │        ├── ...
        │        ├── 📂 Child1         // Same structure as Child2
        │        └── 📂 Child2
        │            ├── 📄 Child2.tsx
        │            ├── 📄 child2.types.ts  
        │            ├── 📂 helpers           // Helpers only for Child2 folder     
        │            └── 📂 components       // Components only for Child2 folder
        │ 
        └── 📂 Feature2 // Same structure as Feature1

I would like to achieve the following rules:

  • The Feature1 can import Feature2.tsx and feature2.types.tsx but cannot import Feature2 components and helpers.
  • The Feature2 can import Feature1.tsx and feature1.types.tsx but cannot import Feature1 components and helpers.
  • Feature1.tsx can import Child1.tsx, child1.types.ts and Child2.tsx, child2.types.ts but cannot import their components and helpers.
  • Child1 folder can import Child2.tsx and child2.types.ts but cannot import Child2 components and helpers.
  • Child2 folder can import Child1.tsx and child1.types.ts but cannot import Child1 components and helpers.
  • The entire components and helpers folder and Feature1.tsx can import feature1.types.ts

I tried many configurations but couldn't achieve these rules. Is it possible?

@javierbrea
Copy link
Owner

Yes, it is possible, but you should try to debug your configuration in order to know if your elements are being categorized properly. I suspect that maybe all of them are being categorized as features because they match first the features pattern, but I'm not sure. Could you please provide logs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants