Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect up a directory then down the same directory #471

Closed
graingert opened this issue Aug 2, 2016 · 22 comments
Closed

detect up a directory then down the same directory #471

graingert opened this issue Aug 2, 2016 · 22 comments

Comments

@graingert
Copy link
Contributor

graingert commented Aug 2, 2016

I have a structure like:

/ham/egg/chips/index.js
/ham/egg/foo.js

then in /ham/egg/chips/index.js I sometimes have code that accidental ends up like:

import x from '../../egg/foo.js'

but I'd much rather it be:

import x from '../foo.js'
@benmosher
Copy link
Member

benmosher commented Aug 2, 2016

Ooo, nice. Yeah, that would be cool. Not sure what to call it, but would be a pretty straightforward rule. Would basically enforce that the path be the same as the path.relative(currentFile, importedFile).

Need a good name, though. shortest-path?

(edit: I initially misused path.resolve when I meant path.relative)

@graingert
Copy link
Contributor Author

graingert commented Aug 2, 2016

import/no-up-a-directory-then-down-the-same-directory ;)

Could also be an easy auto fix too

@jfmengels
Copy link
Collaborator

👍

no-extraneous-path / no-extraneous-relative-path?

@benmosher
Copy link
Member

@jfmengels ooo, I like [something]-relative-path. extraneous doesn't have the right connotation for this case, though, I think. #bikeshedding

shortest-relative-path?

@jfmengels
Copy link
Collaborator

I think extraneous fits, as you have extraneous "steps".
Otherwise no-superfluous, no-unneeded, no-unnecessary, ...

I'd be fine with shortest-relative-path too (though I dig it less than extraneous at the moment 😄 ).

@graingert
Copy link
Contributor Author

I like extraneous

On 2 Aug 2016 21:52, "Jeroen Engels" [email protected] wrote:

I think extraneous fits, as you have extraneous "steps".
Otherwise no-superfluous, no-unneeded, no-unnecessary, ...

I'd be fine with shortest-relative-path too (though I dig it less than
extraneous at the moment 😄 ).


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#471 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZQTNDFlwIECuF3AbHx0h1XGqT_jRGfks5qb63tgaJpZM4Ja5Zv
.

@benmosher
Copy link
Member

I guess I've just got other meaning primed for extraneous from the no-extraneous-deps issue discussion. Feels like this is something else to me. also no-extraneous-relative-path is a mouthful. (keyboardful?)

also also I don't love no- for this, I think because it's more enforcing a good thing (shorter path) than rejecting a bad thing (longer path).

I have weak and meandering enough opinions on this that I'm going to abstain from further name discussion. no-/extraneous-something is fine. 🤓

@jfmengels
Copy link
Collaborator

I'm starting to like shortest-relative-path (I agree that extraneous is a mouthful). Maybe let me sleep on it 😄

@graingert
Copy link
Contributor Author

You can't use "relative" because it's redundant. All paths in node are
relative

On 2 Aug 2016 22:10, "Jeroen Engels" [email protected] wrote:

I'm starting to like shortest-relative-path (I agree that extraneous is a
mouthful). Maybe let me sleep on it 😄


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#471 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZQTEVUa8tipYDQVhvCsB4lfr0aeDpGks5qb7JJgaJpZM4Ja5Zv
.

@benmosher
Copy link
Member

NODE_PATH lets you around that. I'm fine with shortest-path but I think it's less obvious. #abstainfail

@graingert
Copy link
Contributor Author

NODE_PATH and support for other non relative paths is being removed
https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md#521-removal-of-non-local-dependencies

On 2 Aug 2016 22:30, "Ben Mosher" [email protected] wrote:

NODE_PATH lets you around that. I'm fine with shortest-path but I think
it's less obvious. #abstainfail


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#471 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZQTKFXv_49YOg4oX-At_WcMTRb2yRtks5qb7b5gaJpZM4Ja5Zv
.

