This plugin replaces relative parent imports with a defined alias and is meant to be
used in conjunction with applications built with either webpack alias
definitions
or paths
for typescript.
Add replace-relative-imports
to the plugins section of your eslint
configuration.
{
"plugins": ["replace-relative-imports"]
}
Then add the replace imports rule:
{
"rules": {
"replace-relative-imports/replace": ["error", {
"aliases": [
{ "name": "app", "path": "./src" }
]
}]
}
}
The "aliases" object is required in the configuration. You may define multiple aliases. If an alias is not found for a specific import, an error will be thrown for that import. You may also specify blobs in the "ignore" array in order to ignore specific files.
Options:
name | description | default |
---|---|---|
alias (required) | The list of aliases which will be matched for and replaced | |
method | The type of replacement, either all relative paths (./ included) or only parent imports (importPath.startsWith('../') ) |
"only-parent" |
ignore | List of blobs which this rule should ignore | [] |
Example:
{
"rules": {
"replace-relative-imports/replace": ["error", {
"ignore": ["**/__tests__/*"],
"aliases": [
{ "name": "app", "path": "./src" }
]
}]
}
}