Code Monkey home page Code Monkey logo

eslint-plugin-no-relative-import-paths's Introduction

eslint-plugin-no-relative-import-paths

Moving a file to different folder, could result in changing all imports statement in that file. This will not happen is the import paths are absolute. The eslint rule helps enforcing having absolute import paths. Support eslint --fix to automatically change imports to absolute paths.

Installation

Install ESLint either locally or globally. (Note that locally, per project, is strongly preferred)

$ npm install eslint --save-dev

If you installed ESLint globally, you have to install this plugin globally too. Otherwise, install it locally.

$ npm install eslint-plugin-no-relative-import-paths --save-dev

Configuration

Add the plugin to the plugins section, and configure the rule options.

{
  "plugins": ["no-relative-import-paths"],
  "rules": {
    "no-relative-import-paths/no-relative-import-paths": [
      "warn",
      { "allowSameFolder": true }
    ]
  }
}

Rule options

...
"no-relative-import-paths/no-relative-import-paths": [
  "warn",
  { "allowSameFolder": true, "rootDir": "src" }
]
...
  • enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
  • ignorePureComponents: optional boolean set to true to allow relative import paths for imported files from the same folder (default to false).

allowSameFolder

When true the rule will ignore relative import paths for imported files from the same folder

Examples of code for this rule:

// when true this will be ignored
// when false this will generate a warning
import Something from "./something";

// will always generate a warning
import Something from "../modules/something";

rootDir

Useful when auto-fixing and the rootDir should not be included in the absolute path.

Examples of code for this rule:

// when not configured:
import Something from "../../components/something";

// will result in
import Something from "src/components/something";
// when configured as { "rootDir": "src" }
import Something from "../../components/something";

// will result in
import Something from "components/something";
//                     ^- no 'src/' prefix is added

eslint-plugin-no-relative-import-paths's People

Contributors

andidev avatar awesometic avatar joelbourbon avatar maerten avatar melvinvermeer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.