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

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

Open
2 tasks done
lukasz-fi opened this issue Jul 2, 2024 · 1 comment
Open
2 tasks done
Labels

Comments

@lukasz-fi
Copy link

lukasz-fi commented Jul 2, 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.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.

@FloEdelmann
Copy link
Member

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 FloEdelmann added the bug label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants