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 9, 2022
1 parent 14c862a commit fb66f39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
{
"name": "global",
"message": "Use `globalThis` instead"
},
{
"name": "window"
}
],
"require-yield": 0,
Expand Down
18 changes: 11 additions & 7 deletions tests/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type ExecOpts = {
};

const tsConfigPath = path.resolve(
path.join(global.projectDir, 'tsconfig.json'),
path.join(globalThis.projectDir, 'tsconfig.json'),
);

const polykeyPath = path.resolve(
path.join(global.projectDir, 'src/bin/polykey.ts'),
path.join(globalThis.projectDir, 'src/bin/polykey.ts'),
);

const generateDockerArgs = (mountPath: string) => [
Expand Down Expand Up @@ -114,7 +114,7 @@ async function pkStdio(
}> {
const cwd =
opts.cwd ??
(await fs.promises.mkdtemp(path.join(global.tmpDir, 'polykey-test-')));
(await fs.promises.mkdtemp(path.join(globalThis.tmpDir, 'polykey-test-')));
// Recall that we attempt to connect to all specified seed nodes on agent start.
// Therefore, for testing purposes only, we default the seed nodes as empty
// (if not defined in the env) to ensure no attempted connections. A regular
Expand Down Expand Up @@ -241,7 +241,7 @@ async function pkExecWithoutShell(
}> {
const cwd =
opts.cwd ??
(await fs.promises.mkdtemp(path.join(global.tmpDir, 'polykey-test-')));
(await fs.promises.mkdtemp(path.join(globalThis.tmpDir, 'polykey-test-')));
const env = {
...process.env,
...opts.env,
Expand Down Expand Up @@ -293,7 +293,9 @@ async function pkExecWithShell(
}> {
const cwd = path.resolve(
opts.cwd ??
(await fs.promises.mkdtemp(path.join(global.tmpDir, 'polykey-test-'))),
(await fs.promises.mkdtemp(
path.join(globalThis.tmpDir, 'polykey-test-'),
)),
);
const env = {
...process.env,
Expand Down Expand Up @@ -343,7 +345,7 @@ async function pkSpawnWithoutShell(
): Promise<ChildProcess> {
const cwd =
opts.cwd ??
(await fs.promises.mkdtemp(path.join(global.tmpDir, 'polykey-test-')));
(await fs.promises.mkdtemp(path.join(globalThis.tmpDir, 'polykey-test-')));
const env = {
...process.env,
...opts.env,
Expand Down Expand Up @@ -383,7 +385,9 @@ async function pkSpawnWithShell(
): Promise<ChildProcess> {
const cwd = path.resolve(
opts.cwd ??
(await fs.promises.mkdtemp(path.join(global.tmpDir, 'polykey-test-'))),
(await fs.promises.mkdtemp(
path.join(globalThis.tmpDir, 'polykey-test-'),
)),
);
const env = {
...process.env,
Expand Down

0 comments on commit fb66f39

Please sign in to comment.