From 51f252541dabbcbb56c715043d214c31b4da86a9 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 4 Nov 2024 17:47:42 -0800 Subject: [PATCH] Fix processing of .editorConfig files with booleans. --- Extension/src/LanguageServer/editorConfig.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Extension/src/LanguageServer/editorConfig.ts b/Extension/src/LanguageServer/editorConfig.ts index 1ac8452b4..e4a72d4a9 100644 --- a/Extension/src/LanguageServer/editorConfig.ts +++ b/Extension/src/LanguageServer/editorConfig.ts @@ -92,12 +92,18 @@ function parseEditorConfigContent(content: string): Record { const [key, ...values] = line.split('='); if (key && values.length > 0) { const trimmedKey = key.trim(); - const value = values.join('=').trim(); + let value: any = values.join('=').trim(); if (currentSection) { // Ensure the current section is initialized. if (!config[currentSection]) { config[currentSection] = {}; } + // Convert 'true' and 'false' to boolean. + if (value === 'true') { + value = true; + } else if (value === 'false') { + value = false; + } config[currentSection][trimmedKey] = value; } } @@ -114,7 +120,7 @@ function getEditorConfig(filePath: string): any { const rootDir: string = path.parse(currentDir).root; // Traverse from the file's directory to the root directory. - for (;;) { + for (; ;) { const editorConfigPath: string = path.join(currentDir, '.editorconfig'); if (fs.existsSync(editorConfigPath)) { const configFileContent: string = fs.readFileSync(editorConfigPath, 'utf-8'); @@ -139,7 +145,7 @@ function getEditorConfig(filePath: string): any { }); // Check if the current .editorconfig is the root. - if (configData['*']?.root?.toLowerCase() === 'true') { + if (configData['*']?.root === true) { break; // Stop searching after processing the root = true file. } }