From a4c47b80f79593a73519f7318d83675cfca94ee4 Mon Sep 17 00:00:00 2001 From: Elizabeth Elwell Date: Tue, 22 Mar 2016 14:32:13 +0000 Subject: [PATCH] Added eslint config to ironic-ui Set up package to use eslint-openstack-config for linting. Amended existing files to ensure they pass linting tests. Change-Id: I55dfe4cd9cdee99f19b80147df73f66951ca1372 --- .eslintignore | 2 + .eslintrc | 23 ++++++++++++ .gitignore | 5 +++ .../dashboard/admin/ironic/ironic.service.js | 18 +++++---- .../admin/ironic/node-actions.service.js | 8 ++-- .../node-details/node-details.controller.js | 16 ++++---- .../node-details.controller.spec.js | 2 +- .../ironic/node-list/node-list.controller.js | 37 +++++++++---------- package.json | 7 ++-- 9 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..76add878 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..85836639 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,23 @@ +# Enable eslint-plugin-angular +plugins: + - angular + +extends: openstack + +# Set up globals +globals: + angular: false + module: false + +env: + browser: true + jasmine: true + +rules: + angular/no-private-call: 0 + angular/no-services: + - 2 + - - $http + - $resource + - Restangular + angular/no-service-method: 0 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 974ccc2b..9d16c21e 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,8 @@ ChangeLog .secret_key_store *.lock + +# Node generated files +package/ +node_modules/ +npm-debug.log diff --git a/ironic_ui/static/dashboard/admin/ironic/ironic.service.js b/ironic_ui/static/dashboard/admin/ironic/ironic.service.js index a734becd..4eb49645 100755 --- a/ironic_ui/static/dashboard/admin/ironic/ironic.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/ironic.service.js @@ -61,7 +61,7 @@ return apiService.get('/api/ironic/nodes/') .error(function() { toastService.add('error', gettext('Unable to retrieve Ironic nodes.')); - }); + }); } /** @@ -90,7 +90,7 @@ function getPortsWithNode(uuid) { var config = { - 'params' : { + params : { node_id: uuid } }; @@ -103,14 +103,15 @@ * @name horizon.app.core.openstack-service-api.ironic.putNodeInMaintenanceMode * @description Put the node in maintenance mode. * - * http://docs.openstack.org/developer/ironic/webapi/v1.html#put--v1-nodes-(node_ident)-maintenance + * \href{http://docs.openstack.org/developer/ironic/webapi/v1.html# + * put--v1-nodes-(node_ident)-maintenance} * * @param {string} uuid – UUID or logical name of a node. */ function putNodeInMaintenanceMode(uuid, reason) { var data = { - maint_reason: (reason ? reason : gettext("No maintenance reason given.")) + maint_reason: reason ? reason : gettext("No maintenance reason given.") }; return apiService.patch('/api/ironic/nodes/' + uuid + '/maintenance', data).error(function() { toastService.add('error', @@ -122,7 +123,8 @@ * @name horizon.app.core.openstack-service-api.ironic.removeNodeFromMaintenanceMode * @description Remove the node from maintenance mode. * - * http://docs.openstack.org/developer/ironic/webapi/v1.html#delete--v1-nodes-(node_ident)-maintenance + * \href{http://docs.openstack.org/developer/ironic/webapi/v1.html# + * delete--v1-nodes-(node_ident)-maintenance} * * @param {string} uuid – UUID or logical name of a node. */ @@ -138,7 +140,8 @@ * @name horizon.app.core.openstack-service-api.ironic.powerOnNode * @description Set the power state of the node. * - * http://docs.openstack.org/developer/ironic/webapi/v1.html#put--v1-nodes-(node_ident)-states-power + * \href{http://docs.openstack.org/developer/ironic/webapi/v1.html# + * put--v1-nodes-(node_ident)-states-power} * * @param {string} uuid – UUID or logical name of a node. */ @@ -160,7 +163,8 @@ * @name horizon.app.core.openstack-service-api.ironic.powerOffNode * @description Set the power state of the node. * - * http://docs.openstack.org/developer/ironic/webapi/v1.html#put--v1-nodes-(node_ident)-states-power + * \href{http://docs.openstack.org/developer/ironic/webapi/v1.html# + * put--v1-nodes-(node_ident)-states-power} * * @param {string} uuid – UUID or logical name of a node. */ diff --git a/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js b/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js index 21a946fb..4f9bf571 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-actions.service.js @@ -16,8 +16,8 @@ */ (function () { 'use strict'; - - var POWER_STATE_ON ='power on'; + + var POWER_STATE_ON = 'power on'; var POWER_STATE_OFF = 'power off'; angular @@ -51,7 +51,7 @@ return $q.reject(gettext("Node is not powered off.")); } return ironic.powerOnNode(node.uuid).then( - function(response) { + function() { // Set power state to be indeterminate node.power_state = null; }, @@ -65,7 +65,7 @@ return $q.reject(gettext("Node is not powered on.")); } return ironic.powerOffNode(node.uuid).then( - function(response) { + function() { // Set power state to be indeterminate node.power_state = null; }, diff --git a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js index 643f7fe8..7aa06646 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.js @@ -52,7 +52,7 @@ ctrl.getVifPortId = getVifPortId; init(); - + /** * @name horizon.dashboard.admin.ironic.NodeDetailsController.init * @description Initialize the controller instance based on the current page url. @@ -88,11 +88,11 @@ * @description Retrieve the ports associated with a specified node, and store * them in the controller instance. * - * @param {string} node_id – Node name or UUID + * @param {string} nodeId – Node name or UUID * @return {void} */ - function retrievePorts(node_id) { - ironic.getPortsWithNode(node_id).then(function (response) { + function retrievePorts(nodeId) { + ironic.getPortsWithNode(nodeId).then(function (response) { ctrl.ports = response.data.items; }); } @@ -105,7 +105,7 @@ * @return {boolean} True if the string is an OpenStack UUID, otherwise false */ function isUuid(str) { - return str.match(ctrl.re_uuid) ? true : false; + return !!str.match(ctrl.re_uuid); } /** @@ -116,9 +116,9 @@ * @return {string} Value of vif_port_id property or "" if the property does not exist */ function getVifPortId(port) { - return (angular.isDefined(port.extra) && - angular.isDefined(port.extra.vif_port_id)) ? - port.extra.vif_port_id : ""; + return angular.isDefined(port.extra) && + angular.isDefined(port.extra.vif_port_id) + ? port.extra.vif_port_id : ""; } } diff --git a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.spec.js b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.spec.js index 5bbfda65..6687e9ef 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.spec.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-details/node-details.controller.spec.js @@ -118,5 +118,5 @@ expect(ctrl.getVifPortId(createPort(ctrl.node.uuid, 1, extra))). toEqual("port_uuid"); }); - }) + }); })(); diff --git a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js index 79a1f3fa..b9c863ad 100755 --- a/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js +++ b/ironic_ui/static/dashboard/admin/ironic/node-list/node-list.controller.js @@ -42,34 +42,34 @@ */ ctrl.nodeFacets = [ { - 'label': gettext('Name'), - 'name': 'name', - 'singleton': true + label: gettext('Name'), + name: 'name', + singleton: true }, { - 'label': gettext('UUID'), - 'name': 'uuid', - 'singleton': true + label: gettext('UUID'), + name: 'uuid', + singleton: true }, { - 'label': gettext('Power State'), - 'name': 'power_state', - 'singleton': true + label: gettext('Power State'), + name: 'power_state', + singleton: true }, { - 'label': gettext('Provisioning State'), - 'name': 'provision_state', - 'singleton': true + label: gettext('Provisioning State'), + name: 'provision_state', + singleton: true }, { - 'label': gettext('Maintenance'), - 'name': 'maintenance', - 'singleton': true + label: gettext('Maintenance'), + name: 'maintenance', + singleton: true }, { - 'label': gettext('Driver'), - 'name': 'driver', - 'singleton': true + label: gettext('Driver'), + name: 'driver', + singleton: true } ]; @@ -103,4 +103,3 @@ } })(); - diff --git a/package.json b/package.json index 328c2790..ef927a78 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "ironic-ui", "version": "1.0.0", "description": "Horizon plugin for OpenStack Ironic.", - "main": "index.html", "scripts": { "lint": "eslint ./" }, @@ -13,8 +12,8 @@ "author": "Openstack ", "license": "Apache-2.0", "devDependencies": { - "eslint": "1.9.0", - "eslint-config-openstack": "1.2.3", - "eslint-plugin-angular": "0.4.0" + "eslint": "^1.10.3", + "eslint-config-openstack": "^1.2.4", + "eslint-plugin-angular": "1.0.0" } }