From 46a51bd8db5cb141b6eb34202525331b12f6dcd8 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 1 May 2017 13:29:14 -0700 Subject: [PATCH] [Time API] Fixed static code analysis issues --- .../core/src/ui/TimeConductorController.js | 19 ++++---- src/api/telemetry/TelemetryAPI.js | 4 +- src/api/time/TimeAPI.js | 16 +++---- src/api/time/TimeAPISpec.js | 10 ++--- src/plugins/latestDataClock/LADClock.js | 2 +- src/plugins/latestDataClock/plugin.js | 2 +- .../localTimeSystem/LocalTimeFormat.js | 44 ++++++++++++------- .../localTimeSystem/LocalTimeSystem.js | 2 +- src/plugins/localTimeSystem/plugin.js | 2 +- src/plugins/timeConductor/plugin.js | 6 +-- src/plugins/utcTimeSystem/DurationFormat.js | 2 +- src/plugins/utcTimeSystem/UTCTimeFormat.js | 2 +- src/plugins/utcTimeSystem/plugin.js | 4 +- 13 files changed, 64 insertions(+), 51 deletions(-) diff --git a/platform/features/conductor/core/src/ui/TimeConductorController.js b/platform/features/conductor/core/src/ui/TimeConductorController.js index 863fd3236c..5ee579f0f1 100644 --- a/platform/features/conductor/core/src/ui/TimeConductorController.js +++ b/platform/features/conductor/core/src/ui/TimeConductorController.js @@ -19,6 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ +/* global console*/ define( [ @@ -107,7 +108,7 @@ define( }; // Construct the provided time system definitions - this.timeSystems = config.menuOptions.map(function (menuOption){ + this.timeSystems = config.menuOptions.map(function (menuOption) { return this.getTimeSystem(menuOption.timeSystem); }.bind(this)); @@ -175,7 +176,7 @@ define( * @param newOption * @param oldOption */ - TimeConductorController.prototype.selectMenuOption = function (newOption, oldOption){ + TimeConductorController.prototype.selectMenuOption = function (newOption, oldOption) { if (newOption !== oldOption) { var config = this.getConfig(this.timeAPI.timeSystem(), newOption.clock); @@ -235,7 +236,7 @@ define( timeSystemsForClocks[clockKey] = timeSystemsForClocks[clockKey] || []; timeSystemsForClocks[clockKey].push(timeSystem); } else if (menuOption.clock !== undefined) { - console.log('Unknown clock "' + clockKey + '", has it been registered?'); + console.error('Unknown clock "' + clockKey + '", has it been registered?'); } }.bind(this)); @@ -378,26 +379,24 @@ define( this.menu.selected = menuOption; //Try to find currently selected time system in time systems for clock - var selectedTimeSystem = timeSystems.filter(function (timeSystem){ + var selectedTimeSystem = timeSystems.filter(function (timeSystem) { return timeSystem.key === this.$scope.timeSystemModel.selected.key; }.bind(this))[0]; var config = this.getConfig(selectedTimeSystem, clock); - if (selectedTimeSystem === undefined){ + if (selectedTimeSystem === undefined) { selectedTimeSystem = timeSystems[0]; config = this.getConfig(selectedTimeSystem, clock); if (clock === undefined) { - var bounds = config.bounds; - this.timeAPI.timeSystem(selectedTimeSystem, bounds); + this.timeAPI.timeSystem(selectedTimeSystem, config.bounds); } else { //When time system changes, some start bounds need to be provided - var bounds = { + this.timeAPI.timeSystem(selectedTimeSystem, { start: clock.currentValue() + config.clockOffsets.start, end: clock.currentValue() + config.clockOffsets.end - }; - this.timeAPI.timeSystem(selectedTimeSystem, bounds); + }); } } diff --git a/src/api/telemetry/TelemetryAPI.js b/src/api/telemetry/TelemetryAPI.js index 3edf6a06e2..952e068562 100644 --- a/src/api/telemetry/TelemetryAPI.js +++ b/src/api/telemetry/TelemetryAPI.js @@ -323,7 +323,9 @@ define([ TelemetryAPI.prototype.addFormat = function (format) { this.MCT.legacyExtension('formats', { key: format.key, - implementation: function () { return format } + implementation: function () { + return format; + } }); }; diff --git a/src/api/time/TimeAPI.js b/src/api/time/TimeAPI.js index 9c96cf14bb..136f5af0ef 100644 --- a/src/api/time/TimeAPI.js +++ b/src/api/time/TimeAPI.js @@ -267,20 +267,20 @@ define(['EventEmitter'], function (EventEmitter) { throw "Please provide a time system"; } - if (typeof timeSystemOrKey === 'string'){ + if (typeof timeSystemOrKey === 'string') { timeSystem = this.timeSystems.get(timeSystemOrKey); - if (timeSystem === undefined){ + if (timeSystem === undefined) { throw "Unknown time system " + timeSystemOrKey + ". Has it been registered with 'addTimeSystem'?"; } - } else if (typeof timeSystemOrKey === 'object'){ + } else if (typeof timeSystemOrKey === 'object') { timeSystem = timeSystemOrKey; - if (!this.timeSystems.has(timeSystem.key)){ + if (!this.timeSystems.has(timeSystem.key)) { throw "Unknown time system " + timeSystem.key + ". Has it been registered with 'addTimeSystem'?"; } } else { - throw "Attempt to set invalid time system in Time API. Please provide a previously registered time system object or key" + throw "Attempt to set invalid time system in Time API. Please provide a previously registered time system object or key"; } this.system = timeSystem; @@ -353,7 +353,7 @@ define(['EventEmitter'], function (EventEmitter) { } } else if (typeof keyOrClock === 'object') { clock = keyOrClock; - if (!clocks.has(clock.key)){ + if (!this.clocks.has(clock.key)) { throw "Unknown clock '" + keyOrClock.key + "'. Has it been registered with 'addClock'?"; } } @@ -379,8 +379,8 @@ define(['EventEmitter'], function (EventEmitter) { */ this.emit("clock", this.activeClock); - } else if (arguments.length === 1){ - throw "When setting the clock, clock offsets must also be provided" + } else if (arguments.length === 1) { + throw "When setting the clock, clock offsets must also be provided"; } return this.activeClock; diff --git a/src/api/time/TimeAPISpec.js b/src/api/time/TimeAPISpec.js index d2ea55e0ed..995e519beb 100644 --- a/src/api/time/TimeAPISpec.js +++ b/src/api/time/TimeAPISpec.js @@ -68,7 +68,7 @@ define(['./TimeAPI'], function (TimeAPI) { it("Allows setting of previously registered time system with bounds", function () { api.addTimeSystem(timeSystem); expect(api.timeSystem()).not.toBe(timeSystemKey); - expect(function() { + expect(function () { api.timeSystem(timeSystemKey, bounds); }).not.toThrow(); expect(api.timeSystem()).toBe(timeSystemKey); @@ -78,7 +78,7 @@ define(['./TimeAPI'], function (TimeAPI) { api.addTimeSystem(timeSystem); expect(api.timeSystem()).not.toBe(timeSystemKey); expect(function () { - api.timeSystem(timeSystemKey) + api.timeSystem(timeSystemKey); }).toThrow(); expect(api.timeSystem()).not.toBe(timeSystemKey); }); @@ -130,7 +130,7 @@ define(['./TimeAPI'], function (TimeAPI) { "off", "currentValue" ]); - mockTickSource.key = 'mockTickSource' + mockTickSource.key = 'mockTickSource'; }); describe(" when enabling a tick source", function () { @@ -139,7 +139,7 @@ define(['./TimeAPI'], function (TimeAPI) { var mockOffsets = { start: 0, end: 0 - } + }; beforeEach(function () { mockTickSource = jasmine.createSpyObj("clock", [ @@ -205,7 +205,7 @@ define(['./TimeAPI'], function (TimeAPI) { api.on("bounds", boundsCallback); - tickCallback = mockTickSource.on.mostRecentCall.args[1] + tickCallback = mockTickSource.on.mostRecentCall.args[1]; tickCallback(1000); expect(boundsCallback).toHaveBeenCalledWith({ start: 900, diff --git a/src/plugins/latestDataClock/LADClock.js b/src/plugins/latestDataClock/LADClock.js index 08e92986d8..9ec6dc0489 100644 --- a/src/plugins/latestDataClock/LADClock.js +++ b/src/plugins/latestDataClock/LADClock.js @@ -27,7 +27,7 @@ define(['../../../src/plugins/utcTimeSystem/LocalClock'], function (LocalClock) * It DOES NOT tick on receipt of data. * @constructor */ - function LADClock (period) { + function LADClock(period) { LocalClock.call(this, period); this.key = 'test-lad'; diff --git a/src/plugins/latestDataClock/plugin.js b/src/plugins/latestDataClock/plugin.js index 0cbcccce20..a1f8f71a76 100644 --- a/src/plugins/latestDataClock/plugin.js +++ b/src/plugins/latestDataClock/plugin.js @@ -28,6 +28,6 @@ define([ return function () { return function (openmct) { openmct.time.addClock(new LADClock()); - } + }; }; }); diff --git a/src/plugins/localTimeSystem/LocalTimeFormat.js b/src/plugins/localTimeSystem/LocalTimeFormat.js index a9b26ed4ef..b1949da35c 100644 --- a/src/plugins/localTimeSystem/LocalTimeFormat.js +++ b/src/plugins/localTimeSystem/LocalTimeFormat.js @@ -56,8 +56,8 @@ define([ * the threshold required. * @private */ - function getScaledFormat (d) { - var m = moment.utc(d); + function getScaledFormat(d) { + var momentified = moment.utc(d); /** * Uses logic from d3 Time-Scales, v3 of the API. See * https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md @@ -65,23 +65,35 @@ define([ * Licensed */ return [ - [".SSS", function(m) { return m.milliseconds(); }], - [":ss", function(m) { return m.seconds(); }], - ["hh:mma", function(m) { return m.minutes(); }], - ["hha", function(m) { return m.hours(); }], - ["ddd DD", function(m) { - return m.days() && - m.date() != 1; + [".SSS", function (m) { + return m.milliseconds(); }], - ["MMM DD", function(m) { return m.date() != 1; }], - ["MMMM", function(m) { + [":ss", function (m) { + return m.seconds(); + }], + ["hh:mma", function (m) { + return m.minutes(); + }], + ["hha", function (m) { + return m.hours(); + }], + ["ddd DD", function (m) { + return m.days() && + m.date() !== 1; + }], + ["MMM DD", function (m) { + return m.date() !== 1; + }], + ["MMMM", function (m) { return m.month(); }], - ["YYYY", function() { return true; }] - ].filter(function (row){ - return row[1](m); + ["YYYY", function () { + return true; + }] + ].filter(function (row) { + return row[1](momentified); })[0][0]; - }; + } /** * @@ -91,7 +103,7 @@ define([ * @returns {string} the formatted date */ LocalTimeFormat.prototype.format = function (value, scale) { - if (scale !== undefined){ + if (scale !== undefined) { var scaledFormat = getScaledFormat(value, scale); if (scaledFormat) { return moment.utc(value).format(scaledFormat); diff --git a/src/plugins/localTimeSystem/LocalTimeSystem.js b/src/plugins/localTimeSystem/LocalTimeSystem.js index 0c8d2fbca4..3f08d07fe4 100644 --- a/src/plugins/localTimeSystem/LocalTimeSystem.js +++ b/src/plugins/localTimeSystem/LocalTimeSystem.js @@ -27,7 +27,7 @@ define([], function () { * @implements TimeSystem * @constructor */ - function LocalTimeSystem () { + function LocalTimeSystem() { /** * Some metadata, which will be used to identify the time system in diff --git a/src/plugins/localTimeSystem/plugin.js b/src/plugins/localTimeSystem/plugin.js index 4cee78cce3..bac85a0ac6 100644 --- a/src/plugins/localTimeSystem/plugin.js +++ b/src/plugins/localTimeSystem/plugin.js @@ -35,6 +35,6 @@ define([ key: 'local-format', implementation: LocalTimeFormat }); - } + }; }; }); diff --git a/src/plugins/timeConductor/plugin.js b/src/plugins/timeConductor/plugin.js index aaedd2da2c..7cdc893bf5 100644 --- a/src/plugins/timeConductor/plugin.js +++ b/src/plugins/timeConductor/plugin.js @@ -81,13 +81,13 @@ define([], function () { bounds = { start: clock.currentValue() + clockOffsets.start, end: clock.currentValue() + clockOffsets.end - } + }; } openmct.time.timeSystem(timeSystem, bounds); } else { throw 'Invalid time conductor configuration. Please define defaults for time system "' + timeSystem.key + '"'; } }); - } - } + }; + }; }); diff --git a/src/plugins/utcTimeSystem/DurationFormat.js b/src/plugins/utcTimeSystem/DurationFormat.js index ecc9701b9d..029b588071 100644 --- a/src/plugins/utcTimeSystem/DurationFormat.js +++ b/src/plugins/utcTimeSystem/DurationFormat.js @@ -44,7 +44,7 @@ define([ * @memberof platform/commonUI/formats */ function DurationFormat() { - this.key = "duration" + this.key = "duration"; } DurationFormat.prototype.format = function (value) { diff --git a/src/plugins/utcTimeSystem/UTCTimeFormat.js b/src/plugins/utcTimeSystem/UTCTimeFormat.js index 6a8ebb9c39..5bc49afc32 100644 --- a/src/plugins/utcTimeSystem/UTCTimeFormat.js +++ b/src/plugins/utcTimeSystem/UTCTimeFormat.js @@ -129,4 +129,4 @@ define([ }; return UTCTimeFormat; -}); \ No newline at end of file +}); diff --git a/src/plugins/utcTimeSystem/plugin.js b/src/plugins/utcTimeSystem/plugin.js index 0dfc53cd20..e237f352f1 100644 --- a/src/plugins/utcTimeSystem/plugin.js +++ b/src/plugins/utcTimeSystem/plugin.js @@ -24,7 +24,7 @@ define([ "./UTCTimeSystem", "./LocalClock", "./UTCTimeFormat", - "./DurationFormat", + "./DurationFormat" ], function ( UTCTimeSystem, LocalClock, @@ -47,6 +47,6 @@ define([ "key": "DEFAULT_TIME_FORMAT", "value": "utc" }); - } + }; }; });