diff --git a/docs/user-guide/README.md b/docs/user-guide/README.md index 1b1e72fbc..5db1bf191 100644 --- a/docs/user-guide/README.md +++ b/docs/user-guide/README.md @@ -358,26 +358,6 @@ module.exports = { } ``` -#### Compiler macros such as `defineProps` and `defineEmits` are warned by `no-undef` rule - -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'`. - -Example **.eslintrc.js**: - -```js -module.exports = { - globals: { - defineProps: "readonly", - defineEmits: "readonly", - defineExpose: "readonly", - withDefaults: "readonly" - } -} -``` - -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/configs/vue3-essential.js b/lib/configs/vue3-essential.js index 43e8b9253..73c369f9b 100644 --- a/lib/configs/vue3-essential.js +++ b/lib/configs/vue3-essential.js @@ -79,5 +79,11 @@ module.exports = { 'vue/valid-v-show': 'error', 'vue/valid-v-slot': 'error', 'vue/valid-v-text': 'error' + }, + globals: { + defineProps: 'readonly', + defineEmits: 'readonly', + defineExpose: 'readonly', + withDefaults: 'readonly' } } diff --git a/tools/lib/categories.js b/tools/lib/categories.js index 7223fd87b..da8377dd9 100644 --- a/tools/lib/categories.js +++ b/tools/lib/categories.js @@ -6,6 +6,7 @@ 'use strict' const rules = require('./rules') +const categoryGlobals = require('./globals') const categoryTitles = { base: { @@ -75,6 +76,7 @@ module.exports = categoryIds title: categoryTitles[categoryId], rules: (categoryRules[categoryId] || []).filter( (rule) => !rule.meta.deprecated - ) + ), + globals: categoryGlobals[categoryId] })) .filter((category) => category.rules.length >= 1) diff --git a/tools/lib/globals.js b/tools/lib/globals.js new file mode 100644 index 000000000..83a9fa33f --- /dev/null +++ b/tools/lib/globals.js @@ -0,0 +1,14 @@ +/** + * @author Ivo Janssen + * See LICENSE file in root directory for full license. + */ +'use strict' + +module.exports = { + 'vue3-essential': { + defineProps: 'readonly', + defineEmits: 'readonly', + defineExpose: 'readonly', + withDefaults: 'readonly' + } +} diff --git a/tools/update-lib-configs.js b/tools/update-lib-configs.js index b5b2488ca..40b9b00f8 100644 --- a/tools/update-lib-configs.js +++ b/tools/update-lib-configs.js @@ -71,6 +71,7 @@ module.exports = { module.exports = { extends: require.resolve('./${extendsCategoryId}'), rules: ${formatRules(category.rules, category.categoryId)} + ${category.globals ? `,globals: ${JSON.stringify(category.globals)}` : ''} } ` }