Skip to content

Commit

Permalink
Fix processing of bools and numbers in editorConfig files (#12923)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms authored Nov 5, 2024
1 parent fcd0b0c commit 390046c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Extension/src/LanguageServer/editorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ function parseEditorConfigContent(content: string): Record<string, any> {
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();

// Convert boolean-like and numeric values.
if (value.toLowerCase() === 'true') {
value = true;
} else if (value.toLowerCase() === 'false') {
value = false;
} else if (!isNaN(Number(value))) {
value = Number(value);
}

if (currentSection) {
// Ensure the current section is initialized.
if (!config[currentSection]) {
Expand All @@ -114,7 +124,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');
Expand All @@ -139,7 +149,7 @@ function getEditorConfig(filePath: string): any {
});

// Check if the current .editorconfig is the root.
if (configData['*']?.root?.toLowerCase() === 'true') {
if (configData['*']?.root) {
break; // Stop searching after processing the root = true file.
}
}
Expand Down

0 comments on commit 390046c

Please sign in to comment.