https://github.com/qdanik/eslint-plugin-path
An ESLint plugin for enforcing consistent imports across project.
https://github.com/qdanik/eslint-plugin-path
eslint eslint-plugin import javascript lint linting relative-path
Last synced: 27 days ago
JSON representation
An ESLint plugin for enforcing consistent imports across project.
- Host: GitHub
- URL: https://github.com/qdanik/eslint-plugin-path
- Owner: qdanik
- License: mit
- Created: 2022-03-28T20:48:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-06T17:58:59.000Z (3 months ago)
- Last Synced: 2025-04-06T18:01:34.479Z (3 months ago)
- Topics: eslint, eslint-plugin, import, javascript, lint, linting, relative-path
- Language: JavaScript
- Homepage:
- Size: 295 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-plugin-path [](https://github.com/prettier/prettier)
An ESLint plugin for enforcing consistent imports across project. In other words, it helps to replace all relatives import with absolutes dependinng on settings.
## Installation
```sh
# npm
npm install eslint-plugin-path --save-dev# yarn
yarn add eslint-plugin-path --dev
```## ESlint 9+
If you are using ESLint 9 or later, you can use the plugin without any additional configuration. Just install it and add it to your ESLint configuration.
```js
import eslintPluginPath from 'eslint-plugin-path';export default [
{
files: ['*.{js,ts,jsx,tsx}'],
plugins: {
path: eslintPluginPath,
},
rules: {
'path/no-relative-imports': [
'error',
{
maxDepth: 2,
suggested: false,
},
],
},
},
];
```## ESlint 8 and below
If you are using ESLint 8 or below, you need to add the plugin to your ESLint configuration file. You can do this by adding the following lines to your `.eslintrc` file:
```json
{
"plugins": ["path"],
"extends": ["plugin:path/recommended"] // optional
"rules": {
"path/no-relative-imports": [
"error",
{
"maxDepth": 2,
"suggested": false
}
]
}
}
```
Or if you are using a JavaScript configuration file, you can add the following lines to your `.eslintrc.js` file:```js
module.exports = {
plugins: ['path'],
extends: ['plugin:path/recommended'], // optional
rules: {
'path/no-relative-imports': [
'error',
{
maxDepth: 2,
suggested: false,
},
],
},
};
```## Custom tsconfig/jsconfig paths
If you are using custom paths in your `tsconfig.json` or `jsconfig.json` file, you can specify the path to the configuration file in the ESLint configuration file. You can do this by adding the following lines to your config file:```json
{
"settings": {
"path": {
"config": "tsconfig.json" // or "./jsconfig.json"
}
}
}
```## Configuration
Enable the rules in your ESLint configuration file:
```json
{
"plugins": ["path"],
"rules": {
"path/no-relative-imports": "error",
},
}
```Or add the "recommended" preset:
```json
{
"extends": ["plugin:path/recommended"]
}
```## Rules
✔ included in the "recommended" preset
🔧 fixable using the `--fix` command line option
| | | Name | Description |
| --- | --- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| ✔ | 🔧 | [no-relative-imports](https://github.com/qDanik/eslint-plugin-path/blob/main/docs/rules/no-relative-imports.md) | disallow relative imports of files where absolute is preferred |
| | 🔧 | [no-absolute-imports](https://github.com/qDanik/eslint-plugin-path/blob/main/docs/rules/no-absolute-imports.md) | disallow absolute imports of files where relative is preferred |
| | 🔧 | [only-absolute-imports](https://github.com/qDanik/eslint-plugin-path/blob/main/docs/rules/only-absolute-imports.md) |disallow relative imports of files through the whole project |## Presets
- `recommended` enables rules recommended for all users
- `all` enables all rules# License
[MIT](https://github.com/qDanik/eslint-plugin-path/blob/main/LICENSE)