javierbrea / eslint-plugin-boundaries

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

Types are not counted as files from elements which declared with mode: 'files' #316

Closed budarin closed 7 months ago

budarin commented 7 months ago

Describe the bug Folder structure:

src/
├── core/
│   └── domain/
│       └── entities
│           ├── task
│           │   ├── createTask.ts
│           │   ├── types.ts

when 'entities' have been described as

'boundaries/elements': [
  {
      type: 'entities',
      pattern: 'src/core/domain/entities/*',
      mode: 'file',
  },
]

and then allowed in element-types as

'boundaries/element-types': [
  2,
  {
    {
        from: 'contracts',
        allow: [ 'entities' ],
        importKind: 'type',
    }
  }
]

and imported types from entities in contracts

// src/core/contracts/api.ts
import type { Task } from 'entities/task/types.ts';
...

it leads to the error: Importing unknown elements is not allowed

only describing entities twice as file and as folder

'boundaries/elements': [
  {
      type: 'entities',
      pattern: 'src/core/domain/entities/*',
      mode: 'file',
  },
  {
      type: 'entities',
      pattern: 'src/core/domain/entities/*',
      mode: 'folder',
  },
]

prevents the occurrence of an error

Expected behavior It is expected that files of the types described in element-types as files would be recognized by the plugin as known

Logs

[boundaries]: 'src/core/domain/entities/task/types.ts' is of unknown type
{
  "source": "entities/task/types.ts",
  "path": "src/core/domain/entities/task/types.ts",
  "isIgnored": false,
  "isLocal": true,
  "isBuiltIn": false,
  "isExternal": false,
  "baseModule": null,
  "type": null,
  "elementPath": null,
  "capture": null,
  "capturedValues": null,
  "internalPath": null,
  "parents": []
}

Operating system, Node.js an npm versions, and eslint version (please complete the following information):

javierbrea commented 7 months ago

Hi, It seems that your configuration is wrong:

The pattern src/core/domain/entities/* does not match with the file src/core/domain/entities/task/types.ts. It would match with src/core/domain/entities/types.ts. So, I suppose that your pattern should be src/core/domain/entities/*/*, or src/core/domain/entities/**/*, if you want to match files at any folder level.

You can read the micromatch documentation for further info.

budarin commented 7 months ago

Hi, It seems that your configuration is wrong:

Thanks! it helped!