chore: remove usage of the prefer-global rules (#11279)

This commit is contained in:
Denis-Adrian Cristea
2025-12-10 16:05:29 +02:00
committed by GitHub
parent 548d75258b
commit 9bf1f739e0
43 changed files with 64 additions and 66 deletions

View File

@@ -17,7 +17,26 @@ const commonFiles = '{js,mjs,cjs,ts,mts,cts,jsx,tsx}';
const commonRuleset = merge(...common, { files: [`**/*${commonFiles}`] });
const nodeRuleset = merge(...node, { files: [`**/*${commonFiles}`] });
const nodeRuleset = merge(...node, {
files: [`**/*${commonFiles}`],
rules: {
'no-restricted-globals': 0,
'n/prefer-global/buffer': [2, 'never'],
'n/prefer-global/console': [2, 'always'],
'n/prefer-global/process': [2, 'never'],
'n/prefer-global/text-decoder': [2, 'always'],
'n/prefer-global/text-encoder': [2, 'always'],
'n/prefer-global/url-search-params': [2, 'always'],
'n/prefer-global/url': [2, 'always'],
},
});
const nodeBinRuleset = {
files: [`**/bin/*{js,mjs,cjs,ts,mts,cts}`],
rules: {
'n/shebang': [0],
},
};
const typeScriptRuleset = merge(...typescript, {
files: [`**/*${commonFiles}`],
@@ -93,6 +112,7 @@ export default defineConfig(
},
commonRuleset,
nodeRuleset,
nodeBinRuleset,
typeScriptRuleset,
{
files: ['**/*{ts,mts,cts,tsx}'],
@@ -123,7 +143,6 @@ export default defineConfig(
{
files: [`packages/{api-extractor,api-extractor-model,api-extractor-utils}/**/*${commonFiles}`],
rules: {
'n/prefer-global/process': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-empty-object-type': 0,
@@ -236,11 +255,6 @@ export default defineConfig(
{
files: [`packages/rest/**/*${commonFiles}`],
rules: {
'n/prefer-global/url': 0,
'n/prefer-global/url-search-params': 0,
'n/prefer-global/buffer': 0,
'n/prefer-global/process': 0,
'no-restricted-globals': 0,
'unicorn/prefer-node-protocol': 0,
},
},
@@ -255,8 +269,6 @@ export default defineConfig(
{
files: [`packages/voice/**/*${commonFiles}`],
rules: {
'no-restricted-globals': 0,
'n/prefer-global/buffer': 0,
'@typescript-eslint/no-unsafe-declaration-merging': 0,
},
},

View File

@@ -1,5 +1,4 @@
import process from 'node:process';
import { setInterval, clearInterval } from 'node:timers';
import { info, warning } from '@actions/core';
import { getOctokit, context } from '@actions/github';
import { $ } from 'bun';

View File

@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { URL } from 'node:url';
/**
* Constructor options for `SourceLocation`.
*

View File

@@ -1,9 +1,9 @@
/* eslint-disable no-restricted-globals */
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as os from 'node:os';
import * as path from 'node:path';
import process from 'node:process';
import { PackageJsonLookup, FileSystem, type IPackageJson, Path } from '@rushstack/node-core-library';
import {
CommandLineAction,

View File

@@ -2,7 +2,7 @@
// See LICENSE in the project root for license information.
import * as os from 'node:os';
import * as process from 'node:process';
import process from 'node:process';
import colors from 'colors';
import { Extractor } from './api/Extractor.js';
import { ApiExtractorCommandLine } from './cli/ApiExtractorCommandLine.js';

View File

@@ -1,5 +1,4 @@
import type { Buffer } from 'node:buffer';
import { clearTimeout, setTimeout } from 'node:timers';
import type Redis from 'ioredis/built/Redis.js';
import type { IRPCBroker } from '../Broker.js';
import type { RedisBrokerOptions } from './BaseRedis.js';

View File

@@ -27,7 +27,6 @@ export class OAuth2API {
* @param options - The options for creating the authorization URL
*/
public generateAuthorizationURL(options: RESTOAuth2AuthorizationQuery) {
// eslint-disable-next-line n/prefer-global/url
const url = new URL(`${RouteBases.api}${Routes.oauth2Authorization()}`);
url.search = makeURLSearchParams(options).toString();
return url.toString();

View File

@@ -1,4 +1,3 @@
import { clearTimeout, setTimeout } from 'node:timers';
import type { REST } from '@discordjs/rest';
import { calculateShardId, GatewayRateLimitError } from '@discordjs/util';
import { WebSocketShardEvents } from '@discordjs/ws';

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env node
// eslint-disable-next-line n/shebang
import process from 'node:process';
import { styleText } from 'node:util';
import { Option, program } from 'commander';

View File

@@ -1,5 +1,4 @@
import { readFile, writeFile } from 'node:fs/promises';
import { URL } from 'node:url';
const pkgJsonPath = new URL('../package.json', import.meta.url);
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf8'));

View File

@@ -2,7 +2,6 @@ import type { ExecException } from 'node:child_process';
import { cp, mkdir, stat, readdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';
import { URL } from 'node:url';
import { styleText } from 'node:util';
import type { PackageManager } from './helpers/packageManager.js';
import { install } from './helpers/packageManager.js';

View File

@@ -11,6 +11,14 @@ const config = [
...prettier,
{
rules: {
'no-restricted-globals': 0,
'n/prefer-global/buffer': [2, 'never'],
'n/prefer-global/console': [2, 'always'],
'n/prefer-global/process': [2, 'never'],
'n/prefer-global/text-decoder': [2, 'always'],
'n/prefer-global/text-encoder': [2, 'always'],
'n/prefer-global/url-search-params': [2, 'always'],
'n/prefer-global/url': [2, 'always'],
'jsdoc/check-tag-names': 0,
'jsdoc/no-undefined-types': 0,
'jsdoc/valid-types': 0,

View File

@@ -1,4 +1,3 @@
import { URL } from 'node:url';
import { Events } from 'discord.js';
import { loadCommands } from '../util/loaders.js';

View File

@@ -1,5 +1,4 @@
import process from 'node:process';
import { URL } from 'node:url';
import { Client, GatewayIntentBits } from 'discord.js';
import { loadEvents } from './util/loaders.js';

View File

@@ -1,5 +1,4 @@
import process from 'node:process';
import { URL } from 'node:url';
import { API } from '@discordjs/core/http-only';
import { REST } from 'discord.js';
import { loadCommands } from './loaders.js';

View File

@@ -1,6 +1,6 @@
import { glob, stat } from 'node:fs/promises';
import { basename, resolve } from 'node:path';
import { fileURLToPath, URL } from 'node:url';
import { fileURLToPath } from 'node:url';
import { predicate as commandPredicate } from '../commands/index.js';
import { predicate as eventPredicate } from '../events/index.js';

View File

@@ -18,6 +18,14 @@ const config = [
},
},
rules: {
'no-restricted-globals': 0,
'n/prefer-global/buffer': [2, 'never'],
'n/prefer-global/console': [2, 'always'],
'n/prefer-global/process': [2, 'never'],
'n/prefer-global/text-decoder': [2, 'always'],
'n/prefer-global/text-encoder': [2, 'always'],
'n/prefer-global/url-search-params': [2, 'always'],
'n/prefer-global/url': [2, 'always'],
'import/extensions': 0,
},
},

View File

@@ -1,4 +1,3 @@
import { URL } from 'node:url';
import { Events } from 'discord.js';
import { loadCommands } from '../util/loaders.ts';
import type { Event } from './index.ts';

View File

@@ -1,5 +1,4 @@
import process from 'node:process';
import { URL } from 'node:url';
import { Client, GatewayIntentBits } from 'discord.js';
import { loadEvents } from './util/loaders.ts';

View File

@@ -1,5 +1,4 @@
import process from 'node:process';
import { URL } from 'node:url';
import { API } from '@discordjs/core/http-only';
import { REST } from 'discord.js';
import { loadCommands } from './loaders.ts';

View File

@@ -1,7 +1,7 @@
import type { PathLike } from 'node:fs';
import { glob, stat } from 'node:fs/promises';
import { basename, resolve } from 'node:path';
import { fileURLToPath, URL } from 'node:url';
import { fileURLToPath } from 'node:url';
import { predicate as commandPredicate, type Command } from '../commands/index.ts';
import { predicate as eventPredicate, type Event } from '../events/index.ts';

View File

@@ -1,5 +1,4 @@
import { cp } from 'node:fs/promises';
import { URL } from 'node:url';
const rawIndexDTS = new URL('../typings/index.d.ts', import.meta.url);
const rawIndexMTS = new URL('../typings/index.d.mts', import.meta.url);

View File

@@ -1,5 +1,4 @@
import { readdir, writeFile } from 'node:fs/promises';
import { URL } from 'node:url';
async function writeWebsocketHandlerImports() {
const lines = ["'use strict';\n", 'const PacketHandlers = Object.fromEntries(['];

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env node
/* eslint-disable n/shebang */
import process from 'node:process';
import { createCommand } from 'commander';
import packageFile from '../package.json';

View File

@@ -1,5 +1,4 @@
/* eslint-disable no-template-curly-in-string */
import { URL } from 'node:url';
import { describe, test, expect, vitest } from 'vitest';
import {
applicationDirectory,

View File

@@ -1,4 +1,3 @@
import type { URL } from 'node:url';
import type { Snowflake } from 'discord-api-types/globals';
/**
@@ -687,7 +686,6 @@ export function email<Email extends string>(
*/
export function email<Email extends string>(email: Email, headers?: Record<string, string | readonly string[]>) {
if (headers) {
// eslint-disable-next-line n/prefer-global/url-search-params
const searchParams = new URLSearchParams(
Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value])),
);

View File

@@ -1,4 +1,3 @@
import { URL } from 'node:url';
import type { RequestMethod, REST, RouteLike } from '@discordjs/rest';
import { populateSuccessfulResponse, populateErrorResponse } from '../util/responseHelpers.js';
import type { RequestHandler } from '../util/util.js';

View File

@@ -1,6 +1,5 @@
/* eslint-disable id-length */
/* eslint-disable promise/prefer-await-to-then */
import { performance } from 'node:perf_hooks';
import { MockAgent, setGlobalDispatcher } from 'undici';
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor';
import { beforeEach, afterEach, test, expect } from 'vitest';

View File

@@ -1,4 +1,3 @@
import { URLSearchParams } from 'node:url';
import { test, expect } from 'vitest';
import { DiscordAPIError } from '../src/index.js';

View File

@@ -1,5 +1,4 @@
import { Buffer, File } from 'node:buffer';
import { URLSearchParams } from 'node:url';
import { Buffer } from 'node:buffer';
import { DiscordSnowflake } from '@sapphire/snowflake';
import type { Snowflake } from 'discord-api-types/v10';
import { Routes } from 'discord-api-types/v10';

View File

@@ -1,7 +1,5 @@
/* eslint-disable id-length */
/* eslint-disable promise/prefer-await-to-then */
import { performance } from 'node:perf_hooks';
import { setInterval, clearInterval } from 'node:timers';
import { MockAgent, setGlobalDispatcher } from 'undici';
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor.js';
import { beforeEach, afterEach, test, expect, vitest } from 'vitest';

View File

@@ -1,5 +1,4 @@
import { Blob, Buffer } from 'node:buffer';
import { URLSearchParams } from 'node:url';
import { MockAgent, setGlobalDispatcher, FormData as UndiciFormData } from 'undici';
import type { Interceptable, MockInterceptor } from 'undici/types/mock-interceptor.js';
import { beforeEach, afterEach, test, expect, vitest } from 'vitest';

View File

@@ -1,3 +1,5 @@
/* eslint-disable n/prefer-global/process */
import type { RequestInit } from 'undici';
import type { REST } from '../REST.js';
import type { DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError.js';

View File

@@ -1,3 +1,4 @@
import type { Buffer } from 'node:buffer';
import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';
import type { REST } from '../REST.js';
import { RateLimitError } from '../errors/RateLimitError.js';

View File

@@ -1,5 +1,5 @@
import { Buffer } from 'node:buffer';
import { STATUS_CODES } from 'node:http';
import { URLSearchParams } from 'node:url';
import { types } from 'node:util';
import { type RequestInit, request, Headers, FormData as UndiciFormData, Agent } from 'undici';
import type { HeaderRecord } from 'undici/types/header.js';

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env node
/* eslint-disable n/shebang */
import { readFile } from 'node:fs/promises';
import process from 'node:process';
import { createCommand } from 'commander';
@@ -20,11 +20,8 @@ void generateSplitDocumentation(
opts.all
? {}
: {
fetchPackageVersions: async (_) => {
return ['main'];
},
fetchPackageVersionDocs: async (_, __) => {
return JSON.parse(await readFile(`${process.cwd()}/docs/docs.api.json`, 'utf8'));
},
fetchPackageVersions: async (_) => ['main'],
fetchPackageVersionDocs: async (_, __) =>
JSON.parse(await readFile(`${process.cwd()}/docs/docs.api.json`, 'utf8')),
},
).then(() => console.log('Generated split documentation.'));

View File

@@ -1,6 +1,6 @@
import { stat, mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { cwd } from 'node:process';
import process from 'node:process';
import {
type ApiItem,
ApiPackage,
@@ -151,13 +151,13 @@ export async function writeIndexToFileSystem(
const dir = 'searchIndex';
try {
(await stat(join(cwd(), 'public', dir))).isDirectory();
(await stat(join(process.cwd(), 'public', dir))).isDirectory();
} catch {
await mkdir(join(cwd(), 'public', dir));
await mkdir(join(process.cwd(), 'public', dir));
}
await writeFile(
join(cwd(), 'public', dir, `${packageName}-${tag}-index.json`),
join(process.cwd(), 'public', dir, `${packageName}-${tag}-index.json`),
JSON.stringify(members, undefined, 2),
);
}

View File

@@ -1,6 +1,6 @@
import { mkdir, stat, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { cwd } from 'node:process';
import process from 'node:process';
import {
type ApiClass,
type ApiConstructor,
@@ -1001,14 +1001,14 @@ async function writeSplitDocsToFileSystem({
const dir = 'split';
try {
(await stat(join(cwd(), 'docs', packageName, dir))).isDirectory();
(await stat(join(process.cwd(), 'docs', packageName, dir))).isDirectory();
} catch {
await mkdir(join(cwd(), 'docs', packageName, dir), { recursive: true });
await mkdir(join(process.cwd(), 'docs', packageName, dir), { recursive: true });
}
await writeFile(
join(
cwd(),
process.cwd(),
'docs',
packageName,
dir,

View File

@@ -1,5 +1,5 @@
import { readFile } from 'node:fs/promises';
import process, { cwd } from 'node:process';
import process from 'node:process';
import { create } from '@actions/glob';
import { put } from '@vercel/blob';
import { createPool } from '@vercel/postgres';
@@ -8,7 +8,7 @@ const pool = createPool({
connectionString: process.env.DATABASE_URL,
});
process.chdir(`${cwd()}/../../`);
process.chdir(`${process.cwd()}/../../`);
const globber = await create(`packages/*/docs/*.api.json`);
for await (const file of globber.globGenerator()) {
const parsed = /(?<semver>\d+.\d+.\d+)-?.*/.exec(file);

View File

@@ -1,3 +1,4 @@
import { Buffer } from 'node:buffer';
import { test, expect, vitest } from 'vitest';
import { methods, secretboxLoadPromise } from '../src/util/Secretbox';

View File

@@ -1,5 +1,5 @@
import type { Buffer } from 'node:buffer';
import { nextTick } from 'node:process';
import process from 'node:process';
import { Readable, type ReadableOptions } from 'node:stream';
import { SILENCE_FRAME } from '../audio/AudioPlayer';
@@ -79,7 +79,7 @@ export class AudioReceiveStream extends Readable {
if (buffer === null) {
// null marks EOF for stream
nextTick(() => this.destroy());
process.nextTick(() => this.destroy());
}
return super.push(buffer);

View File

@@ -1,5 +1,4 @@
/* eslint-disable id-length */
import { setImmediate } from 'node:timers';
import type { GatewayDispatchPayload, GatewaySendPayload } from 'discord-api-types/v10';
import { GatewayDispatchEvents, GatewayOpcodes } from 'discord-api-types/v10';
import { test, vi, expect, afterEach } from 'vitest';

View File

@@ -1,9 +1,6 @@
import { Buffer } from 'node:buffer';
import { once } from 'node:events';
import { clearInterval, clearTimeout, setInterval, setTimeout } from 'node:timers';
import { setTimeout as sleep } from 'node:timers/promises';
import { URLSearchParams } from 'node:url';
import { TextDecoder } from 'node:util';
import type * as nativeZlib from 'node:zlib';
import { Collection } from '@discordjs/collection';
import { lazy, shouldUseGlobalFetchAndWebSocket } from '@discordjs/util';