Skip to content

disallow importing defineProps etc #1906

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

Closed
jacekkarczmarczyk opened this issue May 26, 2022 · 4 comments
Closed

disallow importing defineProps etc #1906

jacekkarczmarczyk opened this issue May 26, 2022 · 4 comments

Comments

@jacekkarczmarczyk
Copy link

Please describe what the rule should do:
It should warn if defineProps, defineEmits and similar are imported from vue (autofixable)

What category should the rule belong to?

[x] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

bad:

<script setup>
import { defineProps } from '@vue/runtime-dom';

defineProps<{}>();
</script>

good:

<script setup>
defineProps<{}>();
</script>

good:

<script setup>
import { defineProps } from 'my-lib';

defineProps('whatever');

Additional context
Useful when define* are added to eslint globals, there's no need to import them manually. If project was using imports and then dev switched to globals then autofix would just automatically remove unnecessary imports

@ota-meshi
Copy link
Member

Thank you for the rule proposal!
That rule is sounds good to me.

@ItMaga
Copy link
Contributor

ItMaga commented Jan 17, 2023

Isn't this case solved by the rule https://eslint.org/docs/latest/rules/no-restricted-imports?

An example:

'no-restricted-imports': [
  'error',
  {
    patterns: [
      {
        group: ['@vue/*', 'vue'],
        importNames: ['defineProps', 'defineEmits'],
        message: "'defineProps' and 'defineEmits' can be used within <script setup> without importing.",
      },
    ],
  },
]

@FloEdelmann
Copy link
Member

Also, we now have the vue/prefer-import-from-vue rule, which would also warn about the import. So I think the rule suggested in this issue is not required anymore.

@yooouuri
Copy link

yooouuri commented Oct 9, 2023

@FloEdelmann this isn't the case, defineProps and defineEmits are compiler macro's and should not be imported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants