Skip to content

Commit 3cda46b

Browse files
authored
Update docs related to <script setup>. (#1530)
* Update docs related to `<script setup>`. * update doc * update * update doc
1 parent 90cd61e commit 3cda46b

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This plugin allows us to check the `<template>` and `<script>` of `.vue` files w
1515
ESLint editor integrations are useful to check your code in real-time.
1616

1717
:::warning Status of Vue.js 3.x supports
18-
This plugin supports the basic syntax of Vue.js 3.0, but the Vue.js 3.0 experimental features `<script setup>` and `<style vars>` are not yet supported. Follow [#1248](https://github.com/vuejs/eslint-plugin-vue/issues/1248) for more details.
18+
This plugin supports the basic syntax of Vue.js 3.0 and `<script setup>`, but the Vue.js 3.0 experimental feature CSS variable injection is not yet supported. Follow [#1248](https://github.com/vuejs/eslint-plugin-vue/issues/1248) for more details.
1919
:::
2020

2121
## :traffic_light: Versioning policy

docs/rules/experimental-script-setup-vars.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ This rule will find variables defined in `<script setup="args">` and mark them a
1919

2020
This rule only has an effect when the `no-undef` rule is enabled.
2121

22+
:::warning
23+
`<script setup="args">` syntax wasn't rejected by Vue's RFC. Check out the [new syntax](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md).
24+
:::
25+
2226
## :book: Rule Details
2327

2428
Without this rule this code triggers warning:

docs/user-guide/README.md

+82-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ By default all rules from **base** and **essential** categories report ESLint er
7272
:::
7373

7474
:::warning Status of Vue.js 3.x supports
75-
This plugin supports the basic syntax of Vue.js 3.0, but the Vue.js 3.0 experimental features `<script setup>` and `<style vars>` are not yet supported. Follow [#1248](https://github.com/vuejs/eslint-plugin-vue/issues/1248) for more details.
75+
This plugin supports the basic syntax of Vue.js 3.0 and `<script setup>`, but the Vue.js 3.0 experimental feature CSS variable injection is not yet supported. Follow [#1248](https://github.com/vuejs/eslint-plugin-vue/issues/1248) for more details.
7676
:::
7777

7878
### Running ESLint from the command line
@@ -335,3 +335,84 @@ Note that you cannot use angle-bracket type assertion style (`var x = <foo>bar;`
335335
You need to turn off Vetur's template validation by adding `vetur.validation.template: false` to your `.vscode/settings.json`.
336336

337337
See also: "[Visual Studio Code](#editor-integrations)" section and [Vetur - Linting](https://vuejs.github.io/vetur/guide/linting-error.html#linting).
338+
339+
### Does not work well with `<script setup>`
340+
341+
#### The variables used in the `<template>` are warned by `no-unused-vars` rule
342+
343+
You must use [vue/script-setup-uses-vars](../rules/script-setup-uses-vars.md) rule.
344+
In your configuration, use the rule set provided by `eslint-plugin-vue` or enable it rule.
345+
346+
Example **.eslintrc.js**:
347+
348+
```js
349+
module.exports = {
350+
// Use the rule set.
351+
extends: ['plugin:vue/base'],
352+
rules: {
353+
// Enable vue/script-setup-uses-vars rule
354+
'vue/script-setup-uses-vars': 'error',
355+
}
356+
}
357+
```
358+
359+
#### Compiler macros such as `defineProps` and `defineEmits` are warned by `no-undef` rule
360+
361+
You need to define [global variables](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1) in your ESLint configuration file.
362+
If you don't want to define global variables, use `import { defineProps, defineEmits } from 'vue'`.
363+
364+
Example **.eslintrc.js**:
365+
366+
```js
367+
module.exports = {
368+
globals: {
369+
defineProps: "readonly",
370+
defineEmits: "readonly",
371+
defineExpose: "readonly",
372+
withDefaults: "readonly"
373+
}
374+
}
375+
```
376+
377+
See also [ESLint - Specifying Globals > Using configuration files](https://eslint.org/docs/user-guide/configuring/language-options#using-configuration-files-1).
378+
379+
#### Parsing error with Top Level `await`
380+
381+
##### Using ESLint <= v7.x
382+
383+
The parser `espree` that comes with `ESLint` v7.x doesn't understand the syntax of ES2022, so it can't parse the Top Level `await` either.
384+
However, `espree` v8+ can understand the syntax of ES2022 and parse the Top Level `await`.
385+
You install `espree` v8+ and specify `"espree"` and ES2022 in your configuration, the parser will be able to parse it.
386+
387+
```js
388+
module.exports = {
389+
parser: 'vue-eslint-parser',
390+
parserOptions: {
391+
parser: 'espree', // <-
392+
ecmaVersion: 2022, // <-
393+
sourceType: 'module'
394+
},
395+
}
396+
```
397+
398+
However, note that the AST generated by `espree` v8+ may not work well with some rules of `ESLint` v7.x.
399+
400+
<!--
401+
##### Using ESLint >= v8.x
402+
403+
You need to specify `2022` for `parserOptions.ecmaVersion`.
404+
405+
```js
406+
module.exports = {
407+
parserOptions: {
408+
ecmaVersion: 2022,
409+
sourceType: 'module'
410+
},
411+
}
412+
```
413+
-->
414+
415+
#### Other Problems
416+
417+
Try searching for existing issues.
418+
If it does not exist, you should open a new issue and share your repository to reproduce the issue.

0 commit comments

Comments
 (0)