-
-
Notifications
You must be signed in to change notification settings - Fork 32
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: prevent removing imports if a rangeEnd is passed #112
fix: prevent removing imports if a rangeEnd is passed #112
Conversation
It might also make sense to check for |
From what I could tell, |
Just testing this and the following happens: Prettier initially calls the plugin's preprocess with (omitting non-relevant fields): {
code: '<original-code>',
options: {
rangeEnd: 10, // or whatever was set
originalText: undefined,
}
} Prettier calling the plugin at that point seems a bit weird but I guess maybe it's just because we're hooking into the Then it calls the plugin's preprocess a second time with {
code: '<just-the-code-in-the-range>',
options: {
rangeEnd: Infinity, // default value
originalText: '<original-code>',
}
} I think the most correct (and performant) behavior is to
wdyt? |
An alternative would be to pass |
@simonhaenisch Sorry for not getting back to you. That works for me, thanks for sorting the PR! |
….2.4 (#211) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [prettier-plugin-organize-imports](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports) | [`3.2.3` -> `3.2.4`](https://renovatebot.com/diffs/npm/prettier-plugin-organize-imports/3.2.3/3.2.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/prettier-plugin-organize-imports/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/prettier-plugin-organize-imports/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/prettier-plugin-organize-imports/3.2.3/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/prettier-plugin-organize-imports/3.2.3/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>simonhaenisch/prettier-plugin-organize-imports (prettier-plugin-organize-imports)</summary> ### [`v3.2.4`](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/releases/tag/v3.2.4): 3.2.4 [Compare Source](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/compare/v3.2.3...v3.2.4) #### What's Changed - fix: skip when formatting ranges — by [@​MattLish](https://togithub.com/MattLish) in [https://github.com/simonhaenisch/prettier-plugin-organize-imports/pull/112](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/pull/112) #### New Contributors - [@​MattLish](https://togithub.com/MattLish) made their first contribution in [https://github.com/simonhaenisch/prettier-plugin-organize-imports/pull/112](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/pull/112) **Full Changelog**: simonhaenisch/prettier-plugin-organize-imports@v3.2.3...v3.2.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/json-derulo/angular-ecmascript-intl). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
….2.4 (#38) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [prettier-plugin-organize-imports](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports) | [`3.2.3` -> `3.2.4`](https://renovatebot.com/diffs/npm/prettier-plugin-organize-imports/3.2.3/3.2.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/prettier-plugin-organize-imports/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/prettier-plugin-organize-imports/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/prettier-plugin-organize-imports/3.2.3/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/prettier-plugin-organize-imports/3.2.3/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>simonhaenisch/prettier-plugin-organize-imports (prettier-plugin-organize-imports)</summary> ### [`v3.2.4`](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/releases/tag/v3.2.4): 3.2.4 [Compare Source](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/compare/v3.2.3...v3.2.4) #### What's Changed - fix: skip when formatting ranges — by [@​MattLish](https://togithub.com/MattLish) in [https://github.com/simonhaenisch/prettier-plugin-organize-imports/pull/112](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/pull/112) #### New Contributors - [@​MattLish](https://togithub.com/MattLish) made their first contribution in [https://github.com/simonhaenisch/prettier-plugin-organize-imports/pull/112](https://togithub.com/simonhaenisch/prettier-plugin-organize-imports/pull/112) **Full Changelog**: simonhaenisch/prettier-plugin-organize-imports@v3.2.3...v3.2.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/simonknittel/sinister-incorporated). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMDMuMSIsInVwZGF0ZWRJblZlciI6IjM3LjEwMy4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCJ9-->
This prevents destructive operations when a
rangeEnd
is passed.Prior to this, if
rangeEnd
was passed, the imports would be removed because the plugin considered them unused.This should solve a bug experienced in JetBrains IDEs https://youtrack.jetbrains.com/issue/WEB-50178/Code-reformat-with-prettier-and-prettier-plugin-organize-imports-deletes-imports-if-Optimize-imports-is-enabled
Closes #110