This rule is needed to check imports according to redefinition levels whitelist.
This rule has three options.
For example, in a project with three redefinition levels — common, desktop and mobile, you want to allow imports:
- at
commonlevel only fromcommonlevel - at
desktoplevel fromcommonanddesktoplevels - at
mobilelevel fromcommonandmobilelevels
Also you want to disallow imports:
- at
commonlevel fromdesktopandmobilelevels - at
desktoplevel frommobilelevel - at
mobilelevel fromdesktoplevel
You can describe similar restrictions using whiteList option:
"whiteList": {
"common": ["common"],
"desktop": ["common", "desktop"],
"mobile": ["common", "mobile"]
}Now at common redefinition level you can import only from common level.
// Button@common.tsx
import { Icon } from '../Icon/Icon'; // Good
import { Icon } from '../Icon/Icon@common'; // Good
import { Icon } from '../Icon/Icon@mobile'; // No, it's wrong!
import { Icon } from '../Icon/Icon@desktop'; // No, it's wrong!At desktop redefinition level you can import from common and desktop levels, but not from mobile level.
// Button@desktop.tsx
import { Icon } from '../Icon/Icon'; // Good
import { Icon } from '../Icon/Icon@common'; // Good
import { Icon } from '../Icon/Icon@desktop'; // Good
import { Icon } from '../Icon/Icon@mobile'; // No, it's wrong!And at mobile redefinition level you can import from common and mobile levels, but not from desktop level.
// Button@mobile.tsx
import { Icon } from '../Icon/Icon'; // Good
import { Icon } from '../Icon/Icon@common'; // Good
import { Icon } from '../Icon/Icon@mobile'; // Good
import { Icon } from '../Icon/Icon@desktop'; // No, it's wrong!The linter tries to determine a redefinition level of a file by it's filename. So for files like Icon@desktop.tsx and Icon@desktop.example.tsx, the redefinition level is desktop. For a file mobile.tsx the level is mobile, but only if this level is specified in the whiteList setting.
If the linter could not determine a redefinition level by a filename, it accepts that level is a value of defaultLevel setting. In most project this setting has a common value, but you can use other, like base or like that.
Additionally you can ignore some files, use ignorePaths option. For example:
"ignorePath": [
".example.tsx$",
".example.jsx$"
]