vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.4k stars 656 forks source link

vue/no-unused-properties doesn't see usage when used in imported function from another file #2495

Open lukasz-fi opened 3 days ago

lukasz-fi commented 3 days ago

Checklist

Tell us about your environment

Please show your full configuration: .eslintrc.cjs

/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
  extends: [
    'plugin:vue/vue3-recommended',
    '@vue/eslint-config-typescript/recommended',
    '@vue/eslint-config-prettier/skip-formatting',
  ],
  overrides: [
    {
      files: ['*.ts'],
      parser: '@typescript-eslint/parser',
      plugins: ['@typescript-eslint'],
    },
    {
      files: '*.vue',
      rules: {
        'vue/no-unused-properties': 2,
      },
    },
  ],
  parserOptions: {
    ecmaVersion: 'latest',
  },
  root: true,
};

What did you do? This throws 'example' of property found, but never used vue/no-unused-properties:

<script lang="ts" setup>
import { useExample } from '@/utils/example';

const props = defineProps<{
  /**
   * Example prop.  
   */
  example: boolean;
}>();

const { text } = useExample(props);
</script>

<template>
  {{ text }}
</template>

When the useExample is in the same file then there is no error:

<script lang="ts">
export const useExample = (props: { example?: boolean }): { text: string } => {
  return { text: props.example ? 'Example' : 'Test' };
};
</script>

<script lang="ts" setup>
const props = defineProps<{
  /**
   * Example prop.
   */
  example: boolean;
}>();

const { text } = useExample(props);
</script>

<template>
  {{ text }}
</template>

What did you expect to happen? In both cases the prop example should be recognized as used.

What actually happened?

> eslint . --max-warnings=0

[path]/TestExample.vue
  8:3  error  'example' of property found, but never used  vue/no-unused-properties

✖ 1 problem (1 error, 0 warnings)

Repository to reproduce this issue Minimal reproduction code is above.

FloEdelmann commented 3 days ago

Indeed, I think that all props should be marked as used when the whole props object is passed to an (unknown) function.

However, note that toRef(props, 'foo') should only mark the foo prop as used.