JS plugin & Angular controller (function parameters and lines number)

583 views
Skip to first unread message

Alix Lourme

unread,
Nov 18, 2015, 9:36:57 AM11/18/15
to SonarQube
Hi,

The rules "Functions should not have too many parameters" (javascript:ExcessiveParameterList) and "Functions should not have too many lines" (javascript:S138) are very useful in most case, but could be a little tricky in case of Angular controller usage.
On a "real" Angular application, most of controller could not respect these rules.

Good explanation here : How to get SonarQube to play nicely with AngularJS?

These 2 rules could be excluded in the case of this framework function usage ? (Perhaps already in scope of SONARJS-533).

Thanks in advance.
Best regards

Elena Vilchik

unread,
Nov 19, 2015, 8:25:35 AM11/19/15
to SonarQube
Hi,

For sure we don't want you to exclude any valuable rules if using AngularJS. And what's more we want to create new rules for more accurate AngularJS code.
For that we need to ignore AngularJS controller functions for these rules. I've created a ticket SONARJS-548.

But as we don't use AngularJS we don't know all the patterns which should be ignored. Please feel free to supply in this thread any other AngularJS patterns which should be ignored for some reason.
Could you also provide example of code with issue "Functions should not have too many parameters" (which you consider as false positive)?

Thanks for the feedback!

Elena VILCHIK | SonarSource
Language Team

Alix Lourme

unread,
Nov 19, 2015, 4:24:54 PM11/19/15
to Elena Vilchik, SonarQube
Hi Helena,


I've created a ticket SONARJS-548

Thanks.

Please feel free to supply in this thread any other AngularJS patterns which should be ignored for some reason.

At my knowledge, no other case identified at this time.


Could you also provide example of code with issue "Functions should not have too many parameters"

I'm not in capacity to provide this snippet this week, but I will come back ASAP (probably next week).

Best regards.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/M6f5Neze7Jw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/37efc63b-d51b-40d5-a7f6-002f1c4cd5c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alix Lourme

Alix Lourme

unread,
Nov 19, 2015, 4:25:48 PM11/19/15
to Elena Vilchik, SonarQube
Hi Helena,

Grrr, sorry Elena
--
Alix Lourme

Alix Lourme

unread,
Nov 23, 2015, 7:34:42 AM11/23/15
to SonarQube
Hi Elena,

Could you also provide example of code with issue "Functions should not have too many parameters" (which you consider as false positive)?

When you inject some services in Angular controller, you could have a false positive like that :

// my controller, with any injected services
myModule
.controller('myController', [ '$scope', '$resource', '$location', '$http', '$timeout', '$q', 'BusinessService', 'AuthenticationService', function($scope, $resource, $location, $http, $timeout, $q, myBusinessService, myAuthenticationService) {
       

}]);

Best regards

Elena Vilchik

unread,
Nov 24, 2015, 5:03:43 AM11/24/15
to Alix Lourme, SonarQube
Hi Alix,

I prefer to not add angular exception for this rule ("Functions should not have too many parameters"). Here are the reasons:
1) whatever framework you use, function with many parameters is hard to maintain
2) many parameters might indicate design drawback
3) from Jonh Papa guide: "keep the controller simple and focused" (https://github.com/johnpapa/angular-styleguide#style-y037)

More over there is quite big default threshold for this rule (max parameter number is 7) and you can always mark issue as "won't fix".
 
Thanks!


Elena VILCHIK | SonarSource
Language Team

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/M6f5Neze7Jw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

Alix Lourme

unread,
Nov 24, 2015, 5:51:50 AM11/24/15
to SonarQube, alix....@gmail.com
Hi Elena,

Thanks for feedback. We will try to check the best practices and/or use UI exclusion possibilities.

Best regards.
Reply all
Reply to author
Forward
0 new messages