Skip to content

Commit 3c3f711

Browse files
committed
Remove globals from configs (#2674)
1 parent 118ef57 commit 3c3f711

File tree

6 files changed

+78
-14
lines changed

6 files changed

+78
-14
lines changed

docs/user-guide/index.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ npm install --save-dev eslint eslint-plugin-vue
1111
Via [yarn](https://yarnpkg.com/):
1212

1313
```bash
14-
yarn add -D eslint eslint-plugin-vue
14+
yarn add -D eslint eslint-plugin-vue globals
1515
```
1616

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

3232
```js
3333
import pluginVue from 'eslint-plugin-vue'
34+
import globals from 'globals'
35+
3436
export default [
3537
// add more generic rulesets here, such as:
3638
// js.configs.recommended,
@@ -40,6 +42,12 @@ export default [
4042
rules: {
4143
// override/add rules settings here, such as:
4244
// 'vue/no-unused-vars': 'error'
45+
},
46+
languageOptions: {
47+
sourceType: 'module',
48+
globals: {
49+
...globals.browser
50+
}
4351
}
4452
}
4553
]
@@ -67,6 +75,48 @@ You can use the following configs by adding them to `eslint.config.js`.
6775
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).
6876
:::
6977

78+
#### Specifying Globals (`eslint.config.js`)
79+
80+
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).
81+
82+
If you're writing an app that will only render on the browser, use `globals.browser`.
83+
84+
```js
85+
// ...
86+
import globals from 'globals'
87+
88+
export default [
89+
// ...
90+
{
91+
languageOptions: {
92+
globals: {
93+
...globals.browser
94+
}
95+
}
96+
}
97+
// ...
98+
]
99+
```
100+
101+
If you're writing an app that is rendered both server-side and on the browser, use `globals.shared-node-browser`.
102+
103+
```js
104+
// ...
105+
import globals from 'globals'
106+
107+
export default [
108+
// ...
109+
{
110+
languageOptions: {
111+
globals: {
112+
...globals['shared-node-browser']
113+
}
114+
}
115+
}
116+
// ...
117+
]
118+
```
119+
70120
#### Example configuration with [typescript-eslint](https://typescript-eslint.io/) and [Prettier](https://prettier.io/)
71121

72122
```bash
@@ -152,6 +202,30 @@ This plugin supports the basic syntax of Vue.js 3.2, `<script setup>`, and CSS v
152202
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.
153203
:::
154204

205+
#### Specifying Environments (`.eslintrc`)
206+
207+
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).
208+
209+
If you're writing an app that will only render on the browser, use `env.browser`.
210+
211+
```json
212+
{
213+
"env": {
214+
"browser": true
215+
}
216+
}
217+
```
218+
219+
If you're writing an app that is rendered both server-side and on the browser, use `env.shared-node-browser`.
220+
221+
```json
222+
{
223+
"env": {
224+
"shared-node-browser": true
225+
}
226+
}
227+
```
228+
155229
### Running ESLint from the command line
156230

157231
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.

lib/configs/base.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
* This file has been automatically generated,
44
* in order to update its content execute "npm run update"
55
*/
6-
const globals = require('globals')
76
module.exports = {
87
parserOptions: {
98
ecmaVersion: 'latest',
109
sourceType: 'module'
1110
},
12-
globals: globals.browser,
1311
plugins: ['vue'],
1412
rules: {
1513
'vue/comment-directive': 'error',

lib/configs/flat/base.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* This file has been automatically generated,
44
* in order to update its content execute "npm run update"
55
*/
6-
const globals = require('globals')
76
module.exports = [
87
{
98
name: 'vue/base/setup',
@@ -13,8 +12,7 @@ module.exports = [
1312
}
1413
},
1514
languageOptions: {
16-
sourceType: 'module',
17-
globals: globals.browser
15+
sourceType: 'module'
1816
}
1917
},
2018
{
@@ -27,8 +25,7 @@ module.exports = [
2725
},
2826
languageOptions: {
2927
parser: require('vue-eslint-parser'),
30-
sourceType: 'module',
31-
globals: globals.browser
28+
sourceType: 'module'
3229
},
3330
rules: {
3431
'vue/comment-directive': 'error',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
},
6060
"dependencies": {
6161
"@eslint-community/eslint-utils": "^4.4.0",
62-
"globals": "^15.14.0",
6362
"natural-compare": "^1.4.0",
6463
"nth-check": "^2.1.1",
6564
"postcss-selector-parser": "^6.0.15",
@@ -91,6 +90,7 @@
9190
"eslint-plugin-vue": "file:.",
9291
"espree": "^9.6.1",
9392
"events": "^3.3.0",
93+
"globals": "^15.14.0",
9494
"jsdom": "^22.0.0",
9595
"markdownlint-cli": "^0.42.0",
9696
"mocha": "^10.7.3",

tools/update-lib-configs.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ function formatCategory(category) {
5555
* This file has been automatically generated,
5656
* in order to update its content execute "npm run update"
5757
*/
58-
const globals = require('globals')
5958
module.exports = {
6059
parserOptions: {
6160
ecmaVersion: 'latest',
6261
sourceType: 'module'
6362
},
64-
globals: globals.browser,
6563
plugins: [
6664
'vue'
6765
],

tools/update-lib-flat-configs.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function formatCategory(category) {
5555
* This file has been automatically generated,
5656
* in order to update its content execute "npm run update"
5757
*/
58-
const globals = require('globals')
5958
module.exports = [
6059
{
6160
name: 'vue/base/setup',
@@ -66,7 +65,6 @@ module.exports = [
6665
},
6766
languageOptions: {
6867
sourceType: 'module',
69-
globals: globals.browser
7068
}
7169
},
7270
{
@@ -80,7 +78,6 @@ module.exports = [
8078
languageOptions: {
8179
parser: require('vue-eslint-parser'),
8280
sourceType: 'module',
83-
globals: globals.browser
8481
},
8582
rules: ${formatRules(category.rules, category.categoryId)},
8683
processor: 'vue/vue'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy