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

[HOLD] Destructure props of all function components by adding an ESLint rule running the linter with --fix #22671

Closed
hayata-suenaga opened this issue Jul 11, 2023 · 13 comments
Assignees
Labels
Engineering Improvement Item broken or needs improvement. Weekly KSv2

Comments

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Jul 11, 2023

HOLD on #20179

Per this discussion on changing the guideline to always requiring prop destructuring to assign default values to optional props.

Add the following config

'react/destructuring-assignment': ['error', 'always', {ignoreClassFields: true, destructureInSignature: 'always'}],

and run --fix

@hayata-suenaga hayata-suenaga added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 11, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 11, 2023

Triggered auto assignment to @trjExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Jul 11, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@hayata-suenaga hayata-suenaga removed the Bug Something is broken. Auto assigns a BugZero manager. label Jul 11, 2023
@hayata-suenaga hayata-suenaga added Weekly KSv2 Improvement Item broken or needs improvement. Engineering and removed Daily KSv2 labels Jul 11, 2023
@blazejkustra
Copy link
Contributor

@hayata-suenaga Why not add the rule now in TS setup PR? If we put it in rules for TS files, we wouldn't have to run eslint --fix at all. When migrating components to TS we could remove defaultProps and use prop destructuring.

@hayata-suenaga
Copy link
Contributor Author

I was thinking doing that but @roryabraham suggested we ran --fix before starting the migration

and if we gonna do that, we should probably do that in a separate PR

@roryabraham
Copy link
Contributor

I don't feel strongly either way, but figured since the rule supports --fix we can get it out of the way now and reduce the diff of TS migration PRs.

@blazejkustra
Copy link
Contributor

blazejkustra commented Jul 13, 2023

I was worried how defaultProps works out with destructuring props, found out it works just fine:codepen. I'm good with automatic eslint --fix in a separate PR 👌

@hayata-suenaga
Copy link
Contributor Author

Will do this before the migration will start

@hayata-suenaga
Copy link
Contributor Author

will put PR up tomorrow

@melvin-bot melvin-bot bot removed the Overdue label Jul 24, 2023
@hayata-suenaga hayata-suenaga changed the title Destructure Props: Add new ESLint rule and fix all functional components Destructure props of all function components by adding an ESLint rule running the linter with --fix Jul 27, 2023
@hayata-suenaga
Copy link
Contributor Author

This is on hold for #20179 which will turn off an ESLint setting that conflicts with de-structured props

@roryabraham roryabraham changed the title Destructure props of all function components by adding an ESLint rule running the linter with --fix [HOLD] Destructure props of all function components by adding an ESLint rule running the linter with --fix Jul 28, 2023
@melvin-bot melvin-bot bot added the Overdue label Aug 7, 2023
@hayata-suenaga
Copy link
Contributor Author

now that #20179 has been merged, I'll work on this today

@melvin-bot melvin-bot bot removed the Overdue label Aug 7, 2023
@hayata-suenaga
Copy link
Contributor Author

Turned out that ESLint cannot fix all de-structuring rule violations automatically.

These are only files where ESLint was able to fix code automatically.

Screenshot 2023-08-07 at 9 02 52 AM

I also tried to run ESLint with the latest version (the current version specified in package.json is 7.32.0 but the latest is 8.46.0.

Current version confirmation

hayatasuenaga@Hayatas-Work-MBP App % npm list eslint --depth=0
new.expensify@1.3.50-3 /Users/hayatasuenaga/Expensidev/App
└── eslint@7.32.0

Running the latest ESLint. Still doesn't fix issues automatically
Screenshot 2023-08-07 at 9 01 03 AM

@roryabraham what do you think? should we let migration PR also handle prop de-structuring? (we can specify the rule only for ts and tsx rules so that when engineers migrate a file to a TS file, they gonna be notified about de-structuring rule violation if they didn't de-structure

@hayata-suenaga
Copy link
Contributor Author

updated Rory about the limit of --fix option here in slack

@hayata-suenaga
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering Improvement Item broken or needs improvement. Weekly KSv2
Projects
None yet
Development

No branches or pull requests

4 participants