🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

eslint-plugin-path

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-path

An ESLint plugin for enforcing consistent imports across project. In other words, it helps to replace all relatives import with absolutes dependinng on settings.

2.0.2
latest
Source
npm
Version published
Weekly downloads
9.2K
5.14%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-path code style: 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

# 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.

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:

{
  "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:

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:

{
  "settings": {
    "path": {
      "config": "tsconfig.json" // or "./jsconfig.json"
    }
  }
}

Configuration

Enable the rules in your ESLint configuration file:

{
  "plugins": ["path"],
  "rules": {
    "path/no-relative-imports": "error",
  },
}

Or add the "recommended" preset:

{
  "extends": ["plugin:path/recommended"]
}

Rules

✔ included in the "recommended" preset

🔧 fixable using the --fix command line option

NameDescription
🔧no-relative-importsdisallow relative imports of files where absolute is preferred
🔧no-absolute-importsdisallow absolute imports of files where relative is preferred
🔧only-absolute-importsdisallow relative imports of files through the whole project

Presets

  • recommended enables rules recommended for all users
  • all enables all rules

License

MIT

Keywords

eslint

FAQs

Package last updated on 07 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts