vuejs / eslint-plugin-vue

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

Script setup macros defineProps and defineEmits (no-undef) #1604

Closed mitow7821 closed 3 years ago

mitow7821 commented 3 years ago

Checklist

Tell us about your environment

Please show your full configuration:

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    "eslint:recommended",
    "airbnb-base",
    "plugin:vue/vue3-recommended",
    "prettier",
  ],
  parser: "vue-eslint-parser",
  parserOptions: {
    parser: "@babel/eslint-parser",
    ecmaVersion: 2021,
    sourceType: "module",
  },
  plugins: ["vue"],

  rules: {
    "vue/attribute-hyphenation": "off",
    "import/prefer-default-export": "off",
    "import/extensions": ["error", "ignorePackages"],
    "no-underscore-dangle": "off",
    "class-methods-use-this": "off",
    "import/no-cycle": ["error", { maxDepth: 1 }],
    "new-cap": ["error", { properties: false }],
    "no-param-reassign": "off",
    "consistent-return": "off",
    "no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
    "newline-before-return": "error",
  },

  settings: {
    "import/resolver": {
      alias: {
        map: [
          ["@", "./src"],
          ["@a", "./src/api"],
          ["@s", "./src/store"],
          ["@m", "./src/modules"],
          ["@c", "./src/components"],
          ["@l", "./src/layouts"],
          ["@h", "./src/helpers"],
        ],
        extensions: [".js", ".vue"],
      },
    },
  },
};

What did you do?

<script setup>
defineProps({
  alert: {
    type: Object,
    required: true,
  },
});
</script>

What did you expect to happen? I want to use defineProps and defineEmits macros, but eslint throws error "defineProps is not defined" - no undef.

What actually happened?

error 'defineProps' is not defined no-undef

Repository to reproduce this issue Create empty project with vue 3.2.1 and use defineProps macro inside <script setup>

mitow7821 commented 3 years ago

fixed defining global in eslint config

globals: {
    defineProps: "readonly",
    defineEmits: "readonly",
    defineExpose: "readonly",
  }