Skip to content

Commit

Permalink
chore(eslint): fix cwd check for eslint@<6.6.0 (vercel#2848)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Knickman <tom.knickman@vercel.com>
  • Loading branch information
2 people authored and elitan committed Dec 6, 2022
1 parent a5fcea0 commit 480f98b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion packages/eslint-plugin-turbo/lib/rules/no-undeclared-env-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ const meta: Rule.RuleMetaData = {
],
};

/**
* Normalize the value of the cwd
* Extracted from eslint
* SPDX-License-Identifier: MIT
*/
function normalizeCwd(cwd: string | undefined): string | undefined {
if (cwd) {
return cwd;
}
if (typeof process === "object") {
return process.cwd();
}

return undefined;
}

function create(context: Rule.RuleContext): Rule.RuleListener {
const { options } = context;
const allowList: Array<string> = options?.[0]?.allowList || [];
Expand All @@ -46,9 +62,11 @@ function create(context: Rule.RuleContext): Rule.RuleListener {
console.error(`Unable to convert "${allowed}" to regex`);
}
});

const cwd = normalizeCwd(context.getCwd ? context.getCwd() : undefined);
const turboConfig = options?.[0]?.turboConfig;
const turboVars = getEnvVarDependencies({
cwd: context.getCwd(),
cwd,
turboConfig,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getEnvVarDependencies({
cwd,
turboConfig,
}: {
cwd: string;
cwd: string | undefined;
turboConfig?: Schema;
}): Set<string> | null {
const turboJsonContent = turboConfig || findTurboConfig({ cwd });
Expand Down

0 comments on commit 480f98b

Please sign in to comment.