From: Gustavo Martin Morcuende Date: Sun, 21 Aug 2016 21:20:57 +0000 (+0200) Subject: SonarQube JavaScript custom plugin, improvements in description X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=2275d72e59fc37a76acf46a9b1a3247b4d474a71;p=JavaForFun SonarQube JavaScript custom plugin, improvements in description --- diff --git a/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.html b/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.html index ab6882f..16fffe2 100644 --- a/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.html +++ b/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.html @@ -1,18 +1,21 @@ -

Custom rule description.

+

AngularJS Controllers are instantiated every time a web page is loaded. $rootScope.$on do not automatically release the pointer to +the Controller where it was called and $rootScope is an AngularJS singleton. After a couple of web page refreshes we end up having +many instantiated Controllers that will not be used and they can not be reclaimed by the garbage collector because there is a reference to them +from $rootScope. As a good practice we will not use $rootScope.$on in AngularJS Controllers.

Noncompliant Code Example

-class MyClass {
-	
-	int foo1(int value) { return 0; }
-		
-	MyClass foo2(MyClass value) { return null; }
-	
-	...
- 
+function MyController($rootScope, USERS) {
+    var vm = this;
+
+    $rootScope.$on(USERS.ROOTSCOPE.BROADCAST, usersChildOnRootBroadcast); //$rootScope is a singleton, it is not released and either MyController
+        
+    function usersChildOnRootBroadcast(events, broadcastUser) {
+        vm.broadcastUser = broadcastUser;
+    }
 }
 

See

diff --git a/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.json b/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.json index 928a6af..82d0ab8 100644 --- a/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.json +++ b/Sonar/Plugins/sonar-custom-javascript-plugin/src/main/resources/de/example/l10n/javascript/rules/custom/GUJS0001_javascript.json @@ -1,12 +1,13 @@ { - "title": "Function names should comply with a naming convention", + "title": "Do not use $rootScope.$on in AngularJS Controllers", "status": "ready", "remediation": { "func": "Constant\/Issue", "constantCost": "5min" }, "tags": [ - "bug" + "bug", + "angularjs" ], "defaultSeverity": "Major" }