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

Vue: Sort both script and setup script #90

Merged
merged 3 commits into from May 17, 2023
Merged

Vue: Sort both script and setup script #90

merged 3 commits into from May 17, 2023

Conversation

IanVS
Copy link
Owner

@IanVS IanVS commented May 17, 2023

@IanVS IanVS requested a review from fbartho May 17, 2023 13:40
@IanVS
Copy link
Owner Author

IanVS commented May 17, 2023

Note this also fixes the reproduction in trivago/prettier-plugin-sort-imports#199, since we're not processing the entire contents of the file anymore (I don't think imports can happen outside of a script or setup script block). But I think there's some more we can do to address that issue as well, in a separate PR.

Copy link
Collaborator

@fbartho fbartho left a comment

Choose a reason for hiding this comment

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

I don’t use vue but looks reasonable!

@IanVS IanVS merged commit 22ccb2f into next May 17, 2023
6 checks passed
@IanVS IanVS deleted the vue/script-and-setup branch May 17, 2023 15:46
kodiakhq bot pushed a commit to timelessco/browser-js-library-template that referenced this pull request May 26, 2023
…#156)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`^3.7.2` -> `^4.0.0`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.0) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

#### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 12am and before 5am every weekday,every weekend" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/browser-js-library-template).
kodiakhq bot pushed a commit to timelessco/browser-js-website-template that referenced this pull request May 26, 2023
…#109)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`^3.7.2` -> `^4.0.0`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.0) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

#### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 12am and before 5am every weekday,every weekend" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/browser-js-website-template).
kodiakhq bot pushed a commit to timelessco/js-bottomsheet that referenced this pull request May 26, 2023
…#122)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`^3.7.2` -> `^4.0.0`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.0) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

#### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 12am and before 5am every weekday,every weekend" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/js-bottomsheet).
kodiakhq bot pushed a commit to timelessco/node-ts-library-template that referenced this pull request May 26, 2023
…#79)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`3.7.2` -> `4.0.0`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.0) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.0/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

#### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 12am and before 5am on saturday" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/node-ts-library-template).
kodiakhq bot pushed a commit to timelessco/node-js-library-template that referenced this pull request Jun 2, 2023
…#71)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`3.7.2` -> `4.0.2`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.2) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.2`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.2)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v4.0.1...v4.0.2)

#### What's Changed

-   Account for missing filepath by [@&#8203;IanVS](https://togithub.com/IanVS) in [IanVS/prettier-plugin-sort-imports#104

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v4.0.1...v4.0.2

### [`v4.0.1`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.1)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v4.0.0...v4.0.1)

#### What's Changed

-   Fix cli in Install section by [@&#8203;torn4dom4n](https://togithub.com/torn4dom4n) in [IanVS/prettier-plugin-sort-imports#99
-   Fix dollar sign ($) issue in Vue SFC by [@&#8203;istiak-tridip](https://togithub.com/istiak-tridip) in [IanVS/prettier-plugin-sort-imports#101

#### New Contributors

-   [@&#8203;torn4dom4n](https://togithub.com/torn4dom4n) made their first contribution in [IanVS/prettier-plugin-sort-imports#99
-   [@&#8203;istiak-tridip](https://togithub.com/istiak-tridip) made their first contribution in [IanVS/prettier-plugin-sort-imports#101

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v4.0.0...v4.0.1

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

#### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 12am and before 5am on saturday" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/node-js-library-template).
kodiakhq bot pushed a commit to timelessco/recollect that referenced this pull request Jun 4, 2023
…#36)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`3.7.2` -> `4.0.2`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.2) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.2`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.2)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v4.0.1...v4.0.2)

#### What's Changed

-   Account for missing filepath by [@&#8203;IanVS](https://togithub.com/IanVS) in [IanVS/prettier-plugin-sort-imports#104

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v4.0.1...v4.0.2

### [`v4.0.1`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.1)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v4.0.0...v4.0.1)

#### What's Changed

-   Fix cli in Install section by [@&#8203;torn4dom4n](https://togithub.com/torn4dom4n) in [IanVS/prettier-plugin-sort-imports#99
-   Fix dollar sign ($) issue in Vue SFC by [@&#8203;istiak-tridip](https://togithub.com/istiak-tridip) in [IanVS/prettier-plugin-sort-imports#101

#### New Contributors

-   [@&#8203;torn4dom4n](https://togithub.com/torn4dom4n) made their first contribution in [IanVS/prettier-plugin-sort-imports#99
-   [@&#8203;istiak-tridip](https://togithub.com/istiak-tridip) made their first contribution in [IanVS/prettier-plugin-sort-imports#101

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v4.0.0...v4.0.1

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

##### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/bookmark-tags).
kodiakhq bot pushed a commit to timelessco/next-ts-app that referenced this pull request Jun 11, 2023
…#161)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@ianvs/prettier-plugin-sort-imports](https://togithub.com/ianvs/prettier-plugin-sort-imports) | [`3.7.2` -> `4.0.2`](https://renovatebot.com/diffs/npm/@ianvs%2fprettier-plugin-sort-imports/3.7.2/4.0.2) | [![age](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/compatibility-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@ianvs%2fprettier-plugin-sort-imports/4.0.2/confidence-slim/3.7.2)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>ianvs/prettier-plugin-sort-imports</summary>

### [`v4.0.2`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.2)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v4.0.1...v4.0.2)

#### What's Changed

-   Account for missing filepath by [@&#8203;IanVS](https://togithub.com/IanVS) in [IanVS/prettier-plugin-sort-imports#104

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v4.0.1...v4.0.2

### [`v4.0.1`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.1)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v4.0.0...v4.0.1)

#### What's Changed

-   Fix cli in Install section by [@&#8203;torn4dom4n](https://togithub.com/torn4dom4n) in [IanVS/prettier-plugin-sort-imports#99
-   Fix dollar sign ($) issue in Vue SFC by [@&#8203;istiak-tridip](https://togithub.com/istiak-tridip) in [IanVS/prettier-plugin-sort-imports#101

#### New Contributors

-   [@&#8203;torn4dom4n](https://togithub.com/torn4dom4n) made their first contribution in [IanVS/prettier-plugin-sort-imports#99
-   [@&#8203;istiak-tridip](https://togithub.com/istiak-tridip) made their first contribution in [IanVS/prettier-plugin-sort-imports#101

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v4.0.0...v4.0.1

### [`v4.0.0`](https://togithub.com/IanVS/prettier-plugin-sort-imports/releases/tag/v4.0.0)

[Compare Source](https://togithub.com/ianvs/prettier-plugin-sort-imports/compare/v3.7.2...v4.0.0)

#### What's Changed

This new release focuses on simplifying the plugin options, shipping more useful defaults, handling comments around import statements more reliably, and improving Vue and TypeScript compatibility.  We also are targeting Node 16 syntax with our build, though older versions may continue to work (untested).  See the full [migration guide](https://togithub.com/IanVS/prettier-plugin-sort-imports/blob/next/docs/MIGRATION.md#migrating-from-v3xx-to-v4xx) for details of the breaking changes.

##### ⬆️ Breaking Changes

-   Build for Node 16+ ([IanVS/prettier-plugin-sort-imports#59)
-   Remove `importOrderBuiltinModulesToTop` (always true) ([IanVS/prettier-plugin-sort-imports#60)
-   Remove `importOrderSeparation` option ([IanVS/prettier-plugin-sort-imports#62)
-   Remove `importOrderCaseInsensitive` option ([IanVS/prettier-plugin-sort-imports#63)
-   Remove `importOrderGroupNamespaceSpecifiers` option ([IanVS/prettier-plugin-sort-imports#64)
-   Remove `importOrderSortSpecifiers` option ([IanVS/prettier-plugin-sort-imports#65)
-   Remove `importOrderMergeDuplicateImports` option (always on) ([IanVS/prettier-plugin-sort-imports#66)
-   Replace `importOrderCombineTypeAndValueImports` with `importOrderTypeScriptVersion` ([IanVS/prettier-plugin-sort-imports#67)
-   Improve default sort order ([IanVS/prettier-plugin-sort-imports#83)

##### 🐛 Bug Fixes

-   Fix behavior around comments embedded in imports ([IanVS/prettier-plugin-sort-imports#71)
-   Preserve trailing comments on specifiers ([IanVS/prettier-plugin-sort-imports#80)
-   Preserve comments and blank lines at top-of-file (in [IanVS/prettier-plugin-sort-imports#82)
-   Prevent comment gap when re-arranging first import ([IanVS/prettier-plugin-sort-imports#85)
-   Fix: Top-of-file Comments get duplicated when moving runtime code ([IanVS/prettier-plugin-sort-imports#88)
-   Vue: Sort both script and setup script ([IanVS/prettier-plugin-sort-imports#90)
-   Vue and TypeScript: Use correct parser plugins ([IanVS/prettier-plugin-sort-imports#91)

##### ⚡️ Features

-   Add `<BUILTIN_MODULES>` Special Word ([IanVS/prettier-plugin-sort-imports#86)
-   Allow Explicit Separator after Top-of-file-comments ([IanVS/prettier-plugin-sort-imports#92)
-   Support babel-ts parser ([IanVS/prettier-plugin-sort-imports#97)

##### 🛠️ Repo Maintenance

-   Update dependencies, jest -> vitest ([IanVS/prettier-plugin-sort-imports#59)
-   Check formatting in CI ([IanVS/prettier-plugin-sort-imports#61)
-   Update to latest versions of Github Actions ([IanVS/prettier-plugin-sort-imports#73)
-   Add some more tests for comments ([IanVS/prettier-plugin-sort-imports#77)

##### 🧳 Dependencies

-   Drop javascript-natural-sort dependency ([IanVS/prettier-plugin-sort-imports#28)
-   Drop lodash.clone dependency ([IanVS/prettier-plugin-sort-imports#74)
-   Upgrade Babel to 7.21 ([IanVS/prettier-plugin-sort-imports#72)

**Full Changelog**: IanVS/prettier-plugin-sort-imports@v3.7.2...v4.0.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone Asia/Kolkata, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] 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://app.renovatebot.com/dashboard#github/timelessco/next-ts-app).
@Tanimodori
Copy link
Contributor

code.replace is not safe to use here.

return code.replace(
content,
() => `\n${preprocessor(content, adjustedOptions)}\n`,
);

The code here is the whole SFC source code. Despite the fact that up to one <script> and one <script setup> block can exist in a single SFC, other 3rd blocks may exist in that SFC (like vue-i18n adds a new <i18n> block). In rare cases String.prototype.replace may replace the wrong place producing tricky issues and it is slower than merging by block offsets in the original fix.

@fbartho
Copy link
Collaborator

fbartho commented Oct 11, 2023

@Tanimodori that sounds like a serious bug! Would you mind filing a PR to at least give us examples, if not fix it?

I’m not a Vue user, so I only sort of understand your situation here. I’m happy to review any PR that fixes this.

@Tanimodori
Copy link
Contributor

@fbartho Surely. Give me some time to implement that.

@Tanimodori
Copy link
Contributor

Tanimodori commented Oct 12, 2023

@fbartho The fix is blocked by #133. I've opened PR #134 to fix that. But it seems to be blocked by #128 and #129 again...

@Tanimodori
Copy link
Contributor

Tanimodori commented Oct 12, 2023

Let me introduce some backgrounds and give the examples.

Vue Single File Component, or SFC, is a file that contains blocks which describes various aspects of a reusable component similar to Web Component. Here's a typical structure of SFC:

<template>
  <div class="my-text">
    Here's the template block that 
    describes how vue render this component
    into HTML DOM
  </div>
</template>

<script setup lang="ts">
  console.log("Here's the script block that");
  console.log("contains the actual code of this component");
</script>

<style lang="less">
// Here is the style block that
// contains the style used in template
.my-text {
  color: red;
}
</style>

You can tell that different blocks use different languages and the order of blocks does not matter. This prettier plugin only cares about <script> and <script setup> which contains JS/TS code so we use parse from @vue/compiler-sfc to split the blocks.

@Tanimodori
Copy link
Contributor

Tanimodori commented Oct 12, 2023

Here is the problematic example:

<template>
  <code>
import z from 'z';
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import { defineComponent } from 'vue'
function add(a,b) {
  return a + b;
}

import z from 'z';
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import { defineComponent } from 'vue'
function add(a,b) {
  return a + b;
}
  </code>
</template>

<script>
import z from 'z';
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import { defineComponent } from 'vue'
function add(a,b) {
  return a + b;
}
</script>

<script setup>
import z from 'z';
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import { defineComponent } from 'vue'
function add(a,b) {
  return a + b;
}
</script>

The <template> block contains the same "code text" in <script> and <script setup> here! Well the "code text" in <template> block only render into HTML DOM which does not serve as actual JS/TS code. When we want to show the actual code in a component to demonstrate a specific use case of it in a component library, this example may actually exist. Note that 3rd plugins may also add their custom blocks into SFC.

So now you can tell the problem. As String.prototype.replace only replace the first occurrence and the order of blocks does not matter (some programmers prefer writing <template> first actually), code.replace will replace the content in <template> rather than <script> and <script setup>! Here's the outcome:

<template>
    <code>
        import thirdParty from "third-party"; import { defineComponent } from
        'vue'; import z from 'z'; import otherthing from "@core/otherthing";
        import threeLevelRelativePath from "../../../threeLevelRelativePath";
        import oneLevelRelativePath from "../oneLevelRelativePath"; import
        sameLevelRelativePath from "./sameLevelRelativePath"; function add(a,b)
        { return a + b; } import thirdParty from "third-party"; import {
        defineComponent } from 'vue'; import z from 'z'; import otherthing from
        "@core/otherthing"; import threeLevelRelativePath from
        "../../../threeLevelRelativePath"; import oneLevelRelativePath from
        "../oneLevelRelativePath"; import sameLevelRelativePath from
        "./sameLevelRelativePath"; function add(a,b) { return a + b; }
    </code>
</template>

<script>
import z from "z";
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import { defineComponent } from "vue";
function add(a, b) {
    return a + b;
}
</script>

<script setup>
import z from "z";
import threeLevelRelativePath from "../../../threeLevelRelativePath";
import sameLevelRelativePath from "./sameLevelRelativePath";
import thirdParty from "third-party";
import oneLevelRelativePath from "../oneLevelRelativePath";
import otherthing from "@core/otherthing";
import { defineComponent } from "vue";
function add(a, b) {
    return a + b;
}
</script>

Although the <code> is compressed a bit due to the HTML Whitespace Sensitivity settings of prettier in this repo's config, you can tell that the wrong place has been replaced.

@Tanimodori
Copy link
Contributor

As the parse tells where a block starts and ends in SFC, the correct and faster way is using that offset to merge blocks like the original fix. The algorithm here is simple here.

  1. Find out the block we want, say that we got one <script> and one <script setup> here. We may have [0,2] blocks actually.
  2. Sort offsets them by the start one, say that we have [b1, e1) and [b2, e2). Blocks may never overlaps.
  3. Format the contents of those blocks, say we got string c1 and c2.
  4. Merge. We use [0, b1) from the original, then c1, then [e1, b2) from the original, then c2 and finally [e2,code.length)

Tanimodori added a commit to Tanimodori/ianvs-prettier-plugin-sort-imports that referenced this pull request Oct 12, 2023
Tanimodori added a commit to Tanimodori/ianvs-prettier-plugin-sort-imports that referenced this pull request Oct 12, 2023
@Tanimodori
Copy link
Contributor

Tanimodori commented Oct 12, 2023

@fbartho I've submitted PR #135 to fix the problem without touching dependencies and shrimpwarp files anyway. Should be able to merge without conflicts.

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.

Cannot sort <script setup> if multiple <script> are provided in vue sfc
3 participants