-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix single-tree-render codemod remove extra new lines only in modified files #19547
Fix single-tree-render codemod remove extra new lines only in modified files #19547
Conversation
Removes extra new lines between import statements only when file is modified. Previously extra empty lines would be removed also from files codemod didn't modify. Empty lines are caused by `insertAfter()`.
@jsnajdr commented (#19555 (review)):
While I totally agree with the sentiment, it might not solve this specific issue with empty lines between imports, see example (after opening the link, you might need to refresh the tab to see it properly). Anyway, this will get us moving forward for now, but a proper fix for the issue is needed in long term. |
@simison I'd like to keep I'm experimenting with printing the codemodded AST with Prettier directly and avoiding the return root.toSource( config.recastOptions ); which calls return prettier.__debug.formatAST( root.get().value, { originalText: file.source } ).formatted; This doesn't solve the extra lines between |
True, that's totally reasonable considering you have to rebase against new versions of Prettier each time. I was thinking this another day: have you seen My thinking is that rather than maintaining a prettier fork, we could maintain eslint plugin that works on top of it?
That's a great idea! I'll give this a try today. |
…attic#19547) Removes extra new lines between import statements only when file is modified. Previously extra empty lines would be removed also from files codemod didn't modify. Empty lines are caused by `insertAfter()`.
Removes extra new lines between two import statements only when file is modified.
Related to PR #19494 "Single tree-rendering-issues"
That
removeExtraNewlines()
turns this:into this:
...since it's something Prettier doesn't do for us.
Previously in this codemod these kind of extra empty lines would be removed also from files this codemod didn't modify. Now they'll be removed only from files where we add that import
makeLayout
/clientRender
.Empty lines are caused by bug in
insertAfter()
: benjamn/recast#371To test
→ Adds new import, but no newlines
→ Doesn't add import and won't fix old empty lines between imports