Skip to content

add rule jsx-sort-props to order props alphabetically, optionally by type #97

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

Closed
wants to merge 2 commits into from

Conversation

SteveByerly
Copy link

Addresses #8

Also see similar update in tslint:
palantir/tslint#2831

CHANGELOG.md entry:

[new-rule] jsx-sort-props: Sort props alphabetically and optionally by type (spread, shorthand, longhand)

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

Similar comments as I wrote in palantir/tslint#2831 (comment)...

I don't want to start introducing conflicting rules here without a good reason, so would prefer to avoid adding "shorthand" and "longhand" options.

As for "spread", there's no way to statically know the members of an object being spread, so I don't think we can safely suggest the correct sorting position of a spread. Let's just keep this rule simple and do alphabetic sorting.

I'll take another look when this PR has been slimmed down.

type ORDER_OPTION = "spread" | "shorthand" | "longhand";

enum KEY_ORDER {
OPTION_ORDER_SPREAD,
Copy link
Contributor

Choose a reason for hiding this comment

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

consistent 4-space indentation please

Possible settings are:

* \`"${OPTION_ORDER_SPREAD}"\`: Spread assignments \`{...props}\`.
* \`"${OPTION_ORDER_SHORTHAND}"\`: Shorthand properties \`{ isError, isValid }\`.
Copy link
Contributor

Choose a reason for hiding this comment

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

shorthand conflicts with jsx-boolean-value: true, which we enable by default... https://github.com/palantir/tslint-react/blob/master/tslint-react.json#L5

@SteveByerly
Copy link
Author

Will address based on the outcome of my reply.

Spread would no longer be a part of this change, and other than adding alpha-sorting, it would simply allow for ensuring shorthand come first and we can alpha-sort within those groupings.

@SteveByerly
Copy link
Author

Updated based on the same approach I took here: palantir/tslint#2831 (comment)

@david0178418
Copy link

Looking forward to this feature. @adidahiya , did the modifications made by @SteveByerly address your concerns?

@rootulp
Copy link

rootulp commented Sep 10, 2018

ping @palantir/tslint

@johnwiseheart
Copy link

Not sure what the issue is with the builds here, but I'd guess @SteveByerly may need to push once more to have the tests run (and hopefully pass). If they pass, I'd be happy to merge this in.

@Mukhametvaleev
Copy link

Hey @adidahiya! As I can see, the requested changes already implemented. Could you please review the PR?

@bradleyayers
Copy link

Any updates on this one @johnwiseheart ?

@jdolinski1
Copy link

Will it be possible to automatically fix unsorted props with tslint --fix?

@bradleyayers
Copy link

That would be fantastic!

@adidahiya
Copy link
Contributor

closing as stale, sorry it took so long to review @SteveByerly. let us know if it's ok for someone to take take your code and make a new PR.

@adidahiya adidahiya closed this Mar 12, 2019
@daviddelusenet
Copy link

Will this ever be picked up again?

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

Successfully merging this pull request may close these issues.

9 participants