Skip to content

Commit 7628925

Browse files
authored
feat: supported new globals added in the new node.js versions (#154)
For eslintrc configs, using the 'env' property; for flat configs, reference the npm package 'globals'.
1 parent 0c9c2f3 commit 7628925

File tree

4 files changed

+23
-62
lines changed

4 files changed

+23
-62
lines changed

lib/configs/_commons.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,6 @@
11
"use strict"
22

33
module.exports = {
4-
commonGlobals: {
5-
// ECMAScript
6-
ArrayBuffer: "readonly",
7-
Atomics: "readonly",
8-
BigInt: "readonly",
9-
BigInt64Array: "readonly",
10-
BigUint64Array: "readonly",
11-
DataView: "readonly",
12-
Float32Array: "readonly",
13-
Float64Array: "readonly",
14-
Int16Array: "readonly",
15-
Int32Array: "readonly",
16-
Int8Array: "readonly",
17-
Map: "readonly",
18-
Promise: "readonly",
19-
Proxy: "readonly",
20-
Reflect: "readonly",
21-
Set: "readonly",
22-
SharedArrayBuffer: "readonly",
23-
Symbol: "readonly",
24-
Uint16Array: "readonly",
25-
Uint32Array: "readonly",
26-
Uint8Array: "readonly",
27-
Uint8ClampedArray: "readonly",
28-
WeakMap: "readonly",
29-
WeakSet: "readonly",
30-
31-
// ECMAScript (experimental)
32-
globalThis: "readonly",
33-
34-
// ECMA-402
35-
Intl: "readonly",
36-
37-
// Web Standard
38-
TextDecoder: "readonly",
39-
TextEncoder: "readonly",
40-
URL: "readonly",
41-
URLSearchParams: "readonly",
42-
WebAssembly: "readonly",
43-
clearInterval: "readonly",
44-
clearTimeout: "readonly",
45-
console: "readonly",
46-
queueMicrotask: "readonly",
47-
setInterval: "readonly",
48-
setTimeout: "readonly",
49-
50-
// Node.js
51-
Buffer: "readonly",
52-
GLOBAL: "readonly",
53-
clearImmediate: "readonly",
54-
global: "readonly",
55-
process: "readonly",
56-
root: "readonly",
57-
setImmediate: "readonly",
58-
},
594
commonRules: {
605
"n/no-deprecated-api": "error",
616
"n/no-extraneous-import": "error",

lib/configs/recommended-module.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"use strict"
22

3-
const { commonGlobals, commonRules } = require("./_commons")
3+
const globals = require("globals")
4+
const { commonRules } = require("./_commons")
45

56
// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
67
module.exports.eslintrc = {
8+
env: {
9+
node: true,
10+
es2021: true,
11+
},
712
globals: {
8-
...commonGlobals,
913
__dirname: "off",
1014
__filename: "off",
1115
exports: "off",
@@ -30,7 +34,11 @@ module.exports.eslintrc = {
3034
module.exports.flat = {
3135
languageOptions: {
3236
sourceType: "module",
33-
globals: module.exports.eslintrc.globals,
37+
globals: {
38+
...globals.node,
39+
...globals.es2021,
40+
...module.exports.eslintrc.globals,
41+
},
3442
},
3543
rules: module.exports.eslintrc.rules,
3644
}

lib/configs/recommended-script.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"use strict"
22

3-
const { commonGlobals, commonRules } = require("./_commons")
3+
const globals = require("globals")
4+
const { commonRules } = require("./_commons")
45

56
// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
67
module.exports.eslintrc = {
8+
env: {
9+
node: true,
10+
es2021: true,
11+
},
712
globals: {
8-
...commonGlobals,
913
__dirname: "readonly",
1014
__filename: "readonly",
1115
exports: "writable",
@@ -27,7 +31,11 @@ module.exports.eslintrc = {
2731
module.exports.flat = {
2832
languageOptions: {
2933
sourceType: "commonjs",
30-
globals: module.exports.eslintrc.globals,
34+
globals: {
35+
...globals.node,
36+
...globals.es2021,
37+
...module.exports.eslintrc.globals,
38+
},
3139
},
3240
rules: module.exports.eslintrc.rules,
3341
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"builtins": "^5.0.1",
1919
"eslint-plugin-es-x": "^7.5.0",
2020
"get-tsconfig": "^4.7.0",
21+
"globals": "^13.24.0",
2122
"ignore": "^5.2.4",
2223
"is-builtin-module": "^3.2.1",
2324
"is-core-module": "^2.12.1",
@@ -36,7 +37,6 @@
3637
"eslint-plugin-eslint-plugin": "^5.1.0",
3738
"eslint-plugin-n": "file:.",
3839
"fast-glob": "^3.2.12",
39-
"globals": "^13.20.0",
4040
"husky": "^8.0.3",
4141
"import-meta-resolve": "^3.0.0",
4242
"lint-staged": "^13.2.2",

0 commit comments

Comments
 (0)