Skip to content

Commit

Permalink
Update docs related to <script setup>. (#1530)
Browse files Browse the repository at this point in the history
* Update docs related to `<script setup>`.

* update doc

* update

* update doc
  • Loading branch information
ota-meshi committed Jul 6, 2021
1 parent 90cd61e commit 3cda46b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -15,7 +15,7 @@ This plugin allows us to check the `<template>` and `<script>` of `.vue` files w
ESLint editor integrations are useful to check your code in real-time.

:::warning Status of Vue.js 3.x supports
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.
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.
:::

## :traffic_light: Versioning policy
Expand Down
4 changes: 4 additions & 0 deletions docs/rules/experimental-script-setup-vars.md
Expand Up @@ -19,6 +19,10 @@ This rule will find variables defined in `<script setup="args">` and mark them a

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

:::warning
`<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).
:::

## :book: Rule Details

Without this rule this code triggers warning:
Expand Down
83 changes: 82 additions & 1 deletion docs/user-guide/README.md
Expand Up @@ -72,7 +72,7 @@ By default all rules from **base** and **essential** categories report ESLint er
:::

:::warning Status of Vue.js 3.x supports
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.
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.
:::

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

See also: "[Visual Studio Code](#editor-integrations)" section and [Vetur - Linting](https://vuejs.github.io/vetur/guide/linting-error.html#linting).

### Does not work well with `<script setup>`

#### The variables used in the `<template>` are warned by `no-unused-vars` rule

You must use [vue/script-setup-uses-vars](../rules/script-setup-uses-vars.md) rule.
In your configuration, use the rule set provided by `eslint-plugin-vue` or enable it rule.

Example **.eslintrc.js**:

```js
module.exports = {
// Use the rule set.
extends: ['plugin:vue/base'],
rules: {
// Enable vue/script-setup-uses-vars rule
'vue/script-setup-uses-vars': 'error',
}
}
```

#### 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

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.
However, `espree` v8+ can understand the syntax of ES2022 and parse the Top Level `await`.
You install `espree` v8+ and specify `"espree"` and ES2022 in your configuration, the parser will be able to parse it.

```js
module.exports = {
parser: 'vue-eslint-parser',
parserOptions: {
parser: 'espree', // <-
ecmaVersion: 2022, // <-
sourceType: 'module'
},
}
```

However, note that the AST generated by `espree` v8+ may not work well with some rules of `ESLint` v7.x.

<!--
##### Using ESLint >= v8.x
You need to specify `2022` for `parserOptions.ecmaVersion`.
```js
module.exports = {
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module'
},
}
```
-->

#### Other Problems

Try searching for existing issues.
If it does not exist, you should open a new issue and share your repository to reproduce the issue.

0 comments on commit 3cda46b

Please sign in to comment.