Skip to content

Comments array order is incorrect when parsing multiple script blocks #264

Closed
@waynzh

Description

@waynzh

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I'm using eslint-plugin-vue.
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-vue repo and open the issue in eslint-plugin-vue repo if there is no solution.
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.57.0, 9.29.0

What version of eslint-plugin-vue and vue-eslint-parser are you using?

  • vue-eslint-parser@0.0.0
  • eslint-plugin-vue@9.33.0, @10.2.0

What did you do?

<script lang="ts" setup>
const test = () => {
  // This comment goes second
  console.log('hello')
}
</script>

<script lang="ts">
/**
 * This comment goes first.
 */
export default {}
</script>

<template>
  <div @click="test" />
</template>
Image

What did you expect to happen?

The comments array should be ordered according to their position in the original source code.

Otherwise, this could impact the functionality of certain rules, such as @eslint-stylistic/padded-blocks. For example, when using sourceCode.getTokenAfter(node, { includeComments: true }), the incorrect comment order could lead to inaccurate results. See vuejs/eslint-plugin-vue#2764.

What actually happened?

Image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-cgjurzim?file=FailComponent.vue,eslint.config.js,PassComponent.vue

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions