Skip to content

Latest commit

 

History

History
61 lines (42 loc) · 1.43 KB

no-relative-packages.md

File metadata and controls

61 lines (42 loc) · 1.43 KB

import-x/no-relative-packages

🔧 This rule is automatically fixable by the --fix CLI option.

Use this rule to prevent importing packages through relative paths.

It's useful in a monorepo setup, where it's possible to import a sibling package using ../package relative path, while direct package is the correct one.

Examples

Given the following folder structure:

my-project
├── packages
│   ├── foo
│   │   ├── index.js
│   │   └── package.json
│   └── bar
│       ├── index.js
│       └── package.json
└── entry.js

And the .eslintrc file:

{
  ...
  "rules": {
    "import-x/no-relative-packages": "error"
  }
}

The following patterns are considered problems:

/** In my-project/packages/foo.js */

import bar from '../bar' // Import sibling package using relative path
import entry from '../../entry.js' // Import from parent package using relative path

/** In my-project/entry.js */

import bar from './packages/bar' // Import child package using relative path

The following patterns are NOT considered problems:

/** In my-project/packages/foo.js */

import bar from 'bar' // Import sibling package using package name

/** In my-project/entry.js */

import bar from 'bar' // Import sibling package using package name