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

Misnamed import when trying to import a default class #387

Closed
5angel opened this issue Aug 22, 2017 · 5 comments
Closed

Misnamed import when trying to import a default class #387

5angel opened this issue Aug 22, 2017 · 5 comments
Labels
Status: Needs Investigation We're not sure whether this a good thing to do. Type: Bug
Milestone

Comments

@5angel
Copy link

5angel commented Aug 22, 2017

It expects default imports to start with a lower case letter, but that in turn contradicts the common rule of writing classes with a first upper case letter.

@thisisjoshhansen
Copy link

thisisjoshhansen commented Mar 29, 2018

It seems to follow the filename of the import.

When I renamed foo-bar.ts to FooBar.ts tslint allowed the following:
import FooBar from './FooBar'

Though, I would have preferred it to follow the given classname, not the filename.

@5angel
Copy link
Author

5angel commented Apr 4, 2018

@iamjoshhansen your example is actually ok, it's expected to name your files as your classes.

What I forgot to mention is that this rule also applies to packages as well.

Say, you're importing a lib named foo-bar, but it is actually a FooBar class.
So you'll want something like import FooBar from 'foo-bar'.
That will trigger an error in tslint.

@JoshuaKGoldberg
Copy link

JoshuaKGoldberg commented Jul 6, 2018

It seems to follow the filename of the import.
filename

Yes, this is a problem. Rules shouldn't work differently depending on whether the OS is case sensitive or case insensitive for file names. We should ignore name casing.

That section is a duplicate of #430.

On the other hand, the idea of allowing import FooBar from 'foo-bar' is a good point. See #451 for tracking that.

@massimonewsuk
Copy link

I like what @5angel suggested about allowing you to start imports with a capital letter (import FooBar as opposed to import fooBar), however I can also see a small downside around developer experience. For example typescript auto-suggests imports based on file names. So if you type let x = new fooBar then typescript will suggest importing fooBar from ./foo-bar, but it won't suggest it if you had written new FooBar. So I guess the linting is currently aligned closely with how the TypeScript compiler expects people to reference these default exports, which is a good thing because it means a more consistent developer experience. However I do agree in that it's extremely odd to import a class with a lowercase letter to satisfy a linting rule.

@JoshuaKGoldberg Maybe we should ask the TypeScript guys to suggest the import to start with an uppercase letter if the default export was a class?

@villelahdenvuo
Copy link

@JoshuaKGoldberg This is actually not a duplicate of #430 and not fixed by #451. If I have a default export export default class User {...} and try to import it: import User from './models/user'; tslint complains. Misnamed import. Import should be named 'user' but found 'User' (import-name) unless I rename the file to User.ts. So like in export-name in #430 there should be ignore-case option for the import-name rule.

@JoshuaKGoldberg JoshuaKGoldberg added Status: Needs Investigation We're not sure whether this a good thing to do. Type: Bug and removed Resolution: Duplicate labels Apr 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: Needs Investigation We're not sure whether this a good thing to do. Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants