Skip to content

Commit

Permalink
style: restricted use of global as a global variable
Browse files Browse the repository at this point in the history
`globalThis` is the correct name, so introduced an eslint rule to restrict using `global`
  • Loading branch information
emmacasolin committed Aug 8, 2022
1 parent 6e09a00 commit fd87744
Show file tree
Hide file tree
Showing 46 changed files with 123 additions and 116 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"rules": {
"linebreak-style": ["error", "unix"],
"no-empty": 1,
"no-restricted-globals": ["error", "window", "global"],
"no-useless-catch": 1,
"no-prototype-builtins": 1,
"no-constant-condition": 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/GRPCClientAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe(GRPCClientAgent.name, () => {
serverHost: host,
serverPort: port,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await testAgentUtils.closeTestAgentClient(client);
await testAgentUtils.closeTestAgentServer(server);
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesChainDataGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('nodesClosestLocalNode', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesClosestLocalNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('nodesChainDataGet', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesCrossSignClaim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('nodesCrossSignClaim', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/nodesHolePunchMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('nodesHolePunchMessage', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
2 changes: 1 addition & 1 deletion tests/agent/service/notificationsSend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('notificationsSend', () => {
port: grpcServer.getPort(),
logger,
});
}, global.defaultTimeout);
}, globalThis.defaultTimeout);
afterEach(async () => {
await grpcClient.destroy();
await grpcServer.stop();
Expand Down
28 changes: 14 additions & 14 deletions tests/bin/agent/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('start', () => {
let dataDir: string;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
});
afterEach(async () => {
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('start', () => {
const statusInfo = (await status.waitFor('DEAD'))!;
expect(statusInfo.status).toBe('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms()(
'start in background',
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('start', () => {
const statusInfo2 = await status.waitFor('DEAD');
expect(statusInfo2.status).toBe('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'concurrent starts results in 1 success',
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('start', () => {
agentProcess1.kill('SIGQUIT');
}
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'concurrent with bootstrap results in 1 success',
Expand Down Expand Up @@ -388,7 +388,7 @@ describe('start', () => {
agentProcess.kill('SIGTERM');
}
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'start with existing state',
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('start', () => {
const statusInfo = (await status.waitFor('DEAD'))!;
expect(statusInfo.status).toBe('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'start when interrupted, requires fresh on next start',
Expand Down Expand Up @@ -573,7 +573,7 @@ describe('start', () => {
const statusInfo = (await status.readStatus())!;
expect(statusInfo.status).toBe('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'start from recovery code',
Expand Down Expand Up @@ -715,7 +715,7 @@ describe('start', () => {
agentProcess4.kill('SIGTERM');
await execUtils.processExit(agentProcess4);
},
global.defaultTimeout * 3,
globalThis.defaultTimeout * 3,
);
runTestIfPlatforms('docker')(
'start with network configuration',
Expand Down Expand Up @@ -770,7 +770,7 @@ describe('start', () => {
// Check for graceful exit
await status.waitFor('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'start with PK_ROOT_KEY env override',
Expand Down Expand Up @@ -810,7 +810,7 @@ describe('start', () => {
// Check for graceful exit
await status.waitFor('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'start with --root-key-file override',
Expand Down Expand Up @@ -861,7 +861,7 @@ describe('start', () => {
// Check for graceful exit
await status.waitFor('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runDescribeIfPlatforms()('start with global agent', () => {
let agentDataDir;
Expand All @@ -878,7 +878,7 @@ describe('start', () => {
beforeEach(async () => {
// Additional seed node
agentDataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
({ agentStatus: agent1Status, agentClose: agent1Close } =
await execUtils.setupTestAgent(globalRootKeyPems[0], logger));
Expand Down Expand Up @@ -962,7 +962,7 @@ describe('start', () => {
mockedConfigDefaultsNetwork.mockRestore();
await status.waitFor('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
test(
'start with seed nodes environment variable',
Expand Down Expand Up @@ -1025,7 +1025,7 @@ describe('start', () => {
mockedConfigDefaultsNetwork.mockRestore();
await status.waitFor('DEAD');
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
});
});
4 changes: 2 additions & 2 deletions tests/bin/agent/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('status', () => {
let dataDir: string;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
});
afterEach(async () => {
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('status', () => {
status: 'DEAD',
});
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')('status on missing agent', async () => {
const { exitCode, stdout } = await execUtils.pkExec(
Expand Down
10 changes: 5 additions & 5 deletions tests/bin/agent/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('stop', () => {
let dataDir: string;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.testDir, 'polykey-test-'),
path.join(globalThis.testDir, 'polykey-test-'),
);
});
afterEach(async () => {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('stop', () => {
await sleep(5000);
agentProcess.kill();
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'stopping is idempotent during concurrent calls and STOPPING or DEAD status',
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('stop', () => {
expect(agentStop4.exitCode).toBe(0);
agentProcess.kill();
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms()(
'stopping starting agent results in error',
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('stop', () => {
await status.waitFor('DEAD');
agentProcess.kill();
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'stopping while unauthenticated does not stop',
Expand Down Expand Up @@ -290,6 +290,6 @@ describe('stop', () => {
await status.waitFor('DEAD');
agentProcess.kill();
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
});
12 changes: 6 additions & 6 deletions tests/bin/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('bootstrap', () => {
let dataDir: string;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
});
afterEach(async () => {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('bootstrap', () => {
recoveryCode.split(' ').length === 24,
).toBe(true);
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'bootstraps node state from provided private key',
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('bootstrap', () => {
);
expect(exitCode2).toBe(0);
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'bootstrapping occupied node state',
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('bootstrap', () => {
recoveryCode.split(' ').length === 24,
).toBe(true);
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'concurrent bootstrapping results in 1 success',
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('bootstrap', () => {
expect(exitCode2).toBe(0);
}
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms('docker')(
'bootstrap when interrupted, requires fresh on next bootstrap',
Expand Down Expand Up @@ -314,6 +314,6 @@ describe('bootstrap', () => {
recoveryCode.split(' ').length === 24,
).toBe(true);
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
});
2 changes: 1 addition & 1 deletion tests/bin/identities/allowDisallowPermissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('allow/disallow/permissions', () => {
let nodePort: Port;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
nodePath = path.join(dataDir, 'polykey');
pkAgent = await PolykeyAgent.createPolykeyAgent({
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/identities/authenticateAuthenticated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('authenticate/authenticated', () => {
let testProvider: TestProvider;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
nodePath = path.join(dataDir, 'polykey');
// Cannot use global shared agent since we need to register a provider
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/identities/claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('claim', () => {
let testProvider: TestProvider;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
nodePath = path.join(dataDir, 'polykey');
// Cannot use global shared agent since we need to register a provider
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/identities/discoverGet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('discover/get', () => {
let nodeAPort: Port;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
// Setup the remote gestalt state here
// Setting up remote nodes
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/identities/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('search', () => {
let pkAgent: PolykeyAgent;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
nodePath = path.join(dataDir, 'polykey');
// Cannot use global shared agent since we need to register a provider
Expand Down
6 changes: 3 additions & 3 deletions tests/bin/identities/trustUntrustList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('trust/untrust/list', () => {
let nodePort: Port;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
nodePath = path.join(dataDir, 'polykey');
pkAgent = await PolykeyAgent.createPolykeyAgent({
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('trust/untrust/list', () => {
// @ts-ignore - get protected property
pkAgent.discovery.visitedVertices.clear();
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms()(
'trusts and untrusts a gestalt by identity, adds it to the gestalt graph, and lists the gestalt with notify permission',
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('trust/untrust/list', () => {
// @ts-ignore - get protected property
pkAgent.discovery.visitedVertices.clear();
},
global.defaultTimeout * 2,
globalThis.defaultTimeout * 2,
);
runTestIfPlatforms()('should fail on invalid inputs', async () => {
let exitCode;
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/keys/renew.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('renew', () => {
.mockResolvedValueOnce(globalKeyPair)
.mockResolvedValue(newKeyPair);
dataDir = await fs.promises.mkdtemp(
path.join(global.tmpDir, 'polykey-test-'),
path.join(globalThis.tmpDir, 'polykey-test-'),
);
nodePath = path.join(dataDir, 'polykey');
pkAgent = await PolykeyAgent.createPolykeyAgent({
Expand All @@ -42,7 +42,7 @@ describe('renew', () => {
},
logger,
});
}, global.defaultTimeout * 2);
}, globalThis.defaultTimeout * 2);
afterAll(async () => {
await pkAgent.stop();
await fs.promises.rm(dataDir, {
Expand Down
Loading

0 comments on commit fd87744

Please sign in to comment.