Skip to content

Commit

Permalink
feat: supported new globals added in the new node.js versions (#154)
Browse files Browse the repository at this point in the history
For eslintrc configs, using the 'env' property;
for flat configs, reference the npm package 'globals'.
  • Loading branch information
aladdin-add authored Dec 29, 2023
1 parent 0c9c2f3 commit 7628925
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 62 deletions.
55 changes: 0 additions & 55 deletions lib/configs/_commons.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,6 @@
"use strict"

module.exports = {
commonGlobals: {
// ECMAScript
ArrayBuffer: "readonly",
Atomics: "readonly",
BigInt: "readonly",
BigInt64Array: "readonly",
BigUint64Array: "readonly",
DataView: "readonly",
Float32Array: "readonly",
Float64Array: "readonly",
Int16Array: "readonly",
Int32Array: "readonly",
Int8Array: "readonly",
Map: "readonly",
Promise: "readonly",
Proxy: "readonly",
Reflect: "readonly",
Set: "readonly",
SharedArrayBuffer: "readonly",
Symbol: "readonly",
Uint16Array: "readonly",
Uint32Array: "readonly",
Uint8Array: "readonly",
Uint8ClampedArray: "readonly",
WeakMap: "readonly",
WeakSet: "readonly",

// ECMAScript (experimental)
globalThis: "readonly",

// ECMA-402
Intl: "readonly",

// Web Standard
TextDecoder: "readonly",
TextEncoder: "readonly",
URL: "readonly",
URLSearchParams: "readonly",
WebAssembly: "readonly",
clearInterval: "readonly",
clearTimeout: "readonly",
console: "readonly",
queueMicrotask: "readonly",
setInterval: "readonly",
setTimeout: "readonly",

// Node.js
Buffer: "readonly",
GLOBAL: "readonly",
clearImmediate: "readonly",
global: "readonly",
process: "readonly",
root: "readonly",
setImmediate: "readonly",
},
commonRules: {
"n/no-deprecated-api": "error",
"n/no-extraneous-import": "error",
Expand Down
14 changes: 11 additions & 3 deletions lib/configs/recommended-module.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"use strict"

const { commonGlobals, commonRules } = require("./_commons")
const globals = require("globals")
const { commonRules } = require("./_commons")

// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
module.exports.eslintrc = {
env: {
node: true,
es2021: true,
},
globals: {
...commonGlobals,
__dirname: "off",
__filename: "off",
exports: "off",
Expand All @@ -30,7 +34,11 @@ module.exports.eslintrc = {
module.exports.flat = {
languageOptions: {
sourceType: "module",
globals: module.exports.eslintrc.globals,
globals: {
...globals.node,
...globals.es2021,
...module.exports.eslintrc.globals,
},
},
rules: module.exports.eslintrc.rules,
}
14 changes: 11 additions & 3 deletions lib/configs/recommended-script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"use strict"

const { commonGlobals, commonRules } = require("./_commons")
const globals = require("globals")
const { commonRules } = require("./_commons")

// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
module.exports.eslintrc = {
env: {
node: true,
es2021: true,
},
globals: {
...commonGlobals,
__dirname: "readonly",
__filename: "readonly",
exports: "writable",
Expand All @@ -27,7 +31,11 @@ module.exports.eslintrc = {
module.exports.flat = {
languageOptions: {
sourceType: "commonjs",
globals: module.exports.eslintrc.globals,
globals: {
...globals.node,
...globals.es2021,
...module.exports.eslintrc.globals,
},
},
rules: module.exports.eslintrc.rules,
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"builtins": "^5.0.1",
"eslint-plugin-es-x": "^7.5.0",
"get-tsconfig": "^4.7.0",
"globals": "^13.24.0",
"ignore": "^5.2.4",
"is-builtin-module": "^3.2.1",
"is-core-module": "^2.12.1",
Expand All @@ -36,7 +37,6 @@
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-n": "file:.",
"fast-glob": "^3.2.12",
"globals": "^13.20.0",
"husky": "^8.0.3",
"import-meta-resolve": "^3.0.0",
"lint-staged": "^13.2.2",
Expand Down

0 comments on commit 7628925

Please sign in to comment.