Skip to content

Commit

Permalink
Upgrade vue-eslint-parser (#1849)
Browse files Browse the repository at this point in the history
* Upgrade vue-eslint-parser

* Update tests/lib/script-setup-vars.js

Co-authored-by: Flo Edelmann <[email protected]>

* Update docs/user-guide/README.md

Co-authored-by: Flo Edelmann <[email protected]>

* Update docs/user-guide/README.md

Co-authored-by: Flo Edelmann <[email protected]>

* Update parser

* Update tools/update-lib-index.js

Co-authored-by: Flo Edelmann <[email protected]>

Co-authored-by: Flo Edelmann <[email protected]>
  • Loading branch information
ota-meshi and FloEdelmann authored May 12, 2022
1 parent 186833a commit 2f96315
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Rules in this category are enabled for all presets provided by eslint-plugin-vue
|:--------|:------------|:--:|:--:|
| [vue/comment-directive](./comment-directive.md) | support comment-directives in `<template>` | | :warning: |
| [vue/jsx-uses-vars](./jsx-uses-vars.md) | prevent variables used in JSX to be marked as unused | | :warning: |
| [vue/script-setup-uses-vars](./script-setup-uses-vars.md) | prevent `<script setup>` variables used in `<template>` to be marked as unused | | :warning: |

</rules-table>

Expand Down Expand Up @@ -321,3 +320,4 @@ The following rules extend the rules provided by ESLint itself and apply them to
| [vue/no-confusing-v-for-v-if](./no-confusing-v-for-v-if.md) | [vue/no-use-v-if-with-v-for](./no-use-v-if-with-v-for.md) |
| [vue/no-invalid-model-keys](./no-invalid-model-keys.md) | [vue/valid-model-definition](./valid-model-definition.md) |
| [vue/no-unregistered-components](./no-unregistered-components.md) | [vue/no-undef-components](./no-undef-components.md) |
| [vue/script-setup-uses-vars](./script-setup-uses-vars.md) | (no replacement) |
1 change: 0 additions & 1 deletion docs/rules/jsx-uses-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ If you are not using JSX or if you do not use the `no-unused-vars` rule then you

## :couple: Related Rules

- [vue/script-setup-uses-vars](./script-setup-uses-vars.md)
- [no-unused-vars](https://eslint.org/docs/rules/no-unused-vars)

## :rocket: Version
Expand Down
14 changes: 12 additions & 2 deletions docs/rules/script-setup-uses-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ since: v7.13.0

> prevent `<script setup>` variables used in `<template>` to be marked as unused
- :gear: This rule is included in all of `"plugin:vue/base"`, `"plugin:vue/essential"`, `"plugin:vue/vue3-essential"`, `"plugin:vue/strongly-recommended"`, `"plugin:vue/vue3-strongly-recommended"`, `"plugin:vue/recommended"` and `"plugin:vue/vue3-recommended"`.
- :warning: This rule was **deprecated**.

::: tip

This rule is not needed when using `vue-eslint-parser` v9.0.0 or later.

:::

ESLint `no-unused-vars` rule does not detect variables in `<script setup>` used in `<template>`.
This rule will find variables in `<script setup>` used in `<template>` and mark them as used.
Expand Down Expand Up @@ -47,7 +53,11 @@ After turning on, `Foo` is being marked as used and `no-unused-vars` rule doesn'

## :mute: When Not To Use It

If you are not using `<script setup>` or if you do not use the `no-unused-vars` rule then you can disable this rule.
You can disable this rule in any of the following cases:

- You are using `vue-eslint-parser` v9.0.0 or later.
- You are not using `<script setup>`.
- You do not use the `no-unused-vars` rule.

## :couple: Related Rules

Expand Down
31 changes: 6 additions & 25 deletions docs/user-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,36 +342,15 @@ See also: "[Visual Studio Code](#editor-integrations)" section and [Vetur - Lint

#### 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.
You need to use [vue-eslint-parser] v9.0.0 or later.

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',
}
}
```
Previously you had to use the [vue/script-setup-uses-vars](../rules/script-setup-uses-vars.md) rule, this is no longer needed.

#### Compiler macros such as `defineProps` and `defineEmits` generate `no-undef` warnings

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.
You need to use [vue-eslint-parser] v9.0.0 or later.

Example **.eslintrc.js**:

```js
module.exports = {
env: {
'vue/setup-compiler-macros': true
}
}
```
Previously you had to use the `vue/setup-compiler-macros` environment, this is no longer needed.

#### Parsing error with Top Level `await`

Expand Down Expand Up @@ -411,3 +390,5 @@ module.exports = {

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

[vue-eslint-parser]: https://github.com/vuejs/vue-eslint-parser
3 changes: 1 addition & 2 deletions lib/configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = {
plugins: ['vue'],
rules: {
'vue/comment-directive': 'error',
'vue/jsx-uses-vars': 'error',
'vue/script-setup-uses-vars': 'error'
'vue/jsx-uses-vars': 'error'
}
}
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ module.exports = {
'.vue': require('./processor')
},
environments: {
// Deprecated
'setup-compiler-macros': {
globals: {
defineProps: 'readonly',
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/script-setup-uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ module.exports = {
docs: {
description:
'prevent `<script setup>` variables used in `<template>` to be marked as unused', // eslint-disable-line eslint-plugin/require-meta-docs-description
categories: ['base'],
categories: undefined,
url: 'https://eslint.vuejs.org/rules/script-setup-uses-vars.html'
},
deprecated: true,
schema: []
},
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"nth-check": "^2.0.1",
"postcss-selector-parser": "^6.0.9",
"semver": "^7.3.5",
"vue-eslint-parser": "^8.0.1"
"vue-eslint-parser": "^9.0.1"
},
"devDependencies": {
"@types/eslint": "^7.28.1",
Expand Down
Loading

0 comments on commit 2f96315

Please sign in to comment.