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

Cannot sort <script setup> if multiple <script> are provided in vue sfc #218

Open
1 task done
Tanimodori opened this issue Mar 9, 2023 · 3 comments · Fixed by IanVS/prettier-plugin-sort-imports#90 · May be fixed by #219
Open
1 task done

Cannot sort <script setup> if multiple <script> are provided in vue sfc #218

Tanimodori opened this issue Mar 9, 2023 · 3 comments · Fixed by IanVS/prettier-plugin-sort-imports#90 · May be fixed by #219

Comments

@Tanimodori
Copy link

Tanimodori commented Mar 9, 2023

Your Environment

  • prettier-plugin-sort-imports: 4.1.1
  • Prettier version: 2.8.4
  • node version: 16.19.0
  • package manager: [email protected]
  • IDE: VScode
  • prettier-plugin-sort-imports: 4.1.1
  • OS: Windows 11

Describe the bug

If multiple <script> blocks are provided in vue sfc, the <script setup> block will be ignored where imports inside are not sorted while other prettier functions still work.

It is common that both <script> and <script setup> are required in the same sfc (e.g. you need to use defineComponent to define the name of the component, or exports something from sfc).

To Reproduce

  1. git clone https://github.com/Tanimodori/prettier-import-vue-repro.git
  2. cd prettier-import-vue-repro
  3. pnpm i
  4. pnpm format
  5. inspect diff of src/App.vue. The imports in <script setup> are not sorted.

Expected behavior

The imports in <script setup> should also be sorted.

Screenshots, code sample, etc

PHli37YJhC

<script lang="ts">
import { dummy } from './dummy'
import { ref } from 'vue'

export const foo = ref(dummy)
</script>

<script setup lang="ts">
import HelloWorld from './components/HelloWorld.vue'
import TheWelcome from './components/TheWelcome.vue'
import { computed } from 'vue'

const bar = computed(() => foo.value)
</script>

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

Error log

N/A

Contribute to @trivago/prettier-plugin-sort-imports

  • I'm willing to fix this bug 🥇
@Tanimodori
Copy link
Author

const content = (descriptor.script ?? descriptor.scriptSetup)?.content;

I suppose this is causing the problem.

@seanogdev
Copy link

FWiW, in Vue 3.3+ we now have defineOptions() which can now define these global properies on the components

@Caffeine19
Copy link

Caffeine19 commented Sep 11, 2024

FWiW, in Vue 3.3+ we now have defineOptions() which can now define these global properies on the components

<script lang="ts">
/** 页脚 */
export default {};
</script>
<script setup lang="ts"></script>

But I need to add a description for the components. The defineOptions didn't help with this

adamDilger added a commit to adamDilger/prettier-plugin-sort-imports that referenced this issue Dec 2, 2024
byara pushed a commit that referenced this issue Dec 2, 2024
* (#276) Fixed dollar sign group replace in vue preprocessor

* (#218) format both script and script setup tags if they exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants