benawad / destiny

Prettier for File Structures
MIT License
3.53k stars 80 forks source link

Suggestion: Avoid duplication as file+folder #106

Closed paramaggarwal closed 4 years ago

paramaggarwal commented 4 years ago

Currently we do this:

App/dep.js
App.js

This is confusing to me because if I import ./App - it seems controversial to have a folder and a file of the same name in the same directory...

I recommend that we do this instead:

App/dep.js
App/index.js
AnatoleLucet commented 4 years ago

So the following

src
├── index
│   ├── header
│   │   └── nav.js
│   ├── footer
│   │   ├── helper.js
│   │   └── button.js
│   ├── shared
│   │   └── helper.js
│   ├── header.js
│   └── footer.js
└── index.js

Would be transformed to

src
├── header
│   ├── index.js
│   └── nav.js
├── footer
│   ├── index.js
│   ├── helper.js
│   └── button.js
├── shared
│   └── helper.js
└── index.js

I personally find it harder to read the file tree, but maybe it's just me.

Also it wouldn't describe that well who is using the file(s) in the shared folder. In the above example of you suggestion we're not able to tell if helper.js is used by src/index.js and someone in header / footer, or if he's only used by someone in header and footer. Which we can easily tell with current way that Destiny choose to move files.

I don't think this would improve the readability / understanding and even surely regress it.

paramaggarwal commented 4 years ago

In the suggested approach:

Hence, if you drop the concept of file and folder and instead think of it as a single component, then you can see that shared is used by header and footer. Plus, everything related to header resides in one single place, rather than one file separate and all the other related things inside a sibling folder.

AnatoleLucet commented 4 years ago

Well ok, I haven't seen it that way. Why not.

cc @benawad, @sQVe any thought?

benawad commented 4 years ago

We need to start thinking about how we want to customization api to work for cases like this

paramaggarwal commented 4 years ago

I am actually in the convention over configurability camp. Hence, if we choose to go ahead with the current approach I'll use that instead.

It's just that I tried it out on my projects and found it little awkward to have a file and a folder of the same name.

I just realised that one benefit of having the component name in the file instead of having component/index.js is that it is easier to open files because they have the relevant name.

Because this project uses an established pattern called the Fractal pattern and because I am in favour or convention over configuration - same principles as Prettier! - I'm closing this suggestion.