Skip to content

Commit 33e25cb

Browse files
Merge pull request #167 from DiogoRibeiro7/codex/atualizar-funções-para-chamar-normalizetag
Normalize tags in parser
2 parents 7d81b29 + 0961cb9 commit 33e25cb

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/parser/extractTodos.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { TodoItem } from './types';
4+
import { normalizeTag } from '../utils/isTextFile';
45

56
const COMMENT_PATTERNS = [
67
{ ext: ['.ts', '.js', '.java', '.go'], pattern: /^\s*\/\/\s*(.*)$/ },
@@ -37,8 +38,9 @@ export function extractTodosFromFile(filePath: string): TodoItem[] {
3738
const comment = commentMatch[1];
3839
const tagMatch = comment.match(TAG_REGEX);
3940
if (tagMatch) {
40-
const [_, tag, metaRaw, text] = tagMatch;
41+
const [_, rawTag, metaRaw, text] = tagMatch;
4142
const metadata = metaRaw ? extractMetadata(metaRaw) : undefined;
43+
const tag = normalizeTag(rawTag) ?? rawTag;
4244
todos.push({
4345
file: filePath,
4446
line: idx + 1,

src/parser/extractTodosFromContent.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// src/parser/extractTodosFromContent.ts
22

33
import { TodoItem } from './types';
4+
import { normalizeTag } from '../utils/isTextFile';
45

56
const COMMENT_PATTERNS = [
67
{ ext: ['.ts', '.js', '.java', '.go'], pattern: /^\s*\/\/\s*(.*)$/ },
@@ -36,8 +37,9 @@ export function extractTodosFromString(content: string, ext: string): TodoItem[]
3637
const comment = commentMatch[1];
3738
const tagMatch = comment.match(TAG_REGEX);
3839
if (tagMatch) {
39-
const [_, tag, metaRaw, text] = tagMatch;
40+
const [_, rawTag, metaRaw, text] = tagMatch;
4041
const metadata = metaRaw ? extractMetadata(metaRaw) : undefined;
42+
const tag = normalizeTag(rawTag) ?? rawTag;
4143
todos.push({
4244
file: `inline${ext}`,
4345
line: idx + 1,

tests/extractTodosFromContent.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@ describe('extractTodosFromString', () => {
2828
due: '2025-06-01'
2929
});
3030
});
31+
32+
it('normalizes localized tags', () => {
33+
const content = `// À FAIRE: tarefa\n# À CORRIGER: problema`;
34+
const jsTodos = extractTodosFromString(content, '.js');
35+
const pyTodos = extractTodosFromString(content, '.py');
36+
37+
expect(jsTodos[0].tag).toBe('TODO');
38+
expect(pyTodos[0].tag).toBe('FIXME');
39+
});
3140
});

0 commit comments

Comments
 (0)