Skip to content

Commit

Permalink
Revert "Remove globals from config" (#2673)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Jan 30, 2025
1 parent 36e3dda commit ee05994
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 78 deletions.
76 changes: 1 addition & 75 deletions 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 globals
yarn add -D eslint eslint-plugin-vue
```

::: tip Requirements
Expand All @@ -31,8 +31,6 @@ 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 @@ -42,12 +40,6 @@ 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 @@ -75,48 +67,6 @@ 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 @@ -202,30 +152,6 @@ 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: 2 additions & 0 deletions lib/configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* 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: 5 additions & 2 deletions lib/configs/flat/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 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 @@ -12,7 +13,8 @@ module.exports = [
}
},
languageOptions: {
sourceType: 'module'
sourceType: 'module',
globals: globals.browser
}
},
{
Expand All @@ -25,7 +27,8 @@ module.exports = [
},
languageOptions: {
parser: require('vue-eslint-parser'),
sourceType: 'module'
sourceType: 'module',
globals: globals.browser
},
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,6 +59,7 @@
},
"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 @@ -90,7 +91,6 @@
"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: 2 additions & 0 deletions tools/update-lib-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ 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: 3 additions & 0 deletions tools/update-lib-flat-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ 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 @@ -65,6 +66,7 @@ module.exports = [
},
languageOptions: {
sourceType: 'module',
globals: globals.browser
}
},
{
Expand All @@ -78,6 +80,7 @@ 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 ee05994

Please sign in to comment.