From 0961cb95a9a2191038924d24fdf611a5ee5cfdf1 Mon Sep 17 00:00:00 2001 From: Diogo Ribeiro Date: Tue, 3 Jun 2025 21:46:24 +0100 Subject: [PATCH] Normalize tags during extraction --- src/parser/extractTodos.ts | 4 +++- src/parser/extractTodosFromContent.ts | 4 +++- tests/extractTodosFromContent.test.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/parser/extractTodos.ts b/src/parser/extractTodos.ts index 442b774..9acd06c 100644 --- a/src/parser/extractTodos.ts +++ b/src/parser/extractTodos.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import path from 'path'; import { TodoItem } from './types'; +import { normalizeTag } from '../utils/isTextFile'; const COMMENT_PATTERNS = [ { ext: ['.ts', '.js', '.java', '.go'], pattern: /^\s*\/\/\s*(.*)$/ }, @@ -37,8 +38,9 @@ export function extractTodosFromFile(filePath: string): TodoItem[] { const comment = commentMatch[1]; const tagMatch = comment.match(TAG_REGEX); if (tagMatch) { - const [_, tag, metaRaw, text] = tagMatch; + const [_, rawTag, metaRaw, text] = tagMatch; const metadata = metaRaw ? extractMetadata(metaRaw) : undefined; + const tag = normalizeTag(rawTag) ?? rawTag; todos.push({ file: filePath, line: idx + 1, diff --git a/src/parser/extractTodosFromContent.ts b/src/parser/extractTodosFromContent.ts index 7d6f9fa..f3e7b49 100644 --- a/src/parser/extractTodosFromContent.ts +++ b/src/parser/extractTodosFromContent.ts @@ -1,6 +1,7 @@ // src/parser/extractTodosFromContent.ts import { TodoItem } from './types'; +import { normalizeTag } from '../utils/isTextFile'; const COMMENT_PATTERNS = [ { ext: ['.ts', '.js', '.java', '.go'], pattern: /^\s*\/\/\s*(.*)$/ }, @@ -36,8 +37,9 @@ export function extractTodosFromString(content: string, ext: string): TodoItem[] const comment = commentMatch[1]; const tagMatch = comment.match(TAG_REGEX); if (tagMatch) { - const [_, tag, metaRaw, text] = tagMatch; + const [_, rawTag, metaRaw, text] = tagMatch; const metadata = metaRaw ? extractMetadata(metaRaw) : undefined; + const tag = normalizeTag(rawTag) ?? rawTag; todos.push({ file: `inline${ext}`, line: idx + 1, diff --git a/tests/extractTodosFromContent.test.ts b/tests/extractTodosFromContent.test.ts index 8a802be..0febdf7 100644 --- a/tests/extractTodosFromContent.test.ts +++ b/tests/extractTodosFromContent.test.ts @@ -28,4 +28,13 @@ describe('extractTodosFromString', () => { due: '2025-06-01' }); }); + + it('normalizes localized tags', () => { + const content = `// À FAIRE: tarefa\n# À CORRIGER: problema`; + const jsTodos = extractTodosFromString(content, '.js'); + const pyTodos = extractTodosFromString(content, '.py'); + + expect(jsTodos[0].tag).toBe('TODO'); + expect(pyTodos[0].tag).toBe('FIXME'); + }); });