Skip to content

joshmadewell/eslint-plugin-replace-relative-imports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-replace-relative-imports

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.

Usage

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" }
      ]
    }]
  }
}

Configuration

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" }
      ]
    }]
  }
}

License

MIT

About

ESLint plugin which replaces relative imports with a defined alias

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published