Skip to content

Commit 828440a

Browse files
committed
feat(parser): ignore common directories
1 parent f92ae17 commit 828440a

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/parser/extractTodosFromDir.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { extractTodosFromFile } from './extractTodos';
44
import { TodoItem } from './types';
55

66
const SUPPORTED_EXTENSIONS = ['.ts', '.js', '.py', '.go', '.java', '.rb', '.sh', '.html', '.xml'];
7+
const IGNORED_DIRS = ['node_modules', 'dist', 'coverage'];
78

89
export function extractTodosFromDir(dirPath: string): TodoItem[] {
910
const todos: TodoItem[] = [];
@@ -15,6 +16,7 @@ export function extractTodosFromDir(dirPath: string): TodoItem[] {
1516
const fullPath = path.join(currentPath, entry.name);
1617

1718
if (entry.isDirectory()) {
19+
if (IGNORED_DIRS.includes(entry.name)) continue;
1820
walk(fullPath);
1921
} else if (entry.isFile()) {
2022
const ext = path.extname(entry.name);

src/parser/extractTodosWithStructuredTagsFromDir.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import path from 'path';
33
import fs from 'fs';
44
import { TodoItem } from './types';
55
import { extractTodosWithStructuredTags } from './extractTodosWithStructuredTags';
6-
import { isTextFile } from '../utils/isTextFile';
6+
import { isTextFile } from '../utils/isTextFile';
7+
8+
const IGNORED_DIRS = ['node_modules', 'dist', 'coverage'];
79

810

911
export function extractTodosWithStructuredTagsFromDir(dir: string): TodoItem[] {
@@ -15,6 +17,7 @@ export function extractTodosWithStructuredTagsFromDir(dir: string): TodoItem[] {
1517
for (const entry of entries) {
1618
const fullPath = path.join(currentPath, entry.name);
1719
if (entry.isDirectory()) {
20+
if (IGNORED_DIRS.includes(entry.name)) continue;
1821
walk(fullPath);
1922
} else if (entry.isFile()) {
2023
try {

tests/extractTodosFromDir.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ describe('extractTodosFromDir', () => {
2525
expect(typeof one?.line).toBe('number');
2626
expect(one?.line).toBeGreaterThan(0);
2727
});
28+
29+
it('should ignore files inside ignored directories', () => {
30+
const todos = extractTodosFromDir(base);
31+
const ignored = todos.find(t => t.text.includes('Should not be picked up'));
32+
expect(ignored).toBeUndefined();
33+
});
2834
});

tests/fixtures/node_modules/ignore.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)