← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/javascript-lint into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/javascript-lint into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/javascript-lint/+merge/102343
-- 
https://code.launchpad.net/~allenap/maas/javascript-lint/+merge/102343
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/javascript-lint into lp:maas.
=== modified file 'Makefile'
--- Makefile	2012-03-29 22:39:44 +0000
+++ Makefile	2012-04-17 16:11:18 +0000
@@ -57,6 +57,18 @@
 	@find $(sources) -name '*.py' ! -path '*/migrations/*' \
 	    -print0 | xargs -r0 bin/flake8
 
+lint-css: sources = src/maasserver/static/css
+lint-css: /usr/bin/pocketlint
+	@find $(sources) -type f \
+	    -print0 | xargs -r0 pocketlint --max-length=120
+
+lint-js: sources = src/maasserver/static/js
+lint-js: /usr/bin/pocketlint
+	@find $(sources) -type f -print0 | xargs -r0 pocketlint
+
+/usr/bin/pocketlint:
+	sudo apt-get install python-pocket-lint
+
 check: clean test
 
 docs/api.rst: bin/maas src/maasserver/api.py syncdb
@@ -113,8 +125,25 @@
 	bin/maas migrate maasserver --noinput
 	bin/maas migrate metadataserver --noinput
 
-.PHONY: \
-    build check clean dev-db distclean doc \
-    harness lint pserv-start pserv-stop run \
-    txlongpoll-start txlongpoll-stop \
-    syncdb test sampledata
+define phony
+  build
+  check
+  clean
+  dev-db
+  distclean
+  doc
+  harness
+  lint
+  lint-css
+  lint-js
+  pserv-start
+  pserv-stop
+  run
+  sampledata
+  syncdb
+  test
+  txlongpoll-start
+  txlongpoll-stop
+endef
+
+.PHONY: $(phony)

=== modified file 'src/maasserver/static/js/morph.js'
--- src/maasserver/static/js/morph.js	2012-04-04 04:31:01 +0000
+++ src/maasserver/static/js/morph.js	2012-04-17 16:11:18 +0000
@@ -12,7 +12,9 @@
 
 var module = Y.namespace('maas.morph');
 
-var Morph = function(config) {
+var Morph;
+
+Morph = function(config) {
     Morph.superclass.constructor.apply(this, arguments);
 };
 
@@ -44,14 +46,8 @@
     },
 
     morph: function(reverse) {
-        if (reverse){
-            var srcNode = this.get('targetNode');
-            var targetNode = this.get('srcNode');
-        }
-        else {
-            var srcNode = this.get('srcNode');
-            var targetNode = this.get('targetNode');
-        }
+        var srcNode = this.get(reverse ? 'targetNode' : 'srcNode');
+        var targetNode = this.get(reverse ? 'srcNode' : 'targetNode');
         if (this._animate) {
             var target_height = targetNode.getComputedStyle('height');
             var fade_out = new Y.Anim({
@@ -65,7 +61,7 @@
                 targetNode.addClass('hidden');
                 srcNode.setStyle('opacity', 0);
                 srcNode.removeClass('hidden');
-                src_height = srcNode.getComputedStyle('height')
+                var src_height = srcNode.getComputedStyle('height')
                     .replace('px', '');
                 srcNode.setStyle('height', target_height);
                 var fade_in = new Y.Anim({

=== modified file 'src/maasserver/static/js/node_add.js'
--- src/maasserver/static/js/node_add.js	2012-04-16 05:59:24 +0000
+++ src/maasserver/static/js/node_add.js	2012-04-17 16:11:18 +0000
@@ -17,7 +17,9 @@
 // Only used to mockup io in tests.
 module._io = new Y.IO();
 
-var AddNodeWidget = function() {
+var AddNodeWidget;
+
+AddNodeWidget = function() {
     AddNodeWidget.superclass.constructor.apply(this, arguments);
 };
 

=== modified file 'src/maasserver/static/js/node_views.js'
--- src/maasserver/static/js/node_views.js	2012-03-21 15:29:00 +0000
+++ src/maasserver/static/js/node_views.js	2012-04-17 16:11:18 +0000
@@ -145,7 +145,9 @@
         this.numberNode = Y.one(config.numberNode);
         this.descriptionNode = Y.one(config.descriptionNode);
         this.reservedNode = Y.one(config.reservedNode);
+        this.reservedNode.hide();  // Until we support it.
         this.retiredNode = Y.one(config.retiredNode);
+        this.retiredNode.hide();  // Until we support it.
         this.deployed_nodes = 0;
         this.commissioned_nodes = 0;
         this.queued_nodes = 0;
@@ -191,8 +193,8 @@
             {event: 'hover.queued.over', template: this.queued_template},
             {event: 'hover.queued.out'}
             ];
-        for (var ev in events) {
-            this.chart.on(events[ev].event, function(e, template, widget) {
+        Y.Array.each(events, function(event) {
+            this.chart.on(event.event, function(e, template, widget) {
                 if (Y.Lang.isValue(e.nodes)) {
                     widget.setSummary(true, e.nodes, template, true);
                 }
@@ -200,8 +202,8 @@
                     // Set the text to the default
                     widget.setSummary(true);
                 }
-            }, null, events[ev].template, this);
-        }
+            }, null, event.template, this);
+        }, this);
     },
 
    /**
@@ -214,7 +216,8 @@
            so that this.modelList exists.
         */
         if (!this.data_populated) {
-            for (var i=0; i<this.modelList.size(); i++) {
+            var i;
+            for (i=0; i<this.modelList.size(); i++) {
                 var node = this.modelList.item(i);
                 var status = node.get('status');
                 this.updateStatus('add', status);
@@ -256,22 +259,23 @@
     * Update the nodes in the chart.
     */
     updateNode: function(action, node) {
+        var model_node;
         var update_chart = false;
-        if (action == 'created') {
+        if (action === 'created') {
             this.modelList.add(node);
             update_chart = this.updateStatus('add', node.status);
         }
-        else if (action == 'deleted') {
-            var model_node = this.modelList.getById(node.system_id);
+        else if (action === 'deleted') {
+            model_node = this.modelList.getById(node.system_id);
             this.modelList.remove(model_node);
             update_chart = this.updateStatus('remove', node.status);
         }
-        else if (action == 'updated') {
-            var model_node = this.modelList.getById(node.system_id);
-            previous_status = model_node.get('status');
+        else if (action === 'updated') {
+            model_node = this.modelList.getById(node.system_id);
+            var previous_status = model_node.get('status');
             model_node.set('status', node.status);
-            update_remove = this.updateStatus('remove', previous_status);
-            update_add = this.updateStatus('add', node.status);
+            var update_remove = this.updateStatus('remove', previous_status);
+            var update_add = this.updateStatus('add', node.status);
             if (update_remove || update_add) {
                 update_chart = true;
             }
@@ -282,7 +286,7 @@
             this.chart.updateChart();
         }
 
-        if (action != 'updated') {
+        if (action !== 'updated') {
             /* Set the default text on the dashboard. We only need to do this
                if the total number of nodes has changed.
             */
@@ -298,35 +302,36 @@
         /* This seems like an ugly way to calculate the change, but it stops
            duplication of checking for the action for each status.
         */
-        if (action == 'add') {
-            var node_counter = 1;
+        var node_counter;
+        if (action === 'add') {
+            node_counter = 1;
         }
-        else if (action == 'remove') {
-            var node_counter = -1;
+        else if (action === 'remove') {
+            node_counter = -1;
         }
 
         /* TODO: The commissioned status currently doesn't exist, but once it
            does it should be added here too.
         */
-        if (status == 0) {
+        if (status === 0) {
             // Added nodes
             this.added_nodes += node_counter;
             this.chart.set('added_nodes', this.added_nodes);
             update_chart = true;
         }
-        else if (status == 1 || status == 2 || status == 3) {
+        else if (status === 1 || status === 2 || status === 3) {
             // Offline nodes
             this.offline_nodes += node_counter;
             this.chart.set('offline_nodes', this.offline_nodes);
             update_chart = true;
         }
-        else if (status == 4) {
+        else if (status === 4) {
             // Queued nodes
             this.queued_nodes += node_counter;
             this.chart.set('queued_nodes', this.queued_nodes);
             update_chart = true;
         }
-        else if (status == 5) {
+        else if (status === 5) {
             // Reserved nodes
             this.reserved_nodes += node_counter;
             this.setNodeText(
@@ -335,13 +340,13 @@
                 this.reserved_nodes
                 );
         }
-        else if (status == 6) {
+        else if (status === 6) {
             // Deployed nodes
             this.deployed_nodes += node_counter;
             this.chart.set('deployed_nodes', this.deployed_nodes);
             update_chart = true;
         }
-        else if (status == 7) {
+        else if (status === 7) {
             // Retired nodes
             this.retired_nodes += node_counter;
             this.setNodeText(
@@ -360,8 +365,8 @@
             nodes = this.getNodeCount();
             template = this.all_template;
         }
-        plural = (nodes === 1) ? '' : 's';
-        text = Y.Lang.sub(template, {plural: plural})
+        var plural = (nodes === 1) ? '' : 's';
+        var text = Y.Lang.sub(template, {plural: plural});
 
         if (animate) {
             this.fade_out.run();
@@ -381,8 +386,8 @@
     * Set the text from a template for a DOM node.
     */
     setNodeText: function(element, template, nodes) {
-        plural = (nodes === 1) ? '' : 's';
-        text = Y.Lang.sub(template, {plural: plural, nodes: nodes})
+        var plural = (nodes === 1) ? '' : 's';
+        var text = Y.Lang.sub(template, {plural: plural, nodes: nodes});
         element.setContent(text);
     },
 
@@ -391,7 +396,7 @@
     */
     getNodeCount: function() {
         return Y.Array.filter(this.modelList.toArray(), function (model) {
-            return model.get('status') != 7;
+            return model.get('status') !== 7;
         }).length;
     }
 });

=== modified file 'src/maasserver/static/js/nodes_chart.js'
--- src/maasserver/static/js/nodes_chart.js	2012-03-21 16:08:06 +0000
+++ src/maasserver/static/js/nodes_chart.js	2012-04-17 16:11:18 +0000
@@ -12,17 +12,14 @@
 
 var module = Y.namespace('maas.nodes_chart');
 
-var NodesChartWidget = function() {
+var NodesChartWidget;
+
+NodesChartWidget = function() {
     NodesChartWidget.superclass.constructor.apply(this, arguments);
 };
 
 NodesChartWidget.NAME = 'nodes-chart-widget';
 
-
-NodesChartWidget._outer_paths;
-NodesChartWidget._offline_circle;
-NodesChartWidget._added_circle;
-
 var TRANSITION_TIME = 1000,
     TRANSITION_EASING = 'easeInOut',
     OUTER_COLOURS = ['#19b6ee', '#38b44a', '#0d80aa'],
@@ -184,10 +181,9 @@
                 }
             ];
 
-        var outer_total = 0;
-        for (var n in outer_nodes) {
-            outer_total += outer_nodes[n].nodes;
-        }
+        var outer_total = Y.Array.reduce(
+            outer_nodes, 0, function(total, node) {
+                return total + node.nodes; });
         var inner_total = offline_nodes + added_nodes;
         var total_nodes = outer_total + inner_total;
         if (outer_total > 0) {
@@ -197,8 +193,8 @@
                 this._outer_paths = [];
             }
             var segment_start = 0;
-            for(var i in outer_nodes) {
-                var segment_size = 360 / outer_total * outer_nodes[i].nodes;
+            Y.Array.each(outer_nodes, function(outer_node, i) {
+                var segment_size = 360 / outer_total * outer_node.nodes;
                 var segment = [
                     this._center().x,
                     this._center().y,
@@ -209,7 +205,7 @@
                     var slice = r.path();
                     slice.attr({
                         segment: segment,
-                        fill: outer_nodes[i].colour,
+                        fill: outer_node.colour,
                         stroke: STROKE_COLOUR,
                         'stroke-width': STROKE_WIDTH
                         });
@@ -222,9 +218,9 @@
                             widget.fire(out);
                         },
                         null,
-                        outer_nodes[i].events.over,
-                        outer_nodes[i].events.out,
-                        outer_nodes[i].name,
+                        outer_node.events.over,
+                        outer_node.events.out,
+                        outer_node.name,
                         this
                         );
                     this._outer_paths.push(slice);
@@ -235,10 +231,11 @@
                         TRANSITION_TIME,
                         TRANSITION_EASING
                         );
-                    this._outer_paths[i].angle = segment_start - segment_size / 2;
+                    this._outer_paths[i].angle =
+                        segment_start - segment_size / 2;
                 }
                 segment_start += segment_size;
-            }
+            }, this);
         }
 
         var offline_circle_width = 0;
@@ -271,7 +268,7 @@
         }
 
         var added_circle_width = 0;
-        if (total_nodes == 0) {
+        if (total_nodes === 0) {
             added_circle_width = this._radius() - STROKE_WIDTH * 2;
         }
         else if (added_nodes > 0) {
@@ -295,7 +292,7 @@
                 this);
         }
         else {
-            if (added_nodes != total_nodes || total_nodes == 0) {
+            if (added_nodes !== total_nodes || total_nodes === 0) {
                 this._added_circle.toFront();
                 this._added_circle.animate(
                     {r: added_circle_width},
@@ -307,14 +304,15 @@
     },
 
     initializer: function(cfg) {
-        canvas_size = this.get('width') + STROKE_WIDTH * 2;
+        var canvas_size = this.get('width') + STROKE_WIDTH * 2;
         r = Raphael(this.get('node_id'), canvas_size, canvas_size);
         r.customAttributes.segment = function (x, y, r, a1, a2) {
             var flag = (a2 - a1) > 180;
-            if (a1 == 0 && a2 == 360) {
-                /* If the arc is a full circle we need to set the end point to less
-                   than 360 degrees otherwise the start and end points are
-                   calculated as the same location. */
+            if (a1 === 0 && a2 === 360) {
+                /* If the arc is a full circle we need to set the end
+                   point to less than 360 degrees otherwise the start
+                   and end points are calculated as the same
+                   location. */
                 a2 = 359.99;
             }
             a1 = (a1 % 360) * Math.PI / 180;
@@ -347,5 +345,5 @@
 
 module.NodesChartWidget = NodesChartWidget;
 
-}, '0.1', {'requires': ['event-custom', 'widget']}
+}, '0.1', {'requires': ['array-extras', 'event-custom', 'widget']}
 );

=== modified file 'src/maasserver/static/js/prefs.js'
--- src/maasserver/static/js/prefs.js	2012-04-13 05:24:39 +0000
+++ src/maasserver/static/js/prefs.js	2012-04-17 16:11:18 +0000
@@ -14,7 +14,9 @@
 // Only used to mockup io in tests.
 module._io = new Y.IO();
 
-var TokenWidget = function() {
+var TokenWidget;
+
+TokenWidget = function() {
     TokenWidget.superclass.constructor.apply(this, arguments);
 };
 

=== modified file 'src/maasserver/static/js/testing/testing.js'
--- src/maasserver/static/js/testing/testing.js	2012-03-26 15:47:49 +0000
+++ src/maasserver/static/js/testing/testing.js	2012-04-17 16:11:18 +0000
@@ -46,8 +46,9 @@
 
     tearDown: function() {
         this._setUp();
-        var func;
-        while (func = this._cleanups.pop()) { func(); }
+        while (this._cleanups.length) {
+            this._cleanups.pop()();
+        }
     },
 
    /**

=== modified file 'src/maasserver/static/js/testing/yui_test_conf.js'
--- src/maasserver/static/js/testing/yui_test_conf.js	2012-03-07 14:18:11 +0000
+++ src/maasserver/static/js/testing/yui_test_conf.js	2012-04-17 16:11:18 +0000
@@ -1,6 +1,5 @@
 var YUI_config = {
     debug: true,
     combine: false,
-    filter: 'raw',
+    filter: 'raw'
 };
-

=== modified file 'src/maasserver/static/js/tests/test_morph.js'
--- src/maasserver/static/js/tests/test_morph.js	2012-03-29 04:21:34 +0000
+++ src/maasserver/static/js/tests/test_morph.js	2012-04-17 16:11:18 +0000
@@ -17,8 +17,8 @@
         var cfg = {
             srcNode: '#panel-two',
             targetNode: '#panel-one'
-        }
-        morpher = new module.Morph(cfg);
+        };
+        var morpher = new module.Morph(cfg);
         Y.Assert.isFalse(
             Y.one('#panel-one').hasClass('hidden'),
             'The target panel should initially be visible');

=== modified file 'src/maasserver/static/js/tests/test_node_views.js'
--- src/maasserver/static/js/tests/test_node_views.js	2012-03-23 13:46:13 +0000
+++ src/maasserver/static/js/tests/test_node_views.js	2012-04-17 16:11:18 +0000
@@ -160,10 +160,14 @@
             '3 nodes reserved for named deployment.',
             Y.one('#reserved-nodes').get('text'),
             'The reserved text should be set');
+        // However, the reserved nodes message should be hidden for now.
+        Y.Assert.areEqual("none", view.reservedNode.getStyle("display"));
         Y.Assert.areEqual(
             '1 retired node not represented.',
             Y.one('#retired-nodes').get('text'),
             'The retired text should be set');
+        // However, the retired nodes message should be hidden for now.
+        Y.Assert.areEqual("none", view.retiredNode.getStyle("display"));
     },
 
     testUpdateNodeCreation: function() {

=== modified file 'src/maasserver/static/js/tests/test_nodes_chart.html'
--- src/maasserver/static/js/tests/test_nodes_chart.html	2012-03-19 03:24:16 +0000
+++ src/maasserver/static/js/tests/test_nodes_chart.html	2012-04-17 16:11:18 +0000
@@ -16,7 +16,7 @@
   </head>
   <body>
   <div id="chart"></div>
-  
+
   <span id="suite">maas.nodes_chart.tests</span>
   </body>
 </html>

=== modified file 'src/maasserver/static/js/tests/test_nodes_chart.js'
--- src/maasserver/static/js/tests/test_nodes_chart.js	2012-03-16 03:26:42 +0000
+++ src/maasserver/static/js/tests/test_nodes_chart.js	2012-04-17 16:11:18 +0000
@@ -22,7 +22,7 @@
 
 suite.add(new Y.maas.testing.TestCase({
     name: 'test-nodes-chart-widget-creation',
-    
+
     setUp : function () {
         this.chart = new module.NodesChartWidget(cfg);
     },
@@ -38,15 +38,15 @@
         Y.assert(this.chart._offline_circle[0].node);
         Y.assert(this.chart._added_circle[0].node);
     },
-    
+
     tearDown : function () {
-        Y.one('#chart').set('text', '')
-    },
+        Y.one('#chart').set('text', '');
+    }
 }));
 
 suite.add(new Y.maas.testing.TestCase({
     name: 'test-nodes-chart-events',
-    
+
     setUp : function () {
         this.chart = new module.NodesChartWidget(cfg);
     },
@@ -114,22 +114,21 @@
                 node: this.chart._added_circle[0].node
                 }
             ];
-        
-        
-        for (var e in events) {
-            this.chart.on(events[e].event, function(e, event) {
-                events[event].fired = true;
-            }, null, e);
-            Y.one(events[e].node).simulate(events[e].action);
+
+        Y.Array.each(events, function(event) {
+            this.chart.on(event.event, function(e, event) {
+                event.fired = true;
+            }, null, event);
+            Y.one(event.node).simulate(event.action);
             Y.Assert.isTrue(
-                events[e].fired,
-                'Event ' + events[e].event + ' should have fired');
-        }
+                event.fired,
+                'Event ' + event.event + ' should have fired');
+        }, this);
     },
-    
+
     tearDown : function () {
-        Y.one('#chart').set('text', '')
-    },
+        Y.one('#chart').set('text', '');
+    }
 }));
 
 namespace.suite = suite;

=== modified file 'src/maasserver/static/js/tests/test_prefs.html'
--- src/maasserver/static/js/tests/test_prefs.html	2012-03-15 13:58:32 +0000
+++ src/maasserver/static/js/tests/test_prefs.html	2012-04-17 16:11:18 +0000
@@ -30,15 +30,15 @@
       <ul class="list">
         <li class="bundle">
           <a class="delete-link right" href="#">Delete</a>
-          <input type="text" 
-                 value="Sample token 1" 
+          <input type="text"
+                 value="Sample token 1"
                  id="tokenkey1"
                  class="disabled" />
         </li>
         <li class="bundle">
           <a class="delete-link right" href="#">Delete</a>
-          <input type="text" 
-                 value="Sample token 2" 
+          <input type="text"
+                 value="Sample token 2"
                  id="tokenkey2"
                  class="disabled" />
         </li>

=== modified file 'src/maasserver/static/js/tests/test_user_panel.js'
--- src/maasserver/static/js/tests/test_user_panel.js	2012-02-21 23:29:11 +0000
+++ src/maasserver/static/js/tests/test_user_panel.js	2012-04-17 16:11:18 +0000
@@ -20,7 +20,8 @@
         module.createUserPanelWidget();
         Y.Assert.isNotNull(
             module._user_panel_singleton,
-            'module._user_panel_singleton is populated after the call to module.showAddNodeWidget.');
+            'module._user_panel_singleton is populated after the ' +
+            'call to module.showAddNodeWidget.');
     }
 }));
 
@@ -49,7 +50,8 @@
         link.simulate('click');
         Y.Assert.isFalse(
             overlay.get('visible'),
-            'If an element outside the panel is clicked the panel should hide.');
+            'If an element outside the panel is clicked the ' +
+            'panel should hide.');
     }
 }));
 

=== modified file 'src/maasserver/static/js/user_panel.js'
--- src/maasserver/static/js/user_panel.js	2012-02-21 23:29:11 +0000
+++ src/maasserver/static/js/user_panel.js	2012-04-17 16:11:18 +0000
@@ -21,7 +21,6 @@
  */
 module.createUserPanelWidget = function(event) {
     Y.Base.mix(Y.Overlay, [Y.WidgetAutohide]);
-    
     var cfg = {
         srcNode: '#user-options',
         align: {node:'#global-header',

=== modified file 'src/maasserver/static/js/utils.js'
--- src/maasserver/static/js/utils.js	2012-03-15 13:58:32 +0000
+++ src/maasserver/static/js/utils.js	2012-04-17 16:11:18 +0000
@@ -99,7 +99,9 @@
 module.red_flash = red_flash;
 
 
-var TitleEditWidget = function() {
+var TitleEditWidget;
+
+TitleEditWidget = function() {
     TitleEditWidget.superclass.constructor.apply(this, arguments);
 };
 

=== modified file 'src/provisioningserver/tests/test_api.py'
--- src/provisioningserver/tests/test_api.py	2012-04-17 09:20:48 +0000
+++ src/provisioningserver/tests/test_api.py	2012-04-17 16:11:18 +0000
@@ -21,7 +21,6 @@
     )
 from base64 import b64decode
 from contextlib import contextmanager
-from functools import partial
 
 from maasserver.testing.enum import map_enum
 from maastesting.factory import factory

=== modified file 'src/provisioningserver/tests/test_cobblercatcher.py'
--- src/provisioningserver/tests/test_cobblercatcher.py	2012-04-17 09:20:48 +0000
+++ src/provisioningserver/tests/test_cobblercatcher.py	2012-04-17 16:11:18 +0000
@@ -16,7 +16,6 @@
     ABCMeta,
     abstractmethod,
     )
-from unittest import skipIf
 from xmlrpclib import Fault
 
 from maastesting.factory import factory