Skip to content

Commit 64f50b5

Browse files
CopilotyCodeTech
andcommitted
refactor: extract validation into separate function following DOT principle
Co-authored-by: yCodeTech <31927084+yCodeTech@users.noreply.github.com>
1 parent 93d64a4 commit 64f50b5

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/extensionData.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export class ExtensionData {
9595
*/
9696
private setExtensionDiscoveryPaths() {
9797
// Get the DEV_USER_EXTENSIONS_PATH env variable if it exists.
98-
// This variable is validated and sanitized by addDevEnvVariables() in utils.ts
9998
const devUserExtensionsPath = process.env.DEV_USER_EXTENSIONS_PATH;
10099

101100
// The path to the user extensions.

src/utils.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,10 @@ export function mergeArraysBy<T>(primaryArray: T[], secondaryArray: T[], key: ke
240240
}
241241

242242
/**
243-
* Add development environment variables from a local .env file located in the project root.
244-
* Validates and sanitizes specific environment variables after loading.
243+
* Validate and sanitize the DEV_USER_EXTENSIONS_PATH environment variable.
244+
* Removes invalid paths from the environment with logged errors.
245245
*/
246-
export function addDevEnvVariables() {
247-
// Try to load the local .env file from the project root.
248-
try {
249-
process.loadEnvFile(path.join(__dirname, "../../.env"));
250-
} catch (error) {
251-
// Ignore errors if the .env file doesn't exist
252-
}
253-
246+
function validateDevEnvVariables() {
254247
// Validate DEV_USER_EXTENSIONS_PATH if it was loaded
255248
if (process.env.DEV_USER_EXTENSIONS_PATH) {
256249
let devPath = process.env.DEV_USER_EXTENSIONS_PATH;
@@ -287,3 +280,18 @@ export function addDevEnvVariables() {
287280
}
288281
}
289282
}
283+
284+
/**
285+
* Add development environment variables from a local .env file located in the project root.
286+
*/
287+
export function addDevEnvVariables() {
288+
// Try to load the local .env file from the project root.
289+
try {
290+
process.loadEnvFile(path.join(__dirname, "../../.env"));
291+
} catch (error) {
292+
// Ignore errors if the .env file doesn't exist
293+
}
294+
295+
// Validate the loaded environment variables
296+
validateDevEnvVariables();
297+
}

0 commit comments

Comments
 (0)