Skip to content

Commit f37c63c

Browse files
committed
feat: add setup-compiler-macros environment for enabling <script setup> compiler macro globals
1 parent 166dfbf commit f37c63c

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

docs/user-guide/README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,20 @@ module.exports = {
358358
}
359359
```
360360

361-
#### Compiler macros such as `defineProps` and `defineEmits` are warned by `no-undef` rule
361+
#### Compiler macros such as `defineProps` and `defineEmits` generate `no-undef` warnings
362362

363-
You need to define [global variables](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1) in your ESLint configuration file.
364-
If you don't want to define global variables, use `import { defineProps, defineEmits } from 'vue'`.
363+
You need to enable the compiler macros environment in your ESLint configuration file.
365364

366365
Example **.eslintrc.js**:
367366

368367
```js
369368
module.exports = {
370-
globals: {
371-
defineProps: "readonly",
372-
defineEmits: "readonly",
373-
defineExpose: "readonly",
374-
withDefaults: "readonly"
369+
env: {
370+
'vue/setup-compiler-macros': true
375371
}
376372
}
377373
```
378374

379-
See also [ESLint - Specifying Globals > Using configuration files](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1).
380-
381375
#### Parsing error with Top Level `await`
382376

383377
##### Using ESLint <= v7.x

lib/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,15 @@ module.exports = {
218218
},
219219
processors: {
220220
'.vue': require('./processor')
221+
},
222+
environments: {
223+
'setup-compiler-macros': {
224+
globals: {
225+
defineProps: 'readonly',
226+
defineEmits: 'readonly',
227+
defineExpose: 'readonly',
228+
withDefaults: 'readonly'
229+
}
230+
}
221231
}
222232
}

tools/update-lib-index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ module.exports = {
3737
},
3838
processors: {
3939
'.vue': require('./processor')
40+
},
41+
environments: {
42+
'setup-compiler-macros': {
43+
globals: {
44+
defineProps: 'readonly',
45+
defineEmits: 'readonly',
46+
defineExpose: 'readonly',
47+
withDefaults: 'readonly'
48+
}
49+
}
4050
}
4151
}
4252
`

0 commit comments

Comments
 (0)