@jfmengels
Copy link
Collaborator

You can't use "relative" because it's redundant. All paths in node are relative

External modules (things installed with npm for instance), internal modules (when you use Webpack) are not relative. Also, I'm pretty sure you can specify an absolute path.

@jfmengels
Copy link
Collaborator

NODE_PATH and support for other non relative paths is being removed
https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md#521-removal-of-non-local-dependencies

Does that also apply to require statements, or only import?

@graingert
Copy link
Contributor Author

External modules are actually relative to the current module, they just go
up to the nearest node_modules dir. Absolute paths will never trigger this
issue

On 2 Aug 2016 22:39, "Jeroen Engels" [email protected] wrote:

You can't use "relative" because it's redundant. All paths in node are
relative

External modules (things installed with npm for instance), internal
modules (when you use Webpack) are not relative. Also, I'm pretty sure you
can specify an absolute path.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#471 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZQTOnDelfmoh7knaWHvwojkUzEtu-cks5qb7krgaJpZM4Ja5Zv
.

@graingert
Copy link
Contributor Author

Only import, but I presume everyone will switch to import/ whatever dynamic
module loading gets specified

On 2 Aug 2016 22:41, "Thomas Grainger" [email protected] wrote:

External modules are actually relative to the current module, they just go
up to the nearest node_modules dir. Absolute paths will never trigger this
issue

On 2 Aug 2016 22:39, "Jeroen Engels" [email protected] wrote:

You can't use "relative" because it's redundant. All paths in node are
relative

External modules (things installed with npm for instance), internal
modules (when you use Webpack) are not relative. Also, I'm pretty sure you
can specify an absolute path.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#471 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZQTOnDelfmoh7knaWHvwojkUzEtu-cks5qb7krgaJpZM4Ja5Zv
.

@benmosher
Copy link
Member

@graingert mind blown.

@jfmengels
Copy link
Collaborator

I'd still like to see this implemented. If someone wants to have a go at it, let's go with no-extraneous-path as the name until someone has a good reason against it or a better name. But let the name not be a blocker for this nice idea.

@graingert
Copy link
Contributor Author

@benmosher another aberration I've discovered in my travels:

import foo from './../foo';

which should of course be

import foo from '../foo';

graingert added a commit to graingert/eslint-plugin-import that referenced this issue Aug 8, 2017
graingert added a commit to graingert/eslint-plugin-import that referenced this issue Aug 8, 2017
graingert added a commit to graingert/eslint-plugin-import that referenced this issue Aug 8, 2017
graingert added a commit to graingert/eslint-plugin-import that referenced this issue Aug 8, 2017
graingert added a commit to graingert/eslint-plugin-import that referenced this issue Aug 8, 2017
@graingert
Copy link
Contributor Author

@benmosher I've bike-sheded this a bit more, and think that no-useless-path-segments would be the best. To go with the other eslint "no-useless-" rules.

@danny-andrews
Copy link
Contributor

danny-andrews commented Aug 16, 2017

simplest-path?
simplest-local-path?

@graingert
Copy link
Contributor Author

graingert commented Aug 16, 2017

I'd like it to start with no- or no-useless-

@ljharb
Copy link
Member

ljharb commented Aug 16, 2017

no-useless-path-segments; see #912.

graingert added a commit to graingert/eslint-plugin-import that referenced this issue Aug 16, 2017
graingert added a commit to graingert/eslint-plugin-import that referenced this issue Sep 4, 2017
danny-andrews pushed a commit to graingert/eslint-plugin-import that referenced this issue Oct 29, 2017
ljharb pushed a commit to graingert/eslint-plugin-import that referenced this issue Dec 19, 2017
ljharb pushed a commit to graingert/eslint-plugin-import that referenced this issue Dec 19, 2017
ljharb added a commit that referenced this issue Dec 19, 2017
add no-useless-path-segments rule Fixes #471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants