Skip to content

Commit

Permalink
Revert "Revert "Remove globals from config" (#2673)"
Browse files Browse the repository at this point in the history
This reverts commit ee05994.
  • Loading branch information
ota-meshi authored Jan 30, 2025
1 parent ee05994 commit 0c03b77
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
76 changes: 75 additions & 1 deletion docs/user-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ npm install --save-dev eslint eslint-plugin-vue
Via [yarn](https://yarnpkg.com/):

```bash
yarn add -D eslint eslint-plugin-vue
yarn add -D eslint eslint-plugin-vue globals
```

::: tip Requirements
Expand All @@ -31,6 +31,8 @@ Example **eslint.config.js**:

```js
import pluginVue from 'eslint-plugin-vue'
import globals from 'globals'

export default [
// add more generic rulesets here, such as:
// js.configs.recommended,
Expand All @@ -40,6 +42,12 @@ export default [
rules: {
// override/add rules settings here, such as:
// 'vue/no-unused-vars': 'error'
},
languageOptions: {
sourceType: 'module',
globals: {
...globals.browser
}
}
}
]
Expand Down Expand Up @@ -67,6 +75,48 @@ You can use the following configs by adding them to `eslint.config.js`.
By default, all rules from **base** and **essential** categories report ESLint errors. Other rules - because they're not covering potential bugs in the application - report warnings. What does it mean? By default - nothing, but if you want - you can set up a threshold and break the build after a certain amount of warnings, instead of any. More information [here](https://eslint.org/docs/user-guide/command-line-interface#handling-warnings).
:::

#### Specifying Globals (`eslint.config.js`)

Specify global objects depending on how you use Vue.js. More information on how to set globals can be found [here](https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables).

If you're writing an app that will only render on the browser, use `globals.browser`.

```js
// ...
import globals from 'globals'

export default [
// ...
{
languageOptions: {
globals: {
...globals.browser
}
}
}
// ...
]
```

If you're writing an app that is rendered both server-side and on the browser, use `globals.shared-node-browser`.

```js
// ...
import globals from 'globals'

export default [
// ...
{
languageOptions: {
globals: {
...globals['shared-node-browser']
}
}
}
// ...
]
```

#### Example configuration with [typescript-eslint](https://typescript-eslint.io/) and [Prettier](https://prettier.io/)

```bash
Expand Down Expand Up @@ -152,6 +202,30 @@ This plugin supports the basic syntax of Vue.js 3.2, `<script setup>`, and CSS v
If you have issues with these, please also refer to the [FAQ](#does-not-work-well-with-script-setup). If you can't find a solution, search for the issue and if the issue doesn't exist, open a new issue.
:::

#### Specifying Environments (`.eslintrc`)

Specify environments depending on how you use Vue.js. More information on how to set environments can be found [here](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-environments).

If you're writing an app that will only render on the browser, use `env.browser`.

```json
{
"env": {
"browser": true
}
}
```

If you're writing an app that is rendered both server-side and on the browser, use `env.shared-node-browser`.

```json
{
"env": {
"shared-node-browser": true
}
}
```

### Running ESLint from the command line

If you want to run `eslint` from the command line, ESLint will automatically check for the `.vue` extension if you use the config provided by the plugin.
Expand Down
2 changes: 0 additions & 2 deletions lib/configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
* This file has been automatically generated,
* in order to update its content execute "npm run update"
*/
const globals = require('globals')
module.exports = {
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
globals: globals.browser,
plugins: ['vue'],
rules: {
'vue/comment-directive': 'error',
Expand Down
7 changes: 2 additions & 5 deletions lib/configs/flat/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* This file has been automatically generated,
* in order to update its content execute "npm run update"
*/
const globals = require('globals')
module.exports = [
{
name: 'vue/base/setup',
Expand All @@ -13,8 +12,7 @@ module.exports = [
}
},
languageOptions: {
sourceType: 'module',
globals: globals.browser
sourceType: 'module'
}
},
{
Expand All @@ -27,8 +25,7 @@ module.exports = [
},
languageOptions: {
parser: require('vue-eslint-parser'),
sourceType: 'module',
globals: globals.browser
sourceType: 'module'
},
rules: {
'vue/comment-directive': 'error',
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,6 @@
},
"dependencies": {
"@eslint-community/eslint-utils": "^4.4.0",
"globals": "^15.14.0",
"natural-compare": "^1.4.0",
"nth-check": "^2.1.1",
"postcss-selector-parser": "^6.0.15",
Expand Down Expand Up @@ -91,6 +90,7 @@
"eslint-plugin-vue": "file:.",
"espree": "^9.6.1",
"events": "^3.3.0",
"globals": "^15.14.0",
"jsdom": "^22.0.0",
"markdownlint-cli": "^0.42.0",
"mocha": "^10.7.3",
Expand Down
2 changes: 0 additions & 2 deletions tools/update-lib-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ function formatCategory(category) {
* This file has been automatically generated,
* in order to update its content execute "npm run update"
*/
const globals = require('globals')
module.exports = {
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
globals: globals.browser,
plugins: [
'vue'
],
Expand Down
3 changes: 0 additions & 3 deletions tools/update-lib-flat-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function formatCategory(category) {
* This file has been automatically generated,
* in order to update its content execute "npm run update"
*/
const globals = require('globals')
module.exports = [
{
name: 'vue/base/setup',
Expand All @@ -66,7 +65,6 @@ module.exports = [
},
languageOptions: {
sourceType: 'module',
globals: globals.browser
}
},
{
Expand All @@ -80,7 +78,6 @@ module.exports = [
languageOptions: {
parser: require('vue-eslint-parser'),
sourceType: 'module',
globals: globals.browser
},
rules: ${formatRules(category.rules, category.categoryId)},
processor: 'vue/vue'
Expand Down

0 comments on commit 0c03b77

Please sign in to comment.