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

grunt-todos

v0.3.0

Published

Grunt plugin for finding todos/fixmes in code

Downloads

128

Readme

grunt-todos

Build Status NPM version Dependency Status devDependency Status

Grunt plugin for finding todos/fixmes in code

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-todos --save-dev

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-todos');

The "todos" task

Overview

In your project's Gruntfile, add a section named todos to the data object passed into grunt.initConfig().

grunt.initConfig({
  todos: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

options.priorities

Type: Object Default value: { low : /TODO/, med : /FIXME/, high : null }

An object that specifies what the various priorities are for the target. High will add to the errorCount.

options.verbose

Type: Boolean Default value: true

Verbose mode will cause the plugin to report on every file, regardless if there are actual lines to report or not. If set to false, only files with todos will be mentioned.

options.reporter

Type: String|Object Default value: 'default'

Specify a reporter to use. A string value will be resolved first to one of the bundled reporter, otherwise passedto require().

Bundled reporters:

  • default - classic console reporter.
  • markdown - simple markdown format.
  • path - console reporter that print full file-paths.

See below for the 'Custom reporter' section on how to create a custom reporter.

Usage Examples

Default Options

In this example, the default options are used to find all the TODOs and FIXMEs in the code.

grunt.initConfig({
  todos: {
    options: {},
    src : ['src/testing', 'src/123']
  }
})

Save to file

Use the grunt file src/dest convention to write reporter output to a file.

grunt.initConfig({
  todos: {
    options: {},
    files: {
      'path/files.txt': ['src/testing', 'src/123']
    }
  }
})

Custom Options

In this example, custom options are used to escalate TODO to med priority.

grunt.initConfig({
  todos: {
    options: {
        priorities : {
            low : null,
            med : /(TODO|FIXME)/
        }
    },
    src : ['src/testing', 'src/123']
  }
})

In this example, we want minimize the total output by setting verbose to false.

grunt.initConfig({
  todos: {
    options: {
        verbose: false
    },
    src : ['src/**/*.js']
  }
})

Custom Reporters

A custom reporter can be used to change the output of the task.

Reporters have three functions, header, fileTasks, and footer, that should return strings. The result of header is printed once at the beginning of the task. The result of footer is printed once at the end of the task. The fileTasks function is called once for each file that is being scanned.

Printing to the console or to a file is still controlled by the use of the src versus files options.

grunt.initConfig({
  todos: {
    options: {
      reporter: {
        header: function () {
          return '-- Begin Task List --\n';
        },
        fileTasks: function (file, tasks, options) {
          var result = '';
          result += 'For ' + file + '\n';
          tasks.forEach(function (task) {
            result += '[' + task.lineNumber + ' - ' + task.priority + '] ' + task.line + '\n';
          });
          result += '\n';
          return result;
        },
        footer: function () {
          return '-- End Task List--\n';
        }
      }
    }
  }
})

file Parameter

Type: String The path to the file being scanned for tasks.

tasks Parameter

Type: Array Contains the list of tasks found in the file.

An example tasks looks like this:

{
  file: 'path/to/file.js',
  lineNumber: 27,
  priority: 'low', // 'med' or 'high'
  line: '    // TODO something grand and spectacular',
  pattern: /\bTODO\b/ // Pattern used to recognize the priority
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • v0.3.x - adopted for updates & fixes by Bart van der Schoor @Bartvds (2014-05)
  • <= v0.2.x - original releases by Kevin Lakotko @kevinlacotaco

Licence

Copyright (c) 2014 by Bart van der Schoor. Copyright (c) 2013 by Kevin Lakotko.

Licensed under the MIT License.