todo-tree 0.1.0

A CLI tool to find and display TODO-style comments in your codebase
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# Todo Tree

A command-line tool to find and display TODO-style comments in your codebase, similar to the VS Code "Todo Tree" extension.

## Features

- 🔍 **Recursive directory scanning** - Respects `.gitignore` rules automatically
- 🏷️ **Configurable tags** - TODO, FIXME, BUG, NOTE, HACK, XXX, WARN, PERF (and custom tags)
- 🌳 **Tree view output** - Beautiful hierarchical display grouped by file
- 📋 **Multiple output formats** - Tree, flat list, and JSON
- ⚙️ **Configuration file support** - `.todorc` in JSON or YAML format
- 🎨 **Colored output** - Priority-based coloring for different tag types
- 🔗 **Clickable links** - Terminal hyperlinks to file locations (where supported)

## Installation

### Using Cargo (Recommended)

```bash
cargo install todo-tree
```

### From Source

```bash
# Clone the repository
git clone https://github.com/alexandretrotel/todo-tree.git
cd todo-tree

# Build and install
cargo install --path .
```

## Usage

The tool provides two binary names: `todo-tree` and `tt` (alias for quick access).

### Basic Commands

```bash
# Scan current directory (default command)
tt

# Scan a specific directory
tt scan ./src

# Scan with specific tags
tt scan --tags TODO,FIXME,BUG

# List all TODOs in flat format
tt list

# Show configured tags
tt tags

# Show statistics
tt stats
```

### Command Reference

#### `scan` (default)

Scan directories for TODO-style comments and display in tree format.

```bash
tt scan [PATH] [OPTIONS]

Options:
  -t, --tags <TAGS>        Tags to search for (comma-separated)
  -i, --include <PATTERN>  File patterns to include (glob)
  -e, --exclude <PATTERN>  File patterns to exclude (glob)
  -d, --depth <N>          Maximum depth to scan (0 = unlimited)
      --json               Output in JSON format
      --flat               Output in flat format (no tree)
      --group-by-tag       Group results by tag instead of by file
      --hidden             Include hidden files
      --follow-links       Follow symbolic links
      --case-sensitive     Case-sensitive tag matching
      --sort <ORDER>       Sort by: file, tag, line, priority
```

#### `list`

List all TODO items in a flat format.

```bash
tt list [PATH] [OPTIONS]

Options:
  -t, --tags <TAGS>        Tags to search for
  -i, --include <PATTERN>  File patterns to include
  -e, --exclude <PATTERN>  File patterns to exclude
      --filter <TAG>       Filter by specific tag
      --json               Output in JSON format
```

#### `tags`

Show or manage configured tags.

```bash
tt tags [OPTIONS]

Options:
      --json               Output in JSON format
      --add <TAG>          Add a new tag
      --remove <TAG>       Remove a tag
      --reset              Reset to default tags
```

#### `init`

Create a new configuration file.

```bash
tt init [OPTIONS]

Options:
      --format <FORMAT>    Config format: json or yaml [default: json]
  -f, --force              Overwrite existing config file
```

#### `stats`

Show statistics about TODOs in the codebase.

```bash
tt stats [PATH] [OPTIONS]

Options:
  -t, --tags <TAGS>        Tags to search for
      --json               Output in JSON format
```

### Global Options

These options apply to all commands:

```bash
      --no-color           Disable colored output
  -v, --verbose            Enable verbose output
      --config <FILE>      Path to custom config file
```

## Configuration

Create a `.todorc.json` or `.todorc.yaml` file in your project root:

### JSON Format (`.todorc.json`)

```json
{
  "tags": ["TODO", "FIXME", "BUG", "NOTE", "HACK", "XXX", "WARN", "PERF"],
  "include": ["*.rs", "*.py", "*.js", "*.ts"],
  "exclude": ["target/**", "node_modules/**", "dist/**"],
  "json": false,
  "flat": false,
  "no_color": false,
  "case_sensitive": false
}
```

### YAML Format (`.todorc.yaml`)

```yaml
tags:
  - TODO
  - FIXME
  - BUG
  - NOTE
  - HACK

include:
  - "*.rs"
  - "*.py"

exclude:
  - "target/**"
  - "node_modules/**"

json: false
flat: false
no_color: false
```

### Configuration Search Order

1. `.todorc` in the current directory
2. `.todorc.json` in the current directory
3. `.todorc.yaml` or `.todorc.yml` in the current directory
4. Parent directories (recursive)
5. `~/.config/todo-tree/config.json` (global config)

## Examples

### Example 1: Basic Scan

```bash
$ tt scan ./src

├── src/main.rs (2)
│   ├── [L10] TODO: Implement error handling
│   └── [L25] FIXME: This needs refactoring
├── src/lib.rs (3)
│   ├── [L5] NOTE: Public API
│   ├── [L42] TODO(alice): Add documentation
│   └── [L78] BUG: Memory leak in this function
└── src/utils.rs (1)
    └── [L15] HACK: Temporary workaround

Found 6 TODO items in 3 files (15 files scanned)
  TODO: 2, FIXME: 1, NOTE: 1, BUG: 1, HACK: 1
```

### Example 2: Group by Tag

```bash
$ tt scan --group-by-tag ./src

├── BUG (1)
│   └── src/lib.rs:78 - Memory leak in this function
├── FIXME (1)
│   └── src/main.rs:25 - This needs refactoring
├── HACK (1)
│   └── src/utils.rs:15 - Temporary workaround
├── NOTE (1)
│   └── src/lib.rs:5 - Public API
└── TODO (2)
    ├── src/main.rs:10 - Implement error handling
    └── src/lib.rs:42 - Add documentation

Found 6 TODO items in 3 files (15 files scanned)
  TODO: 2, FIXME: 1, NOTE: 1, BUG: 1, HACK: 1
```

### Example 3: JSON Output

```bash
$ tt scan --json

{
  "files": [
    {
      "path": "src/main.rs",
      "items": [
        {
          "tag": "TODO",
          "message": "Implement error handling",
          "line": 10,
          "column": 5,
          "priority": "Medium"
        }
      ]
    }
  ],
  "summary": {
    "total_count": 6,
    "files_with_todos": 3,
    "files_scanned": 15,
    "tag_counts": {
      "TODO": 2,
      "FIXME": 1,
      "NOTE": 1,
      "BUG": 1,
      "HACK": 1
    }
  }
}
```

### Example 4: Filter by Tag

```bash
$ tt list --filter BUG

src/lib.rs:78:5 [BUG] Memory leak in this function
src/database.rs:142:3 [BUG] Connection not closed properly

Found 2 TODO items in 2 files (15 files scanned)
  BUG: 2
```

### Example 5: Include/Exclude Patterns

```bash
# Only scan Rust files
tt scan --include "*.rs"

# Exclude test files
tt scan --exclude "*_test.rs,tests/**"

# Combine patterns
tt scan --include "*.rs,*.py" --exclude "target/**,__pycache__/**"
```

### Example 6: Statistics

```bash
$ tt stats

TODO Statistics

  Total items:        42
  Files with TODOs:   12
  Files scanned:      156
  Avg items per file: 3.50

By Tag:
  TODO       18 ( 42.9%) ████████░░░░░░░░░░░░
  FIXME      10 ( 23.8%) █
████░░░░░░░░░░░░░░░
  BUG         6 ( 14.3%) ███░░░░░░░░░░░░░░░░░
  NOTE        5 ( 11.9%) ██░░░░░░░░░░░░░░░░░░
  HACK        3 (  7.1%) █░░░░░░░░░░░░░░░░░░░
```

## Supported Comment Styles

The tool recognizes TODO-style tags in various comment formats:

| Language | Comment Styles |
|----------|---------------|
| C, C++, Rust, Go, Java, JavaScript, TypeScript | `//`, `/* */` |
| Python, Ruby, Shell, YAML | `#` |
| HTML, XML | `<!-- -->` |
| SQL | `--`, `/* */` |
| Lisp, Clojure | `;` |
| Lua | `--` |

### Tag Formats Recognized

```rust
// TODO: Simple tag with colon
// TODO Simple tag without colon
// TODO(author): Tag with author
// todo: Case insensitive (by default)
```

## Priority Levels

Tags are assigned priority levels for sorting and coloring:

| Priority | Tags | Color |
|----------|------|-------|
| Critical | BUG, FIXME, XXX | Red |
| High | HACK, WARN, WARNING | Yellow |
| Medium | TODO, PERF | Cyan |
| Low | NOTE, INFO, IDEA | Green |

## Terminal Support

### Clickable Links

The tool generates clickable hyperlinks (OSC 8) in supported terminals:

- iTerm2
- WezTerm
- Hyper
- VS Code Terminal
- GNOME Terminal (VTE 0.50+)
- Konsole
- Alacritty

### Color Support

Colors are automatically enabled when outputting to a terminal. Use `--no-color` or set the `NO_COLOR` environment variable to disable.

## Development

### Building

```bash
cargo build --release
```

### Running Tests

```bash
cargo test
```

### Project Structure

```
src/
├── lib.rs       # Library entry point with command implementations
├── main.rs      # Binary entry point (todo-tree)
├── bin/
│   └── tt.rs    # Binary entry point (tt alias)
├── cli.rs       # Command-line argument parsing (clap)
├── config.rs    # Configuration file handling
├── parser.rs    # Regex-based tag detection
├── printer.rs   # Output formatting (tree, flat, JSON)
└── scanner.rs   # Directory traversal (ignore crate)
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feat/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feat/amazing-feature`)
5. Open a Pull Request

## Acknowledgments

- Inspired by the [Todo Tree]https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree VS Code extension
- Built with [clap]https://github.com/clap-rs/clap, [ignore]https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore, and [regex]https://github.com/rust-lang/regex

## License

MIT License - see [LICENSE](LICENSE) for details.