Skip to content

feat: add setup-compiler-macros environment #1685

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

Merged
merged 1 commit into from
Oct 28, 2021
Merged
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
15 changes: 5 additions & 10 deletions docs/user-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,21 @@ 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.
If you don't want to expose these variables globally, you can use `/* global defineProps, defineEmits */` instead.

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
Expand Down
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,15 @@ module.exports = {
},
processors: {
'.vue': require('./processor')
},
environments: {
'setup-compiler-macros': {
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly'
}
}
}
}
10 changes: 10 additions & 0 deletions tools/update-lib-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ module.exports = {
},
processors: {
'.vue': require('./processor')
},
environments: {
'setup-compiler-macros': {
globals: {
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly'
}
}
}
}
`
Expand Down