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
common
level only fromcommon
level - at
desktop
level fromcommon
anddesktop
levels - at
mobile
level fromcommon
andmobile
levels
Also you want to disallow imports:
- at
common
level fromdesktop
andmobile
levels - at
desktop
level frommobile
level - at
mobile
level fromdesktop
level
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.
// [email protected]
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.
// [email protected]
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.
// [email protected]
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 [email protected]
and [email protected]
, 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$"
]