eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

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

Open lukasz-fi opened this issue 1 year ago • 1 comments

Checklist

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

Tell us about your environment

  • ESLint version: 8.57.0
  • eslint-plugin-vue version: 9.27.0
  • Vue version: 3.4.30
  • Node version: 20.15.0
  • Operating System: MacOS 14.5

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.

lukasz-fi avatar Jul 02 '24 11:07 lukasz-fi

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.

FloEdelmann avatar Jul 02 '24 14:07 FloEdelmann