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

Add case sensitivity to 'import-name' rule #830

Closed
djomaa opened this issue Feb 21, 2019 · 3 comments · Fixed by #829
Closed

Add case sensitivity to 'import-name' rule #830

djomaa opened this issue Feb 21, 2019 · 3 comments · Fixed by #829
Labels
Status: In Discussion Please continue discussing the proposed change before sending a pull request. Type: Rule Feature Adding a feature to an existing rule.
Milestone

Comments

@djomaa
Copy link
Contributor

djomaa commented Feb 21, 2019

Rule improvement suggestion

This rule improvement is specific for my development style, but it would not affect general style.

Why

Let's say, there is a rule for file naming using dots.case and a rule to use export default only for constructors. So importing variable should be named in PascalCase. Current import-name rule would not allow this.

Suggestion

I suggest adding an option to set the preferred string case with camelCase by default.

Use case

// ./src/master.class.ts
export default class Master {}
// ./src/another.file.ts
import Master from './master.class';
class Slave extends Master {} 
@JoshuaKGoldberg JoshuaKGoldberg added Type: Rule Feature Adding a feature to an existing rule. Status: In Discussion Please continue discussing the proposed change before sending a pull request. labels Feb 23, 2019
@JoshuaKGoldberg
Copy link

Hi @djomaa! I'm a little confused about what the exact difference is you're proposing. Can you elaborate on the different situations for import names you're thinking of, and for each of them, what the behavior of the rule is now compared to what you'd like it to be?

@IllusionMH
Copy link
Contributor

As I see - this change is aimed to adopt this rule for applications that extensively use default imports of classes (and namespace objects?) which aren't allowed ATM. And I agree with this proposal.

How about cases when app (pretty big) has both default exports of classes and factories/helpers?
@djomaa @JoshuaKGoldberg do you think it makes sense to allow third option any (or other name) - less restrictive setting that will check for both of proposed cases?

@djomaa
Copy link
Contributor Author

djomaa commented Feb 27, 2019

@JoshuaKGoldberg Current rule implementation converts each file name to camelCase, and then compares it with the variable name. Thus, there is no way to name variables using PascalCase without changing a file name.

Some examples can be seen in the pull request related to this issue (thx @IllusionMH).
Let me know if you need more examples.

@IllusionMH It can be done. Frankly speaking, that's what I did at the very beginning. But then the changes were discarded due to some problems that have been solved later.

@IllusionMH IllusionMH added this to the 6.2.0-beta milestone May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: In Discussion Please continue discussing the proposed change before sending a pull request. Type: Rule Feature Adding a feature to an existing rule.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants