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

feat(eslint-config-kodefox): module based import order #400

Closed

Conversation

oshimayoan
Copy link
Contributor

@oshimayoan oshimayoan commented Mar 16, 2020

This is kinda my proposal for import order.

Currently, our import order is based on the path parenthesis. So the default order is from builtin then external then internal then parent path then sibling path then index.

I don't think such order is our usual approach as the we did in the past. Thus, I make this proposal to make the import order based on the module type.

So first goes the module then parent/sibling/index as the same level, then custom hooks/helpers as the same level, then type/constant as the same level. In my opinion, that is the most similar approach that we used in the past. Of course, we can tweak the order if there is any suggestion.

Here is what happens when we put a constant file on top of a component file:

image

And here is the error message:

image

Lastly, here is the example repo if you want to try it yourself.
https://github.com/oshimayoan/import-order-example

Comment on lines +61 to +66
groups: [
'module',
['parent', 'sibling', 'index'],
['//use[A-Z].*/', '//helper(s?)/'],
['//constant(s?)/', '/type(s?)/'],
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I agree with the parent, sibling and index being on the same level.

But I'm not sure about the separation based on content being baked into the config directly.

As of right now, there's no convention about where to put the hooks. So usually I would put them in the same directory as helpers.

I'm not 100% sure about forcing projects that use this config to match their folder structures based on our personal preferences.

This might work if we specify what kind of project this config is for or put this behind option flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just nit, but if we're talking about directories, I think the name should always be plural, so the s is not optional, cheers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I wrote this like days ago and forgot to submit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of right now, there's no convention about where to put the hooks. So usually I would put them in the same directory as helpers.

That's why I didn't define any directories for hooks and just define use as everyone usually put it all over the place, could be anywhere.

I'm not 100% sure about forcing projects that use this config to match their folder structures based on our personal preferences.

I see. That is a good point. By their folder structures, do you mean the user outside our company?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That is a good point. By their folder structures, do you mean the user outside our company?

Not necessarily, we have variations in the older projects, some use lib and maybe utils

Those projects probably can't make use the order unless we add more name variation in the helpers group.

Maybe I worry too much, probably those projects won't use this config anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, unless we want add separate config for additional strictness.

Something like extends: kodefox/strict.

Copy link
Member

@darcien darcien Mar 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better if we have a github action that will do fix from the PR.

Just write a comment in the PR, /format and then import order will be magically fixed ✨

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there will be any people using that except me 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just write a comment in the PR, /format and then import order will be magically fixed

This is new to me!

I don't think we need this new plugin, right?

I think so, unless we want add separate config for additional strictness.

Agreed, let's skip the additional strictness for now and if we find a need for it in future we can create a way to turn it on.

Copy link
Member

@darcien darcien Mar 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new to me!

I think this GitHub action doesn't exist yet, we need to make one 😆

EDIT: Someone already made it, we just need to use it
https://github.com/marketplace/actions/pull-request-comment-trigger

'module',
['parent', 'sibling', 'index'],
['//use[A-Z].*/', '//helper(s?)/'],
['//constant(s?)/', '/type(s?)/'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended that you didn't escape the / for types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because sometimes we didn't put types.ts inside types directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also could be there is a chance that someone using something.types.ts or something.type.ts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when a regex is in string form it doesn't have the / on each side (that is a syntax for the regex literal) and thus doesn't need those characters to be escaped since they don't have special meaning. So in this case are the / intended to match actual slashes? In that case why are there double at the beginning? (Maybe this plugin uses a weird form of regex string?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the plugin example, it uses / on each side of the regex string so I follow the pattern.

The reason why there is double / at the beginning is that the second one is intended to match the / from directory path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants