Skip to content

Commit fd87744

Browse files
committed
style: restricted use of global as a global variable
`globalThis` is the correct name, so introduced an eslint rule to restrict using `global`
1 parent 6e09a00 commit fd87744

46 files changed

Lines changed: 123 additions & 116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"rules": {
2424
"linebreak-style": ["error", "unix"],
2525
"no-empty": 1,
26+
"no-restricted-globals": ["error", "window", "global"],
2627
"no-useless-catch": 1,
2728
"no-prototype-builtins": 1,
2829
"no-constant-condition": 0,

tests/agent/GRPCClientAgent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe(GRPCClientAgent.name, () => {
169169
serverHost: host,
170170
serverPort: port,
171171
});
172-
}, global.defaultTimeout);
172+
}, globalThis.defaultTimeout);
173173
afterEach(async () => {
174174
await testAgentUtils.closeTestAgentClient(client);
175175
await testAgentUtils.closeTestAgentServer(server);

tests/agent/service/nodesChainDataGet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('nodesClosestLocalNode', () => {
6161
port: grpcServer.getPort(),
6262
logger,
6363
});
64-
}, global.defaultTimeout);
64+
}, globalThis.defaultTimeout);
6565
afterEach(async () => {
6666
await grpcClient.destroy();
6767
await grpcServer.stop();

tests/agent/service/nodesClosestLocalNode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('nodesChainDataGet', () => {
6161
port: grpcServer.getPort(),
6262
logger,
6363
});
64-
}, global.defaultTimeout);
64+
}, globalThis.defaultTimeout);
6565
afterEach(async () => {
6666
await grpcClient.destroy();
6767
await grpcServer.stop();

tests/agent/service/nodesCrossSignClaim.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('nodesCrossSignClaim', () => {
8484
port: grpcServer.getPort(),
8585
logger,
8686
});
87-
}, global.defaultTimeout);
87+
}, globalThis.defaultTimeout);
8888
afterEach(async () => {
8989
await grpcClient.destroy();
9090
await grpcServer.stop();

tests/agent/service/nodesHolePunchMessage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('nodesHolePunchMessage', () => {
6161
port: grpcServer.getPort(),
6262
logger,
6363
});
64-
}, global.defaultTimeout);
64+
}, globalThis.defaultTimeout);
6565
afterEach(async () => {
6666
await grpcClient.destroy();
6767
await grpcServer.stop();

tests/agent/service/notificationsSend.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('notificationsSend', () => {
156156
port: grpcServer.getPort(),
157157
logger,
158158
});
159-
}, global.defaultTimeout);
159+
}, globalThis.defaultTimeout);
160160
afterEach(async () => {
161161
await grpcClient.destroy();
162162
await grpcServer.stop();

tests/bin/agent/start.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('start', () => {
2121
let dataDir: string;
2222
beforeEach(async () => {
2323
dataDir = await fs.promises.mkdtemp(
24-
path.join(global.tmpDir, 'polykey-test-'),
24+
path.join(globalThis.tmpDir, 'polykey-test-'),
2525
);
2626
});
2727
afterEach(async () => {
@@ -99,7 +99,7 @@ describe('start', () => {
9999
const statusInfo = (await status.waitFor('DEAD'))!;
100100
expect(statusInfo.status).toBe('DEAD');
101101
},
102-
global.defaultTimeout * 2,
102+
globalThis.defaultTimeout * 2,
103103
);
104104
runTestIfPlatforms()(
105105
'start in background',
@@ -202,7 +202,7 @@ describe('start', () => {
202202
const statusInfo2 = await status.waitFor('DEAD');
203203
expect(statusInfo2.status).toBe('DEAD');
204204
},
205-
global.defaultTimeout * 2,
205+
globalThis.defaultTimeout * 2,
206206
);
207207
runTestIfPlatforms('docker')(
208208
'concurrent starts results in 1 success',
@@ -298,7 +298,7 @@ describe('start', () => {
298298
agentProcess1.kill('SIGQUIT');
299299
}
300300
},
301-
global.defaultTimeout * 2,
301+
globalThis.defaultTimeout * 2,
302302
);
303303
runTestIfPlatforms('docker')(
304304
'concurrent with bootstrap results in 1 success',
@@ -388,7 +388,7 @@ describe('start', () => {
388388
agentProcess.kill('SIGTERM');
389389
}
390390
},
391-
global.defaultTimeout * 2,
391+
globalThis.defaultTimeout * 2,
392392
);
393393
runTestIfPlatforms('docker')(
394394
'start with existing state',
@@ -462,7 +462,7 @@ describe('start', () => {
462462
const statusInfo = (await status.waitFor('DEAD'))!;
463463
expect(statusInfo.status).toBe('DEAD');
464464
},
465-
global.defaultTimeout * 2,
465+
globalThis.defaultTimeout * 2,
466466
);
467467
runTestIfPlatforms('docker')(
468468
'start when interrupted, requires fresh on next start',
@@ -573,7 +573,7 @@ describe('start', () => {
573573
const statusInfo = (await status.readStatus())!;
574574
expect(statusInfo.status).toBe('DEAD');
575575
},
576-
global.defaultTimeout * 2,
576+
globalThis.defaultTimeout * 2,
577577
);
578578
runTestIfPlatforms('docker')(
579579
'start from recovery code',
@@ -715,7 +715,7 @@ describe('start', () => {
715715
agentProcess4.kill('SIGTERM');
716716
await execUtils.processExit(agentProcess4);
717717
},
718-
global.defaultTimeout * 3,
718+
globalThis.defaultTimeout * 3,
719719
);
720720
runTestIfPlatforms('docker')(
721721
'start with network configuration',
@@ -770,7 +770,7 @@ describe('start', () => {
770770
// Check for graceful exit
771771
await status.waitFor('DEAD');
772772
},
773-
global.defaultTimeout * 2,
773+
globalThis.defaultTimeout * 2,
774774
);
775775
runTestIfPlatforms('docker')(
776776
'start with PK_ROOT_KEY env override',
@@ -810,7 +810,7 @@ describe('start', () => {
810810
// Check for graceful exit
811811
await status.waitFor('DEAD');
812812
},
813-
global.defaultTimeout * 2,
813+
globalThis.defaultTimeout * 2,
814814
);
815815
runTestIfPlatforms('docker')(
816816
'start with --root-key-file override',
@@ -861,7 +861,7 @@ describe('start', () => {
861861
// Check for graceful exit
862862
await status.waitFor('DEAD');
863863
},
864-
global.defaultTimeout * 2,
864+
globalThis.defaultTimeout * 2,
865865
);
866866
runDescribeIfPlatforms()('start with global agent', () => {
867867
let agentDataDir;
@@ -878,7 +878,7 @@ describe('start', () => {
878878
beforeEach(async () => {
879879
// Additional seed node
880880
agentDataDir = await fs.promises.mkdtemp(
881-
path.join(global.tmpDir, 'polykey-test-'),
881+
path.join(globalThis.tmpDir, 'polykey-test-'),
882882
);
883883
({ agentStatus: agent1Status, agentClose: agent1Close } =
884884
await execUtils.setupTestAgent(globalRootKeyPems[0], logger));
@@ -962,7 +962,7 @@ describe('start', () => {
962962
mockedConfigDefaultsNetwork.mockRestore();
963963
await status.waitFor('DEAD');
964964
},
965-
global.defaultTimeout * 2,
965+
globalThis.defaultTimeout * 2,
966966
);
967967
test(
968968
'start with seed nodes environment variable',
@@ -1025,7 +1025,7 @@ describe('start', () => {
10251025
mockedConfigDefaultsNetwork.mockRestore();
10261026
await status.waitFor('DEAD');
10271027
},
1028-
global.defaultTimeout * 2,
1028+
globalThis.defaultTimeout * 2,
10291029
);
10301030
});
10311031
});

tests/bin/agent/status.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('status', () => {
1515
let dataDir: string;
1616
beforeEach(async () => {
1717
dataDir = await fs.promises.mkdtemp(
18-
path.join(global.tmpDir, 'polykey-test-'),
18+
path.join(globalThis.tmpDir, 'polykey-test-'),
1919
);
2020
});
2121
afterEach(async () => {
@@ -116,7 +116,7 @@ describe('status', () => {
116116
status: 'DEAD',
117117
});
118118
},
119-
global.defaultTimeout * 2,
119+
globalThis.defaultTimeout * 2,
120120
);
121121
runTestIfPlatforms('docker')('status on missing agent', async () => {
122122
const { exitCode, stdout } = await execUtils.pkExec(

tests/bin/agent/stop.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('stop', () => {
1515
let dataDir: string;
1616
beforeEach(async () => {
1717
dataDir = await fs.promises.mkdtemp(
18-
path.join(global.testDir, 'polykey-test-'),
18+
path.join(globalThis.testDir, 'polykey-test-'),
1919
);
2020
});
2121
afterEach(async () => {
@@ -71,7 +71,7 @@ describe('stop', () => {
7171
await sleep(5000);
7272
agentProcess.kill();
7373
},
74-
global.defaultTimeout * 2,
74+
globalThis.defaultTimeout * 2,
7575
);
7676
runTestIfPlatforms('docker')(
7777
'stopping is idempotent during concurrent calls and STOPPING or DEAD status',
@@ -163,7 +163,7 @@ describe('stop', () => {
163163
expect(agentStop4.exitCode).toBe(0);
164164
agentProcess.kill();
165165
},
166-
global.defaultTimeout * 2,
166+
globalThis.defaultTimeout * 2,
167167
);
168168
runTestIfPlatforms()(
169169
'stopping starting agent results in error',
@@ -227,7 +227,7 @@ describe('stop', () => {
227227
await status.waitFor('DEAD');
228228
agentProcess.kill();
229229
},
230-
global.defaultTimeout * 2,
230+
globalThis.defaultTimeout * 2,
231231
);
232232
runTestIfPlatforms('docker')(
233233
'stopping while unauthenticated does not stop',
@@ -290,6 +290,6 @@ describe('stop', () => {
290290
await status.waitFor('DEAD');
291291
agentProcess.kill();
292292
},
293-
global.defaultTimeout * 2,
293+
globalThis.defaultTimeout * 2,
294294
);
295295
});

0 commit comments

Comments
 (0)