Coder Social home page Coder Social logo

grunt-todos's Introduction

grunt-todos

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.

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']
  }
})

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

(Nothing yet)

grunt-todos's People

Contributors

kevinlacotaco avatar developerdanjo avatar m3nt0r avatar

Stargazers

Arild Rotmo avatar Jiri Matyas avatar  avatar  avatar Orhan Küçükyılmaz avatar Chris Rohrer avatar  avatar Brett McHargue avatar Daniel Gutiérrez avatar Benjamin Adams avatar Jason Founts avatar Nathaniel Furniss avatar David Murphy avatar Rude avatar Andrew Minton avatar Peter Bačinský avatar David Hund avatar Lars Miesner avatar Gleb P avatar  avatar  avatar Philipp Kyeck avatar Nick avatar Braunson Yager avatar Benjamin Parry avatar riz avatar Evo Stamatov avatar Charles Shopsin avatar Jake Rayson avatar René Zschoch avatar Shaked Klein Orbach avatar John Devlin avatar Nolboo Kim avatar Olivier Mourlevat avatar Kitt Hodsden avatar Rishabh Mahajan avatar Lucius Humm avatar Kenneth Lim avatar Chris Meagher avatar Ryan Burgess avatar James Greenaway avatar  avatar Rhys Arkins avatar Bearded Viking avatar Fabrizio Fortunato avatar Marius Hauken avatar Jefferson Rafael Kozerski avatar Ollie Silviotti avatar David Mignot avatar Gustav Hansen avatar yeraycaballero avatar Eric avatar  avatar zeristor avatar Radu Micu avatar Fernando Agüero avatar Remy Martin avatar Piotr Błażejewicz (Peter Blazejewicz) avatar Anselm Hannemann avatar 0xADADA avatar Jeff Jewiss avatar Julio Pavón avatar Adam Simpson avatar Aurélien Thieriot avatar Glen Ihrig avatar Andrew Jones avatar Jeremy Heffner avatar Stacey Moore avatar Pierre avatar Julien Bouquillon avatar Luís Couto avatar Vincent Ogloblinsky avatar Fellipe Cicconi avatar Tauren Mills avatar Adam Garrett-Harris avatar Makoto Tateno avatar Brian Debuire avatar  avatar Stefaney Roberts avatar Javier Mendiara avatar Denis Ciccale avatar Cody Peterson avatar Antonello Pasella avatar Anthony Barone avatar

Watchers

 avatar Youth avatar

grunt-todos's Issues

TypeError: Object .. has no method 'split'

Hi,

I'm using this plugin for the first time, and am getting this error:

TypeError: Object 
[insert contents of a JS file here]
 has no method 'split'
    at fileReader (/Users/Dan/Websites/project_name/_svn/htdocs/node_modules/grunt-todos/lib/grep.js:10:26)
    at fs.readFile (fs.js:176:14)
    at fs.close (/Users/Dan/Websites/project_name/_svn/htdocs/node_modules/grunt/node_modules/rimraf/node_modules/graceful-fs/graceful-fs.js:90:5)
    at Object.oncomplete (fs.js:297:15)

Gruntfile.js config:

paths: {
  resources:        'resources',
  scripts:          '<%= paths.resources %>/scripts',
},

// TODOS
todos: {
  options: {
    priorities: {
      low : /TODO/, // default
      med : /FIXME/, // default
      high : null // default
    },
    verbose: false //  only files with todos will be mentioned.
    // Task-specific options go here.
  },
  src : [
    '<%= paths.scripts %>/*.js' // target all .js files
  ]
},

I get the same error when running the plugin over CSS files.

"devDependencies": {
    "grunt": "~0.4.1",
    "grunt-todos": "~0.2.0"
}

Thanks,
Dan

[note] Forked & adopted the project on npm

I use this project a lot but had to run a fork with my fixes.

Earlier I'd send PR #6 but the maintainer of this project @kevinlacotaco disappeared from Github.

As I didn't like to release yet another todo's plugin I went through the npm procedure to get maintainer rights on npm (all proper & official).

So I just published v0.3.0 with some of the fixes, and this project now lives at https://github.com/Bartvds/grunt-todos. Collaboration is still welcome of course.

'high' errors do not cause grunt task to fail

The check for results.high does not work and will always resolve to false (no error reported).
results is not an object with this property, but an array containing objects that have an injected priority property.

add support for grunt 1.0.0

since the peer dependency is of ~0.4.0, new grunt version (1.x.x) is not supported.
Can you please update the needed?

Tips on running the tests

Im trying to run the test suit but its failing with errors like these:

Error: Unable to read "tmp/default_options" file (Error code: ENOENT).

I dont have those tmp files, I can see them at test/expected but the grunt task is always cleaning/erasing those files before testing?

Any pointers are welcome :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.