‘grunt-complexity-updater’ for nodejs

grunt-complexity-updater is a a little grunt-task that want to help you in multiple ways during development. It utilizes grunt-complexity to:

  • break your build if maintainability drops below a given threshold and will
  • auto-update the overall-maintainability with lowest detected maintainability in .complexityrc


This free’s you from the need to manually update a thresholds file and will (hopefully) help you to semi-automatic increase the maintainability of your project in the long run.

Here is actually all you need.

$ npm install grunt-complexity-updater

// in your Gruntfile.js
grunt.initConfig({
  complexity: {
    generic: {
      src: ['lib/*.js'],
      options: grunt.file.readJSON('.complexityrc')
    }
  }
});

grunt.loadNpmTasks('grunt-complexity-updater');

// a little shortcut
grunt.registerTask('test', ['update-grunt-complexity-values'])


Create a .complexityrc file and make it look like:

{
  "maintainability":      1,    // initial value, will be updated on next run
  "broadcast":            true, // make grunt-complexity broadcasting data

  // following settings are up to you
  //
  "breakOnErrors":        true|false,
  "errorsOnly":           true|false,
  "cyclomatic":           0,
  "halstead":             0,
  "hideComplexFunctions": false
}


That’s it.


I hope grunt-complexity will report more metrics in the future which i would really like to implement.


You can find “grunt-complexity-updater” either on npm or on github. Feel free to try and let me know what you think or file an(y) issues here


~david

This entry was posted in javascript, nodejs and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">