I've been looking at using SonarQube to do quality checking on some javascript code, but this code is written using AngularJS.
One of the SonarQube rules checks the number of lines in a function - which seems sensible - but in AngularJS, functions are used to define controllers, services and directives, and these functions can get pretty big. Conceptually, they're really more like class definitions, with other functions nested within them.
Ideally, I'd like SonarQube to check the lengths of the inner functions, and possibly the outer function with the inner ones excluded, but I don't know of any way to do this.
Has anyone else encountered this problem using SonarQube with AngularJS, or does anyone know a good solution?
One solution is to declare all your methods separately in your self-executing function.
(function(){
var controller = function(dependency){
//...
},
someDirective = function(dependency){
//...
},
//Finally, your module
module = angular.module("MyMod", []);
module.controller("MyController", ['dependency', controller]);
module.directive("someDirective", ['dependency', someDirective]);
}());
This definitely can be an uncomfortable pattern for some devs, but it's one way to break your functions into smaller pieces for SonarQube.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With