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

Add sort keys and sort imports lint rules, and enable fix+format on save #1209

Merged
merged 4 commits into from
Feb 11, 2022

Conversation

justinhaaheim
Copy link
Contributor

@justinhaaheim justinhaaheim commented Feb 2, 2022

This adds lint rules to sort keys (including in flow type defs). It updates the vscode settings to run lint fixes and then formatting on save, which is the way fb vscode works on www.

I have another branch that actually runs all the fixes, which I kept separate from this for clarity.

EDIT: here's that PR: #1210

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 2, 2022
@vercel
Copy link

vercel bot commented Feb 2, 2022

@justinhaaheim is attempting to deploy a commit to the Facebook Open Source Team on Vercel.

To accomplish this, @justinhaaheim needs to request access to the Team.

Afterwards, an owner of the Team is required to accept their membership request.

If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.

@acywatson
Copy link
Contributor

Open to other opinions here, but I wasn't having a particularly difficult time without this rule. I'm not a fan of the way it reorganized some of the keys in various contexts. For instance, in a hypothetical interface that contains "prev" and "next" keys, I think it makes sense for those two to be next to each other.

I like the change to auto-lint on save, but the sorting I would prefer to hold off on.

@justinhaaheim
Copy link
Contributor Author

@acywatson In my mind the benefit of this rule is that keys are in a predictable order. You always know where they're going to be, everything is consistent, and there's no mental friction about "where do I add this new key..." in an object.

Putting keys in a logical order (prev before next) can be a nice way to do it, but there's nothing to ensure consistency of that approach (20 lines down it could be next before prev). I'm generally in favor of things that reduce the amount of formatting and thinking an engineer has to do, and I propose that this would do both! :)

If there is a case where logical order makes sense, I'd say that's a good candidate for block disabling of this lint rule in that specific case.

@trueadm
Copy link
Collaborator

trueadm commented Feb 2, 2022

I think we should give this a go and see how it works out. I'm not super happy about the current situation of some modules, where type imports are randomly scattered through the imports in the heading, so it might not be too much of an issue. Are the others up for trying it out?

@vercel
Copy link

vercel bot commented Feb 4, 2022

An owner of the Facebook Open Source Team on Vercel accepted @justinhaaheim's request to join.

@justinhaaheim's commit is now being deployed.

@vercel
Copy link

vercel bot commented Feb 4, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/fbopensource/lexical/AVrPAoSnkSzwWYPVSCFYLR49b1hG
✅ Preview: https://lexical-git-add-sort-keys-lint-rule-fbopensource.vercel.app

@acywatson
Copy link
Contributor

@zurfyx do you have feelings about this, either way?

I'm not super happy about the current situation of some modules, where type imports are randomly scattered through the imports in the heading, so it might not be too much of an issue.

Does this affect import order? I thought it was just keys in objects and interfaces.

@justinhaaheim
Copy link
Contributor Author

Does this affect import order? I thought it was just keys in objects and interfaces.

I'll add the sort imports lint rule too. This PR enables the auto fixing of that on save.

@justinhaaheim justinhaaheim force-pushed the add-sort-keys-lint-rule branch from 426f8d8 to 76207fb Compare February 8, 2022 23:07
@justinhaaheim justinhaaheim changed the title Add sort keys lint rule Add sort keys and sort imports lint rules, and enable fix+format on save Feb 8, 2022
@justinhaaheim
Copy link
Contributor Author

Sort imports is now added in as well. I'll rebase tonight, run eslint & prettier on the whole repo and then merge.

@justinhaaheim justinhaaheim force-pushed the add-sort-keys-lint-rule branch from ff2c7ae to 2568270 Compare February 11, 2022 01:41
@justinhaaheim justinhaaheim merged commit a876f7d into main Feb 11, 2022
@trueadm trueadm deleted the add-sort-keys-lint-rule branch April 6, 2022 15:22
acywatson pushed a commit that referenced this pull request Apr 9, 2022
…ave (#1209)

* Add sort keys rule and update configs so it works

Bump version of flowtype eslint plugin to fix bugs with autofixing

* Add sort imports fixable lint rule

* Run lint fix and prettier on whole repo 

* Fix unit tests broken by key sorting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants