Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Option request: allow same folder imports (no-relative-import) #493

Closed
axelboc opened this issue Aug 17, 2018 · 6 comments · Fixed by #508
Closed

Option request: allow same folder imports (no-relative-import) #493

axelboc opened this issue Aug 17, 2018 · 6 comments · Fixed by #508
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Rule Feature Adding a feature to an existing rule.
Milestone

Comments

@axelboc
Copy link

axelboc commented Aug 17, 2018

Angular generates specs with same folder imports, like:

import { MyComponent } from './my.component';

So it would be really convenient if rule no-relative-import had an option to ignore imports that point to the same folder as the current file, with ./.

With this option enabled, the no-relative-import rule would still have to report unnecessarily complex same folder imports like ./../my/my.component.

@JoshuaKGoldberg JoshuaKGoldberg added Status: Accepting PRs Good First Issue 🙌 Howdy, neighbor! Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Type: Rule Feature Adding a feature to an existing rule. labels Aug 17, 2018
@IllusionMH
Copy link
Contributor

May I take on this?

If I understand correctly - new option should be created.
Is there any preference for option name?
Candidates:

  • allowSameFolder
  • allowSameFolderImport
  • allowSiblings

@JoshuaKGoldberg
Copy link

JoshuaKGoldberg commented Oct 1, 2018

Absolutely @IllusionMH, thanks for taking this on!

I like allowSiblings allow-siblings the most personally.

Edit: yes, what karol-majewski commented!

@karol-majewski
Copy link

karol-majewski commented Oct 1, 2018

allow-siblings or allow-same-folder perhaps? This would match the kebab-case convention used for other rules.

"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"]

@IllusionMH
Copy link
Contributor

@karol-majewski thanks for suggestions. I will use kebab-case.

@JoshuaKGoldberg I will implement with allow-siblings first, and it will be possible to decide on final name in PR.

@IllusionMH
Copy link
Contributor

Sorry for pinging all in this thread, but in the process of implementation I had another question:

Should rule allow

import { MyComponent } from './subcomponents/sub.component';

when allow-siblings is enabled?

Or it might be another option to the rule?

P.S. Its really late here, so I'll hope to submit first WIP PR tomorrow.

@JoshuaKGoldberg
Copy link

That seems reasonable to allow by default, especially for projects that store assets inline with components:

import { closeIcon } from "./my.component/assets";

IllusionMH added a commit to IllusionMH/tslint-microsoft-contrib that referenced this issue Oct 2, 2018
JoshuaKGoldberg pushed a commit that referenced this issue Oct 5, 2018
* Clean up. Fix lint error and unexpected chars.

* Add allow-siblings option to no-relative-imports rule (fixes #493)

* Check parent reference only at the import start
@JoshuaKGoldberg JoshuaKGoldberg added this to the 6.0.0-beta0 milestone Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Rule Feature Adding a feature to an existing rule.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants