Skip to content

feat: include Vue3 script setup compiler macro globals #1682

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions docs/user-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/configs/vue3-essential.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
4 changes: 3 additions & 1 deletion tools/lib/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict'

const rules = require('./rules')
const categoryGlobals = require('./globals')

const categoryTitles = {
base: {
Expand Down Expand Up @@ -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)
14 changes: 14 additions & 0 deletions tools/lib/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @author Ivo Janssen <https://github.com/foxxyz>
* See LICENSE file in root directory for full license.
*/
'use strict'

module.exports = {
'vue3-essential': {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly'
}
}
1 change: 1 addition & 0 deletions tools/update-lib-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}` : ''}
}
`
}
Expand Down