npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

report-todo

v1.0.1

Published

Parse and report TODO, FIXME, BUG etc. comments in source code.

Downloads

4,197

Readme

report-todo

Generate reports of TODO, FIXME, BUG etc. comments across trees of text files.

Features:

  • Easy setup, as report-todo does not try to understand the grammar of the used programming languages and detect comments, but it simply searches for the configured tags naively, i.e. without regard for the used programming language, and tries to detect the respective comments by looking at how lines start
  • Support for multiline comments
  • Support for comment labels/tags
  • The Markdown report provides links to the files and lines where the comments are found, giving a quick way to open them when using code editors that can preview Markdown documents, for example Vim or Visual Studio Code
  • Both CLI command and Node.js API
  • Highly configurable

Quick installation and usage

$ npm install -g report-todo
$ report-todo my/project/directory/

...but I don't want to install it system-wide!

$ cd my/project/directory/
$ npm install report-todo
$ npx report-todo

I use Arch Linux, can I use pacman?

Install the report-todo package with your favorite AUR helper.

Otherwise follow the manual instructions.

Then just run the report-todo command.

I want JSON, not Markdown

$ report-todo -m json

Report examples

These are based on src/DEMO.js.

Markdown

$ report-todo aux/DEMO.js -m markdown
# Table of contents

1. [#45](#1-0)
2. [[NO LABEL]](#1-1)
3. [defect](#1-2)
4. [setup](#1-3)

# #45<a id="1-0"></a>

| file path | line # | tag | labels | comment
|:----------|:-------|:----|:-------|:-------
| [./aux/DEMO.js](./aux/DEMO.js#L11) | 11 | BUG | defect,#45 | Solve this problem<br>This second line adds more details<br>So does this third line

# [NO LABEL]<a id="1-1"></a>

| file path | line # | tag | labels | comment
|:----------|:-------|:----|:-------|:-------
| [./aux/DEMO.js](./aux/DEMO.js#L1) | 1 | TODO |  | Simple comment without labels

# defect<a id="1-2"></a>

| file path | line # | tag | labels | comment
|:----------|:-------|:----|:-------|:-------
| [./aux/DEMO.js](./aux/DEMO.js#L11) | 11 | BUG | defect,#45 | Solve this problem<br>This second line adds more details<br>So does this third line

# setup<a id="1-3"></a>

| file path | line # | tag | labels | comment
|:----------|:-------|:----|:-------|:-------
| [./aux/DEMO.js](./aux/DEMO.js#L6) | 6 | TODO | setup | I can make this do a lot more<br>It's all written here

JSON

$ report-todo aux/DEMO.js -m json
[
  {
    "type": "labels",
    "key": "#45",
    "matches": [
      {
        "filePath": "./aux/DEMO.js",
        "tag": "BUG",
        "startLineNo": 11,
        "lines": [
          "Solve this problem",
          "This second line adds more details",
          "So does this third line"
        ],
        "labels": [
          "defect",
          "#45"
        ]
      }
    ]
  },
  {
    "type": "labels",
    "key": "[NO LABEL]",
    "matches": [
      {
        "filePath": "./aux/DEMO.js",
        "tag": "TODO",
        "startLineNo": 1,
        "lines": [
          "Simple comment without labels"
        ],
        "labels": []
      }
    ]
  },
  {
    "type": "labels",
    "key": "defect",
    "matches": [
      {
        "filePath": "./aux/DEMO.js",
        "tag": "BUG",
        "startLineNo": 11,
        "lines": [
          "Solve this problem",
          "This second line adds more details",
          "So does this third line"
        ],
        "labels": [
          "defect",
          "#45"
        ]
      }
    ]
  },
  {
    "type": "labels",
    "key": "setup",
    "matches": [
      {
        "filePath": "./aux/DEMO.js",
        "tag": "TODO",
        "startLineNo": 6,
        "lines": [
          "I can make this do a lot more",
          "It's all written here"
        ],
        "labels": [
          "setup"
        ]
      }
    ]
  }
]

Command-line usage

Running the command without arguments will parse the files in and under the current working directory:

$ report-todo

The above command is equivalent to:

$ report-todo ./

Pass multiple arguments to parse files under various patterns. Patterns are processed with globby, which for example also supports negative (exclude) matches by prefixing them with an exclamation mark. Some patterns are also excluded by default, see also the --no-default-excludes option. For example:

$ report-todo ./src ./docs !./test

Use the --help option to print a quick usage guide and a list of all the available CLI options:

$ report-todo --help

Or, if locally installed in a directory:

$ npx report-todo --help

Options

| Flag | Description | |------|-------------| | -t, --tags <TAG1,TAG2...> | comma-separated whitelist of tags to parse; default is "TODO,FIXME,BUG" | | -l, --labels <LABEL1,LABEL2...> | comma-separated whitelist of labels to include in the results; using an empty string in the list will also include results without labels; it is enough for a match with multiple labels to have only of them in the whitelist to be included in the results; default is to include all results regardless of their labels | | --labels-delimiters <OPEN,CLOSE> | two comma-separated strings that are used to enclose labels; default is "[" "]" | | --labels-separator <SEP> | string to be used to separate labels; default is "," | | -b, --labels-is-blacklist | treat --labels as a blacklist instead; using an empty string in --labels will exclude results without labels; it is enough for a match with multiple labels to have only of them in the --labels to be excluded from the results; --labels is a whitelist by default | | -i, --case-insensitive | parse tags and labels case-insensitively; default is to also match letter case | | --ignore-line-comment <COMMENT> | the string to be appended to lines to exclude them from the results; default is "report-todo-ignore-line" | | -m, --report-mode <MODE> | the generated report mode; one of "json", "markdown"; more modes are available through the Node.js API; default is "markdown" | | -g, --report-group-by <KEY1,KEY2...> | comma-separated, ordered list of keys by which results are grouped and (possibly nested) report sections created; one or more of "filePath", "tag", "startLineNo", "lines", "labels"; default is "labels" | | -s, --report-sort-by <KEY1,KEY2...> | comma-separated, ordered list of keys by which results are sorted within report sections; one or more of "filePath", "tag", "startLineNo", "lines", "labels"; default is "filePath,startLineNo" | | --report-links-prefix <PREFIX> | reports that create links to the files will prefix their URLs with this string; nothing is prefixed by default |


Node.js API

Require the reportTodo() function from the report-todo module.

const {reportTodo} = require('report-todo')

The reportTodo() function accepts two arguments:

reportTodo(globs, options)

globs is a pattern or array of patterns that indicate the root paths under which files will be parsed. globs is processed by globby, which for example also supports negative (exclude) matches by prefixing them with an exclamation mark.

options is an object of key:value configuration pairs:

reportTodo(globs, {
  tags,
  labels,
  labelsDelimiters,
  labelsSeparator,
  labelsIsBlacklist,
  caseInsensitive,
  ignoreLineComment,
  reportMode,
  reportGroupBy,
  reportSortBy,
  reportLinksPrefix,
}

Options

| Key | Default | Description | |-----|---------|-------------| | tags | ["TODO","FIXME","BUG"] | array of tags to parse | | labels | null | whitelist array of labels to include in the results; adding null or an empty string in the array will also include results without labels; setting labels=false will only include results without labels; it is enough for a match with multiple labels to have only of them in the whitelist to be included in the results default is to include all results regardless of their labels | | labelsDelimiters | ["[","]"] | array of two strings that are used to enclose labels | | labelsSeparator | "," | string to be used to separate labels | | labelsIsBlacklist | false | treat labels as a blacklist instead; using null or an empty string in labels will exclude results without labels; it is enough for a match with multiple labels to have only of them in the labels to be excluded from the results; labels is a whitelist by default | | caseInsensitive | false | parse tags and labels case-insensitively; default is to also match letter case | | ignoreLineComment | "report-todo-ignore-line" | the string to be appended to lines to exclude them from the results | | reportMode | "markdown" | the generated report mode; one of "generator", "object", "json", "markdown"; "generator" returns an asynchronous generator that yields results as they are found (files are opened asynchronously, so the order of the results is not guaranteed to be the same at every run); "object" returns a grouped and sorted JavaScript object; "json" returns a JSON string; "markdown" returns a Markdown document | | reportGroupBy | ["labels"] | ordered array of keys by which results are grouped and (possibly nested) report sections created; one or more of "filePath", "tag", "startLineNo", "lines", "labels" | | reportSortBy | ["filePath","startLineNo"] | ordered array of keys by which results are sorted within report sections; one or more of "filePath", "tag", "startLineNo", "lines", "labels" | | reportLinksPrefix | null | reports that create links to the files will prefix their URLs with this string; nothing is prefixed by default |

Examples

Pre-grouped/sorted object:

const {reportTodo} = require('report-todo')

reportTodo(`./src/`, {reportMode: 'object'}).then((report) => {
  console.log(report)
})

Asynchronous generator:

const {reportTodo} = require('report-todo')

const generator = reportTodo(`./src/`, {reportMode: 'generator'})

for await (const todo of generator) {
  console.log(todo)
}

Todo match objects

Some report modes such as generator, object and json list results as objects with the following keys:

| Key | Description | |-----------------|--------------------------------------| | filePath | the file path | | startLineNo | the match's start line number | | tag | the matched tag | | labels | array with the match's labels | | lines | array with the match's comment lines |


Similar projects

  • Leasot: the goal is similar, however Leasot attempts to detect the comments according to the specific syntax of the programming languages used in the parsed files.

License

MIT, see LICENSE.