vuejs / eslint-plugin-vue

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

bug with 3.2.2 lint error no-undef defineProps and defineEmits API's #1606

Closed wcbell51 closed 3 years ago

wcbell51 commented 3 years ago

Checklist

Tell us about your environment

Please show your full configuration:

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    'plugin:vue/vue3-essential',
    '@vue/airbnb',
    '@vue/typescript/recommended',
  ],
  parserOptions: {
    ecmaVersion: 2020,
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    'max-len': ['error', { code: 150 }],
    'linebreak-style': 0,
  },
};

What did you do?

const props = defineProps({
  name: String,
});

What did you expect to happen? -no errors

What actually happened?

Module Error (from ./node_modules/eslint-loader/index.js):

20:15 error 'defineProps' is not defined no-undef ✖ 1 problem (1 error, 0 warnings)

@ ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/views/Scenes.vue?vue&type=script&setup=true&lang=js 3:0-56 21:19-30 @ ./src/views/Scenes.vue?vue&type=script&setup=true&lang=js tup=true&lang=js 3:0-56 21:19-30
@ ./src/views/Scenes.vue @ ./src/router/index.ts @ ./src/main.ts @ multi (webpack)-dev-server/client?http://192.168.86.221:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

Repository to reproduce this issue

-> cannot submit ~ internal repo with my company

thought I'd leave these here as well~

image screen shot from this page in the docs: https://v3.vuejs.org/api/sfc-script-setup.html#using-components

image this was a post I made in the Vue Land Discord about the issue

image this was a DM I had with someone from the vue core team who referred me to post an issue about this in this repository so here I am :)

wcbell51 commented 3 years ago

hope this helps: right now the only way to get around this is to import defineProps from vue until you all hopefully update the package. thank you in advance!

ota-meshi commented 3 years ago

Please read faq. https://eslint.vuejs.org/user-guide/#compiler-macros-such-as-defineprops-and-defineemits-are-warned-by-no-undef-rule

haoqunjiang commented 3 years ago

Is it possible to only enable these globals in <script setup>?

ota-meshi commented 3 years ago

There is no way to define globals only in <script setup>. You need use import {defineProps, defineEmits} from 'vue', if you don't want to add it to globals in other files.

KaliaJS commented 3 years ago

@ota-meshi Putting this information in the doc at https://v3.vuejs.org/api/sfc-script-setup.html#defineprops-and-defineemits would be very useful. I looked for a while before I got here.