Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including leasot with all npm packages installed. Try it out:

var leasot = require("leasot")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

leasot v8.2.0

Parse and output TODOs and FIXMEs from comments in your files



Leasot


Leasot

Intelligently parse and output TODOs and FIXMEs from comments in your files

npm npm downloads Travis (.org) code style: prettier

Easily extract, collect and report TODOs and FIXMEs in your code. This project uses regex in order to extract your todos from comments.

Basic output example of leasot

Comment format

TODO: add some info

  • Spaces are optional.
  • Colon is optional.
  • Must be in a comment (line or block) in its' own line (some code(); //TODO: do something is not supported).
  • Can be prefixed with a @ (i.e @TODO).
  • Spaces are trimmed around comment text.
  • Supported default types are TODO and FIXME - case insensitive.
  • Additional types can be added (using tags in cli and customTags in leasot.parse)
  • New extensions can be associated with bundled parsers as many languages have overlapping syntax
  • Supports both leading and trailing references. Examples:
    • // TODO(tregusti): Make this better
    • // TODO: Text /tregusti

Supported languages

FiletypeExtensionNotesParser Name
C#.csSupports // and /* */ comments.defaultParser
C++/C.cpp .c .hSupports // and /* */ comments.defaultParser
Coffee-React.cjsxSupports # comments.coffeeParser
Coffeescript.coffeeSupports # comments.coffeeParser
Crystal.crSupports # comments.coffeeParser
CSon.csonSupports # comments.coffeeParser
CSS.cssSupports /* */ comments.defaultParser
EJS.ejsSupports <!-- --> and <%# %>ejsParser
Erb.erbSupports <!-- --> and <%# %>ejsParser
Erlang.erl .hrlSupports % comments.erlangParser
Go.goSupports // and /* */ comments.defaultParser
Haml.hamlSupports / -# <!-- --> and <%# %>twigParser
Handlebars.hbs .handlebarsSupports {{! }} and {{!-- --}}hbsParser
Haskell.hsSupports --haskellParser
Hogan.hgn .hoganSupports {{! }} and {{!-- --}}hbsParser
HTML.html .htmSupports <!-- -->twigParser
Jade.jade .pugSupports // and //- comments.jadeParser
Java.javaSupports // and /* */ commentsdefaultParser
Javascript.js .es .es6Supports // and /* */ commentsdefaultParser
Jsx.jsxSupports // and /* */ comments.defaultParser
Kotlin.ktSupports // and /* */ comments.defaultParser
Latex.texSupports \begin{comment} and % commentslatexParser
Less.lessSupports // and /* */ comments.defaultParser
Markdown.markdown, .mdSupports <!-- -->twigParser
Mustache.mustacheSupports {{! }} and {{!-- --}}hbsParser
Nunjucks.njkSupports {# #} and <!-- -->twigParser
Objective-C.mSupports // and /* */ commentsdefaultParser
Objective-C++.mmSupports // and /* */ commentsdefaultParser
Pascal.pasSupports // and { } comments.pascalParser
Perl.pl, .pmSupports # comments.coffeeParser
PHP.phpSupports // and /* */ comments.defaultParser
Protocol Buffer.protoSupports // and /* */ comments.defaultParser
Python.pySupports """ and # comments.pythonParser
Ruby.rbSupports # comments.coffeeParser
Rust.rsSupports // and /* */ comments.defaultParser
Sass.sass .scssSupports // and /* */ comments.defaultParser
Scala.scalaSupports // and /* */ comments.defaultParser
Shell.sh .zsh .bashSupports # comments.coffeeParser
SilverStripe.ssSupports <%-- --%> comments.ssParser
SQL.sqlSupports -- and /* */ commentsdefaultParser & haskellParser
Stylus.stylSupports // and /* */ comments.defaultParser
Swift.swiftSupports // and /* */ comments.defaultParser
Svelte.svelteSupports // /* */ <!-- --> comments.twigParser
Twig.twigSupports {# #} and <!-- -->twigParser
Typescript.ts, .tsxSupports // and /* */ comments.defaultParser
Vue.vueSupports // /* */ <!-- --> comments.twigParser
Yaml.yaml .ymlSupports # comments.coffeeParser

Javascript is the default parser. PRs for additional filetypes is most welcomed!!

Usage in command line

npm install --global leasot

Command line help

$ leasot --help

Usage: leasot [options] <file ...>

Parse and output TODOs and FIXMEs from comments in your files

Options:
  -V, --version                        output the version number
  -A, --associate-parser [ext,parser]  associate unknown extensions with bundled parsers (parser optional / default: defaultParser) (default: {})
  -i, --ignore <patterns>              add ignore patterns (default: [])
  -I, --inline-files                   parse possible inline files (default: false)
  -r, --reporter [reporter]            use reporter (table|json|xml|markdown|vscode|raw) (default: table) (default: "table")
  -S, --skip-unsupported               skip unsupported filetypes (default: false)
  -t, --filetype [filetype]            force the filetype to parse. Useful for streams (default: .js)
  -T, --tags <tags>                    add additional comment types to find (alongside todo & fixme) (default: [])
  -x, --exit-nicely                    exit with exit code 0 even if todos/fixmes are found (default: false)
  -h, --help                           output usage information

Examples:
    # Check a specific file
    $ leasot index.js

    # Check php files with glob
    $ leasot '**/*.php'

    # Check multiple different filetypes
    $ leasot 'app/**/*.js' test.rb

    # Use the json reporter
    $ leasot --reporter json index.js

    # Search for REVIEW comments as well
    $ leasot --tags review index.js

    # Add ignore pattern to filter matches
    $ leasot 'app/**/*.js' --ignore '**/custom.js'

    # Search for REVIEW comments as well
    $ leasot --tags review index.js

    # Check a stream specifying the filetype as coffee
    $ cat index.coffee | leasot --filetype .coffee

    # Report from leasot parsing and filter todos using `jq`
    $ leasot 'tests/**/*.styl' --reporter json | jq 'map(select(.tag == "TODO"))' | leasot-reporter

    # Associate a parser for an unknown extension`
    $ leasot -A '.svelte,twigParser' -A '.svelte,defaultParser' 'frontend/*.svelte'

Usage in NPM scripts

Use leasot -x in order to prevent exiting with a non-zero exit code. This is a good solution if you plan to run leasot in a CI tool to generate todos.

{
    "scripts": {
        "todo": "leasot 'src/**/*.js'",
        "todo-ci": "leasot -x --reporter markdown 'src/**/*.js' > TODO.md"
    },
    "devDependencies": {
        "leasot": "^7.0.0"
    }
}

Programmatic Installation

npm install --save-dev leasot

Programmatic Examples

const fs = require('fs');
const leasot = require('leasot');

const contents = fs.readFileSync('./contents.js', 'utf8');
// get the filetype of the file, or force a special parser
const filetype = path.extname('./contents.js');
// add file for better reporting
const file = 'contents.js';
const todos = leasot.parse(content, { extension: filetype, filename: file });

// -> todos now contains the array of todos/fixme parsed

const output = leasot.reporter(todos, 'json', { spacing: 2 });

console.log(output);
// -> json output of the todos

Leasot with build tools

API

const leasot = require('leasot');

See main exported functions

Mainly, you should be using 2 functions:

  • parse for parsing file contents
  • report for reporting the todos

Type documentation

Built-in Reporters

See built-in reporters

License

MIT © Gilad Peleg

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free