javierbrea / eslint-plugin-boundaries

Eslint plugin checking architecture boundaries between elements
MIT License
473 stars 9 forks source link

Allow imports from a given nested folder #328

Open Igorkowalski94 opened 2 months ago

Igorkowalski94 commented 2 months ago

Hello,

Is it possible to write such a rule?

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
javierbrea commented 2 months ago

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
Igorkowalski94 commented 2 months ago

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:

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

javierbrea commented 2 months ago

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?