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

An alphabetical order rule? #1406

Closed
fa93hws opened this issue Jul 6, 2019 · 7 comments · Fixed by #1105 or #1360
Closed

An alphabetical order rule? #1406

fa93hws opened this issue Jul 6, 2019 · 7 comments · Fixed by #1105 or #1360

Comments

@fa93hws
Copy link
Contributor

fa93hws commented Jul 6, 2019

Hi!
I found that the alphabetical order import rule is very useful.
Do you mind I add a new rule for that?
Or an option to existed order rule?

@ljharb
Copy link
Member

ljharb commented Jul 6, 2019

Why is it useful? What rule are you referring to?

Either way it’d be an option to the existing rule, not a new one.

@fa93hws
Copy link
Contributor Author

fa93hws commented Jul 6, 2019

Hi, we are a typescript team and are migrating to eslint from the tslint.
While the import order rule is quite different between that in eslint and the tslint.
I think it might be useful for other team who migrated from tslint as well.

Thanks, I will make such a rule when I have time.

@ljharb
Copy link
Member

ljharb commented Jul 6, 2019

Closing as a duplicate of #1311.

@ljharb ljharb closed this as completed Jul 6, 2019
@gustavopch
Copy link

Closing as a duplicate of #1311.

How is this is a duplicate of #1311? Alphabetical order is only mentioned there, but it's not the point of the issue.

@ljharb ljharb reopened this Oct 5, 2019
@sveyret
Copy link
Contributor

sveyret commented Nov 12, 2019

I also like very much the alphabetical order of the tslint rule, because when there are lot of imports in a file, it is far easier to find if one needs to be added or not. Probably should it be an option of the already existing order rule. What would be great also, to conform to tslint rule, would be to be able to sort imported members from a library by alphabetical order, and to have the ability to put lowercase starting members at the end. See https://palantir.github.io/tslint/rules/ordered-imports/

Would you accept PR for that?

@caribou-code
Copy link

This would be a useful addition to the package. For example in a React project we can already sort props, propTypes, defaultProps and more alphabetically with rules such as react/jsx-sort-default-props, react/jsx-sort-props and react/sort-prop-types.

For unordered lists of code such as imports, exports and objects, it makes sense to group and sort these so there's some consistent order throughout a project. import/order already handles the grouping, but being able to sort alphabetically within those groups would be beneficial.

@ljharb
Copy link
Member

ljharb commented Nov 26, 2019

One challenge is that bindingless imports (import 'path' versus import x from 'path') are by convention side-effecting, so nothing should be reordered across them, and they should not be reordered themselves.

However, yes, after some thought I think it does make sense to add this as an option to the order rule. A PR would be appreciated.

marcusdarmstrong pushed a commit to marcusdarmstrong/eslint-plugin-import that referenced this issue Dec 9, 2019
…n groups

Fixes import-js#1406. Fixes import-js#389. Closes import-js#629. Closes import-js#1105. Closes import-js#1360.

Co-Authored-By: dannysindra <als478@cornell.edu>
Co-Authored-By: Radim Svoboda <radim.svoboda@socialbakers.com>
Co-Authored-By: Soma Lucz <luczsoma@gmail.com>
Co-Authored-By: Randall Reed, Jr <randallreedjr@gmail.com>
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants