https://github.com/euforic/todos
Golang TODO style comment parser
https://github.com/euforic/todos
cli fixme linter todos
Last synced: 5 months ago
JSON representation
Golang TODO style comment parser
- Host: GitHub
- URL: https://github.com/euforic/todos
- Owner: euforic
- License: mit
- Created: 2023-03-03T07:10:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-10T17:58:12.000Z (over 3 years ago)
- Last Synced: 2024-06-20T22:33:55.686Z (about 2 years ago)
- Topics: cli, fixme, linter, todos
- Language: Go
- Homepage: https://euforic.in/todos/
- Size: 43 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Todos
[](https://goreportcard.com/report/github.com/euforic/todos)
[](https://pkg.go.dev/github.com/euforic/todos/todos)
[](https://github.com/euforic/todos/actions/workflows/lint.yml)
[](https://sourcegraph.com/github.com/euforic/todos?badge)
This is a command-line program written in Go that searches for `// TODO: xxxx` style comments in a directory and outputs them to the console or in JSON format.
## Usage
```bash
todos [options]
```
The program accepts the following command-line arguments:
- `-ignore`: A comma-separated list of files and directories to ignore, in gitignore format.
- `-sortby`: Sort results by field (`author`, `file`, `line`, `type`, or `text`)
- `-output`: Output style (table, file, json). Default: table
- `-types`: A comma-separated list of comment types to search for. The default is "TODO,FIXME".
- `-hidden`: Search hidden files and directories.
- `-permissive`: Permissive mode (looser regex, but can match more than intended, strict format is 'TYPE(author): text' where author is optional)
- `-format`: Uses the provide go template to output the result
- `-no-gitignore`: Ignore .gitignore file
- `-validate-max`: Validate that the number of comments is less than or equal to the max.
## Install
To install the program, run the following command:
```bash
go install github.com/euforic/todos@latest
```
## Running the Program
To run the program for the current dir, execute the following command:
```bash
todos
```
You can also pass command-line arguments to the program. For example, to search for comments in the directory "myproject" and output the results in JSON format, run the following command:
```bash
todos -output json ./myproject
```
### Search a Specific Directory
To search a specific directory, use `todos [options] ` the first arg is the directory path. For example, to search the directory `~/projects/myproject`, run the following command:
```bash
todos ~/projects/myproject
```
### Ignore Files and Directories
To ignore files and directories, use the `-ignore` flag followed by a comma-separated list of files and directories in gitignore format. For example, to ignore files with the extensions `.txt` and `.log`, and directories named `vendor` and `node_modules`, run the following command:
```bash
todos -ignore "*.txt,*.log,vendor/,node_modules/"
```
### Output in Format Style
To output the results in the chosen format (json, file, table), use the `-output` flag. For example, to output the results in json format, run the following command:
```bash
todos -output json
```
### Sort Results
To sort the results, use the `-sortby` flag followed by the field to sort by. The valid fields are `author`, `file`, `line`, `type`, and `text`. For example, to sort the results by comment type, run the following command:
```bash
todos -sortby type
```
To sort in descending order add the postfix `:desc`. For example to sort by author in decending order, you would run the following command:
```bash
todos -sortby author:desc
```
### Search for Different Comment Types
To search for different types of comments, use the `-types` flag followed by a comma-separated list of comment types. For example, to search for comments with the types `TODO`, `FIXME`, and `NOTE`, run the following command:
```bash
todos -types=TODO,FIXME,NOTE
```
### Format
To format the output of the comments, use the `-format` flag followed by a Go template string. For example, to see all of the comments, use the following command:
```bash
todos -format "{{range .}}{{ .File}}\n Line: {{.Line}}\n Text: {{.Text}}\n Author: {{- .Author}}\n\n{{end}}"
```
To use a template file, use the following command:
```bash
todos -format "$(cat some.template)"
```
### Validate Max
To validate the maximum amount of comments does not exceed a certin value, use the `-validate-max` flag followed by the maximium number of comments. For example, to limit the maximum amount of comments to `20`, run the following command:
```bash
todos -validate-max 20
```