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

getCommentsBefore empty in Vue SFC with two script tags #2446

Open
2 tasks done
eliottvincent opened this issue Apr 9, 2024 · 1 comment
Open
2 tasks done

getCommentsBefore empty in Vue SFC with two script tags #2446

eliottvincent opened this issue Apr 9, 2024 · 1 comment

Comments

@eliottvincent
Copy link

eliottvincent commented Apr 9, 2024

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 8.45.0
  • eslint-plugin-vue version: 9.24.1
  • Vue version: n.a.
  • Node version: v20.5.0
  • Operating System: macOS 14.3.1 (23D60)

Please show your full configuration:

module.exports = {
  root: true,

  env: {
    browser: true,
    es6: true,
    node: true
  },

  parser: "vue-eslint-parser",

  parserOptions: {
    sourceType: "module"
  },

  extends: [
    "plugin:vue/vue3-recommended"
  ],

  plugins: [
    "eslint-plugin-jsdoc",
    "eliottvincent"
  ],

  rules: {
    "eliottvincent/import-group-comment": "error",

    "jsdoc/require-jsdoc": [
      "error",

      {
        "contexts": [
          "Property[key.name=\"methods\"] > ObjectExpression > Property"
        ]
      }
    ]
  }
};

What did you do?

<template lang="pug">
.hello-world
  span {{ "Hello world" }}
</template>

<script setup>
// NPM
import { definePageMeta, useHead } from "#imports";
import { useI18n } from "vue-i18n";

definePageMeta({
  layout: "showcase"
});

useHead({
  title: "Hello World"
});
</script>

<script>
export default {
  methods: {
    // --> EVENT LISTENERS <--

    /**
     * Some function
     * @public
     * @return {undefined}
     */
    someFunction() {
      console.log("test");
    }
  }
};
</script>

What did you expect to happen?
I have two rules:

  • a custom rule eliottvincent/import-group-comment: it ensures import statements are preceded by a comment stating their type
  • a rule from the official plugin jsdoc/require-jsdoc: it enforces JSDoc comments on functions and classes

I expect both these rules to work in Vue SFC files.

What actually happened?

When a Vue SFC file contains two script tags, one with setup keyword (to make use of Vue Composition API) and a regular one, both of these rules will fail (check the file res/example/not_ok.vue in the repro example).

When a Vue SFC file contains only one script tag, these rules work fine (check the file res/example/ok_1.vue in the repro example).

When a Vue SFC file contains two regular script tags (no setup keyword), these rules work fine as well (check the file res/example/ok_2.vue in the repro example).

This is the raw output:

/vue-eslint-parser-script-repro/res/example/not_ok.vue
   8:1  error  Import "#imports" should be in the "NPM" group  eliottvincent/import-group-comment
   9:1  error  Import "vue-i18n" should be in the "NPM" group  eliottvincent/import-group-comment
  30:5  error  Missing JSDoc comment                           jsdoc/require-jsdoc

✖ 3 problems (3 errors, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Repository to reproduce this issue

https://github.com/eliottvincent/vue-eslint-parser-script-repro

I suspect the culprit is the getCommentsBefore method which returns an empty array when both rule fails.

@eliottvincent
Copy link
Author

Initial issue: vuejs/vue-eslint-parser#230

Posting here as well since I don't know which repo is at fault. Thanks!

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

No branches or pull requests

1 participant