Skip to content

Latest commit

 

History

History
107 lines (83 loc) · 2.17 KB

no-unknown.md

File metadata and controls

107 lines (83 loc) · 2.17 KB

boundaries/no-unknown

Prevent importing unknown elements from the known ones

Rule details

It checks import statements to local files. If the imported file is not recognized as any of the element types from settings, the import will be notified as an error.

Options

"boundaries/no-unknown": [<enabled>]
  • enabled: for enabling the rule. 0=off, 1=warn, 2=error.
Options example
{
  "rules": {
    "boundaries/no-unknown": [2]
  }
}

Settings

Examples in the next sections are based on the previous options example and these files and settings.

src/
├── components/
│   └─ atoms/
│       ├── atom-a/
│       │   ├── index.js
│       │   └── AtomA.js
│       └── atom-b/
│           ├── index.js
│           └── AtomB.js
├── helpers/
│   ├── data/
│   │   ├── sort.js
│   │   └── parse.js
│   └── permissions/
│       └── roles.js
│
├── foo.js
└── index.js
{
  "settings": {
    "boundaries/elements": [
      {
        "type": "helpers",
        "pattern": "helpers/*/*.js",
        "mode": "file",
        "capture": ["category", "elementName"]
      },
      {
        "type": "components",
        "pattern": "components/*/*",
        "mode": "folder",
        "capture": ["family", "elementName"]
      }
    ]
  }
}

Examples of incorrect files for this rule:

Helpers can't import foo.js file because it is unknown

// src/helpers/data/parse.js
import foo from '../../foo'

Components can't import index.js file because it is unknown

// src/components/atoms/atom-a/AtomA.js
import index from '../../../index'

Examples of correct files for this rule:

Components can import helpers

// src/components/atoms/atom-a/AtomA.js
import index from '../../../helpers/data/parse'

index.js file can import foo.js file because both are unknown

// src/index.js
import foo from './foo'

Further reading