diff --git a/docs/user-guide/README.md b/docs/user-guide/README.md index 1b1e72fbc..7c39b56d5 100644 --- a/docs/user-guide/README.md +++ b/docs/user-guide/README.md @@ -358,26 +358,20 @@ module.exports = { } ``` -#### Compiler macros such as `defineProps` and `defineEmits` are warned by `no-undef` rule +#### Compiler macros such as `defineProps` and `defineEmits` generate `no-undef` warnings -You need to define [global variables](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1) in your ESLint configuration file. -If you don't want to define global variables, use `import { defineProps, defineEmits } from 'vue'`. +You need to enable the compiler macros environment in your ESLint configuration file. Example **.eslintrc.js**: ```js module.exports = { - globals: { - defineProps: "readonly", - defineEmits: "readonly", - defineExpose: "readonly", - withDefaults: "readonly" + env: { + 'vue/setup-compiler-macros': true } } ``` -See also [ESLint - Specifying Globals > Using configuration files](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1). - #### Parsing error with Top Level `await` ##### Using ESLint <= v7.x diff --git a/lib/index.js b/lib/index.js index 27567ae66..da16bbf1c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -218,5 +218,15 @@ module.exports = { }, processors: { '.vue': require('./processor') + }, + environments: { + 'setup-compiler-macros': { + globals: { + defineProps: 'readonly', + defineEmits: 'readonly', + defineExpose: 'readonly', + withDefaults: 'readonly' + } + } } } diff --git a/tools/update-lib-index.js b/tools/update-lib-index.js index 85a5ead3f..b9a5dcbd9 100644 --- a/tools/update-lib-index.js +++ b/tools/update-lib-index.js @@ -37,6 +37,16 @@ module.exports = { }, processors: { '.vue': require('./processor') + }, + environments: { + 'setup-compiler-macros': { + globals: { + defineProps: 'readonly', + defineEmits: 'readonly', + defineExpose: 'readonly', + withDefaults: 'readonly' + } + } } } `