From 5221e4dd3a831739a7408ed1afd10311650412ad Mon Sep 17 00:00:00 2001 From: Mehmet Bektas Date: Tue, 7 Jan 2020 15:09:59 +0100 Subject: [PATCH] fix eslint errors reported --- packages/base/src/manager-base.ts | 16 ++-- packages/base/src/utils.ts | 8 +- packages/base/src/widget.ts | 15 ++- packages/base/src/widget_layout.ts | 2 +- packages/base/src/widget_style.ts | 2 +- packages/base/test/src/dummy-manager.ts | 94 +++++++++---------- packages/controls/src/typedoc.d.ts | 10 +- packages/controls/src/widget_color.ts | 3 +- packages/controls/src/widget_controller.ts | 18 ++-- packages/controls/src/widget_date.ts | 4 +- packages/controls/src/widget_int.ts | 15 ++- packages/controls/src/widget_selection.ts | 28 +++--- packages/controls/test/src/dummy-manager.ts | 58 ++++++------ packages/html-manager/src/libembed.ts | 7 +- packages/html-manager/test/src/output_test.ts | 6 +- packages/jupyterlab-manager/src/manager.ts | 2 +- packages/jupyterlab-manager/src/output.ts | 3 +- packages/jupyterlab-manager/src/plugin.ts | 1 + packages/jupyterlab-manager/src/typedoc.d.ts | 6 +- 19 files changed, 143 insertions(+), 155 deletions(-) diff --git a/packages/base/src/manager-base.ts b/packages/base/src/manager-base.ts index f5e4ecd9f7..87da036d56 100644 --- a/packages/base/src/manager-base.ts +++ b/packages/base/src/manager-base.ts @@ -25,8 +25,7 @@ const PROTOCOL_MAJOR_VERSION = PROTOCOL_VERSION.split('.', 1)[0]; * Either a comm or a model_id must be provided. */ export -// tslint:disable-next-line:interface-name -interface ModelOptions { +interface IModelOptions { /** * Target name of the widget model to create. */ @@ -78,8 +77,7 @@ interface ModelOptions { * Either a comm or a model_id must be provided. */ export -// tslint:disable-next-line:interface-name -interface WidgetOptions { +interface IWidgetOptions { /** * Target name of the widget model to create. */ @@ -240,7 +238,7 @@ abstract class ManagerBase { * required and additional options are available. * @param serialized_state - serialized model attributes. */ - new_widget(options: WidgetOptions, serialized_state: any = {}): Promise { + new_widget(options: IWidgetOptions, serialized_state: any = {}): Promise { let commPromise; // we check to make sure the view information is provided, to help catch // backwards incompatibility errors. @@ -316,7 +314,7 @@ abstract class ManagerBase { * (err) => {console.error(err)}); * */ - async new_model(options: ModelOptions, serialized_state: any = {}): Promise { + async new_model(options: IModelOptions, serialized_state: any = {}): Promise { let model_id; if (options.model_id) { model_id = options.model_id; @@ -332,7 +330,7 @@ abstract class ManagerBase { return await modelPromise; } - async _make_model(options: ModelOptions, serialized_state: any = {}): Promise { + async _make_model(options: IModelOptions, serialized_state: any = {}): Promise { const model_id = options.model_id; const model_promise = this.loadClass( options.model_name, @@ -443,13 +441,13 @@ abstract class ManagerBase { }); } - const modelCreate: ModelOptions = { + const modelCreate: IModelOptions = { model_id: model_id, model_name: model.model_name, model_module: model.model_module, model_module_version: model.model_module_version }; - if (live_comms.hasOwnProperty(model_id)) { // live comm + if (Object.prototype.hasOwnProperty.call(live_comms, 'model_id')) { // live comm // This connects to an existing comm if it exists, and // should *not* send a comm open message. return this._create_comm(this.comm_target_name, model_id).then(comm => { diff --git a/packages/base/src/utils.ts b/packages/base/src/utils.ts index d5a18865ea..ceaaffc8ed 100644 --- a/packages/base/src/utils.ts +++ b/packages/base/src/utils.ts @@ -34,9 +34,9 @@ function isEqual(a: any, b: any) { * This is from code that Typescript 2.4 generates for a polyfill. */ export -const assign = (Object as any).assign || function(t: any) { - for (let i = 1; i < arguments.length; i++) { - const s = arguments[i]; +const assign = (Object as any).assign || function(t: any, ...args: any[]) { + for (let i = 1; i < args.length; i++) { + const s = args[i]; for (const p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; @@ -199,7 +199,7 @@ function remove_buffers(state: any): {state: any; buffers: ArrayBuffer[]; buffer } else if (isPlainObject(obj)) { for (const key in obj) { let is_cloned = false; - if (obj.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { const value = obj[key]; if (value) { if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) { diff --git a/packages/base/src/widget.ts b/packages/base/src/widget.ts index 7c2498bb36..b0b036e24b 100644 --- a/packages/base/src/widget.ts +++ b/packages/base/src/widget.ts @@ -208,7 +208,6 @@ class WidgetModel extends Backbone.Model { _handle_comm_msg(msg: KernelMessage.ICommMsgMsg): Promise { const data = msg.content.data as any; const method = data.method; - // tslint:disable-next-line:switch-default switch (method) { case 'update': this.state_change = this.state_change @@ -504,10 +503,9 @@ class WidgetModel extends Backbone.Model { * while the first will call foo only once. */ on_some_change(keys: string[], callback: (...args: any[]) => void, context: any) { - const scope = this; - this.on('change', function () { - if (keys.some(scope.hasChanged, scope)) { - callback.apply(context, arguments); + this.on('change', (...args) => { + if (keys.some(this.hasChanged, this)) { + callback.apply(context, args); } }, this); } @@ -601,7 +599,7 @@ class WidgetView extends NativeView { /** * Initializer, called at the end of the constructor. */ - initialize(parameters: WidgetView.InitializeParameters) { + initialize(parameters: WidgetView.IInitializeParameters) { this.listenTo(this.model, 'change', () => { const changed = Object.keys(this.model.changedAttributes() || {}); if (changed[0] === '_view_count' && changed.length === 1) { @@ -693,7 +691,7 @@ class WidgetView extends NativeView { } export namespace WidgetView { - export interface InitializeParameters extends Backbone.ViewOptions { + export interface IInitializeParameters extends Backbone.ViewOptions { options: any; } } @@ -789,7 +787,7 @@ class DOMWidgetView extends WidgetView { /** * Public constructor */ - initialize(parameters: WidgetView.InitializeParameters) { + initialize(parameters: WidgetView.IInitializeParameters) { super.initialize(parameters); this.listenTo(this.model, 'change:_dom_classes', (model: WidgetModel, new_classes: string[]) => { @@ -950,7 +948,6 @@ class DOMWidgetView extends WidgetView { } processPhosphorMessage(msg: Message) { - // tslint:disable-next-line:switch-default switch (msg.type) { case 'after-attach': this.trigger('displayed'); diff --git a/packages/base/src/widget_layout.ts b/packages/base/src/widget_layout.ts index 99f78dda43..e56de3c444 100644 --- a/packages/base/src/widget_layout.ts +++ b/packages/base/src/widget_layout.ts @@ -75,7 +75,7 @@ class LayoutView extends WidgetView { /** * Public constructor */ - initialize(parameters: WidgetView.InitializeParameters) { + initialize(parameters: WidgetView.IInitializeParameters) { this._traitNames = []; super.initialize(parameters); // Register the traits that live on the Python side diff --git a/packages/base/src/widget_style.ts b/packages/base/src/widget_style.ts index 90147bc5f6..ec8ac6113d 100644 --- a/packages/base/src/widget_style.ts +++ b/packages/base/src/widget_style.ts @@ -38,7 +38,7 @@ class StyleView extends WidgetView { /** * Public constructor */ - initialize(parameters: WidgetView.InitializeParameters) { + initialize(parameters: WidgetView.IInitializeParameters) { this._traitNames = []; super.initialize(parameters); // Register the traits that live on the Python side diff --git a/packages/base/test/src/dummy-manager.ts b/packages/base/test/src/dummy-manager.ts index 5441669392..a7dcc351d7 100644 --- a/packages/base/test/src/dummy-manager.ts +++ b/packages/base/test/src/dummy-manager.ts @@ -54,54 +54,6 @@ class MockComm implements widgets.IClassicComm { _on_close: Function = null; } -export -class DummyManager extends widgets.ManagerBase { - constructor() { - super(); - this.el = window.document.createElement('div'); - } - - display_view(msg: services.KernelMessage.IMessage, view: Backbone.View, options: any) { - // TODO: make this a spy - // TODO: return an html element - return Promise.resolve(view).then(view => { - this.el.appendChild(view.el); - view.on('remove', () => console.log('view removed', view)); - return view.el; - }); - } - - protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise { - if (moduleName === '@jupyter-widgets/base') { - if ((widgets as any)[className]) { - return Promise.resolve((widgets as any)[className]); - } else { - return Promise.reject(`Cannot find class ${className}`); - } - } else if (moduleName === 'test-widgets') { - if ((testWidgets as any)[className]) { - return Promise.resolve((testWidgets as any)[className]); - } else { - return Promise.reject(`Cannot find class ${className}`); - } - } else { - return Promise.reject(`Cannot find module ${moduleName}`); - } - } - - _get_comm_info() { - return Promise.resolve({}); - } - - _create_comm() { - return Promise.resolve(new MockComm()); - } - - el: HTMLElement; -} - -// Dummy widget with custom serializer and binary field - const typesToArray: {[key: string]: any} = { int8: Int8Array, int16: Int16Array, @@ -178,3 +130,49 @@ class BinaryWidgetView extends TestWidgetView { } const testWidgets = {TestWidget, TestWidgetView, BinaryWidget, BinaryWidgetView}; + +export +class DummyManager extends widgets.ManagerBase { + constructor() { + super(); + this.el = window.document.createElement('div'); + } + + display_view(msg: services.KernelMessage.IMessage, view: Backbone.View, options: any) { + // TODO: make this a spy + // TODO: return an html element + return Promise.resolve(view).then(view => { + this.el.appendChild(view.el); + view.on('remove', () => console.log('view removed', view)); + return view.el; + }); + } + + protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise { + if (moduleName === '@jupyter-widgets/base') { + if ((widgets as any)[className]) { + return Promise.resolve((widgets as any)[className]); + } else { + return Promise.reject(`Cannot find class ${className}`); + } + } else if (moduleName === 'test-widgets') { + if ((testWidgets as any)[className]) { + return Promise.resolve((testWidgets as any)[className]); + } else { + return Promise.reject(`Cannot find class ${className}`); + } + } else { + return Promise.reject(`Cannot find module ${moduleName}`); + } + } + + _get_comm_info() { + return Promise.resolve({}); + } + + _create_comm() { + return Promise.resolve(new MockComm()); + } + + el: HTMLElement; +} diff --git a/packages/controls/src/typedoc.d.ts b/packages/controls/src/typedoc.d.ts index 9639324a7a..aa2802f7e0 100644 --- a/packages/controls/src/typedoc.d.ts +++ b/packages/controls/src/typedoc.d.ts @@ -2,8 +2,8 @@ * TODO: remove the below typings after typedoc understands the lib compiler option * and the @types typing resolution. */ -/// -/// -/// -/// -/// +import "mathjax"; +import "requirejs"; +import "../node_modules/typescript/lib/lib.es2015.promise.d.ts"; +import "../node_modules/typescript/lib/lib.dom.d.ts"; +import "../node_modules/typescript/lib/lib.es5.d.ts"; diff --git a/packages/controls/src/widget_color.ts b/packages/controls/src/widget_color.ts index f27eaa7d8d..2cdbe22490 100644 --- a/packages/controls/src/widget_color.ts +++ b/packages/controls/src/widget_color.ts @@ -15,6 +15,7 @@ import { import * as _ from 'underscore'; +const named_colors: {[key: string]: string} = { aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc', bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00', chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff', darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9', darkgrey: '#a9a9a9', darkgreen: '#006400', darkkhaki: '#bdb76b', darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000', darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f', darkslategrey: '#2f4f4f', darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493', deepskyblue: '#00bfff', dimgray : '#696969', dimgrey : '#696969', dodgerblue: '#1e90ff', firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff', gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080', grey: '#808080', green: '#008000', greenyellow: '#adff2f', honeydew: '#f0fff0', hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa', lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff', lightgoldenrodyellow: '#fafad2', lightgreen: '#90ee90', lightgray: '#d3d3d3', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a', lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899', lightsteelblue: '#b0c4de', lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000', mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee', mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585', midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23', orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98', paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9', peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd', powderblue: '#b0e0e6', purple: '#800080', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1', saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d', silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090', slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f', steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee', wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32', }; export class ColorPickerModel extends CoreDescriptionModel { @@ -126,8 +127,6 @@ class ColorPickerView extends DescriptionView { private _colorpicker: HTMLInputElement; } -const named_colors: {[key: string]: string} = { aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc', bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00', chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff', darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9', darkgrey: '#a9a9a9', darkgreen: '#006400', darkkhaki: '#bdb76b', darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000', darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f', darkslategrey: '#2f4f4f', darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493', deepskyblue: '#00bfff', dimgray : '#696969', dimgrey : '#696969', dodgerblue: '#1e90ff', firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff', gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080', grey: '#808080', green: '#008000', greenyellow: '#adff2f', honeydew: '#f0fff0', hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa', lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff', lightgoldenrodyellow: '#fafad2', lightgreen: '#90ee90', lightgray: '#d3d3d3', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a', lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899', lightsteelblue: '#b0c4de', lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000', mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee', mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585', midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23', orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98', paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9', peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd', powderblue: '#b0e0e6', purple: '#800080', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1', saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d', silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090', slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f', steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee', wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32', }; - /* * From a valid html color (named color, 6-digits or 3-digits hex format) * return a 6-digits hexadecimal color #rrggbb. diff --git a/packages/controls/src/widget_controller.ts b/packages/controls/src/widget_controller.ts index ec68bd6a6e..48d8afc2e1 100644 --- a/packages/controls/src/widget_controller.ts +++ b/packages/controls/src/widget_controller.ts @@ -189,11 +189,10 @@ class ControllerModel extends CoreDOMWidgetModel { const index = this.get('index'); const pad = navigator.getGamepads()[index]; if (pad) { - const that = this; - this.setup(pad).then(function(controls) { - that.set(controls); - that.save_changes(); - window.requestAnimationFrame(that.update_loop.bind(that)); + this.setup(pad).then((controls) => { + this.set(controls); + this.save_changes(); + window.requestAnimationFrame(this.update_loop.bind(this)); }); } else { window.requestAnimationFrame(this.wait_loop.bind(this)); @@ -217,13 +216,12 @@ class ControllerModel extends CoreDOMWidgetModel { timestamp: pad.timestamp }); // Create buttons and axes. When done, start the update loop - const that = this; return utils.resolvePromisesDict({ - buttons: Promise.all(pad.buttons.map(function(btn, index) { - return that._create_button_model(index); + buttons: Promise.all(pad.buttons.map((btn, index) => { + return this._create_button_model(index); })), - axes: Promise.all(pad.axes.map(function(axis, index) { - return that._create_axis_model(index); + axes: Promise.all(pad.axes.map((axis, index) => { + return this._create_axis_model(index); })), }); } diff --git a/packages/controls/src/widget_date.ts b/packages/controls/src/widget_date.ts index 5ae322ffaa..ef31202f62 100644 --- a/packages/controls/src/widget_date.ts +++ b/packages/controls/src/widget_date.ts @@ -28,7 +28,7 @@ function serialize_date(value: Date) { } } -export interface SerializedDate { +export interface ISerializedDate { /** * Full year */ @@ -46,7 +46,7 @@ export interface SerializedDate { } export -function deserialize_date(value: SerializedDate) { +function deserialize_date(value: ISerializedDate) { if (value === null) { return null; } else { diff --git a/packages/controls/src/widget_int.ts b/packages/controls/src/widget_int.ts index d67291275f..824672855c 100644 --- a/packages/controls/src/widget_int.ts +++ b/packages/controls/src/widget_int.ts @@ -135,13 +135,12 @@ abstract class BaseIntSliderView extends DescriptionView { // JQuery slider option keys. These keys happen to have a // one-to-one mapping with the corresponding keys of the model. const jquery_slider_keys = ['step', 'disabled']; - const that = this; - that.$slider.slider({}); + this.$slider.slider({}); - jquery_slider_keys.forEach(function(key) { - const model_value = that.model.get(key); + jquery_slider_keys.forEach((key) => { + const model_value = this.model.get(key); if (model_value !== undefined) { - that.$slider.slider('option', key, model_value); + this.$slider.slider('option', key, model_value); } }); @@ -190,10 +189,10 @@ abstract class BaseIntSliderView extends DescriptionView { if (readout) { this.readout.style.display = ''; this.displayed.then(function() { - if (that.readout_overflow()) { - that.readout.classList.add('overflow'); + if (this.readout_overflow()) { + this.readout.classList.add('overflow'); } else { - that.readout.classList.remove('overflow'); + this.readout.classList.remove('overflow'); } }); } else { diff --git a/packages/controls/src/widget_selection.ts b/packages/controls/src/widget_selection.ts index 6d29ab1469..65daaf29c4 100644 --- a/packages/controls/src/widget_selection.ts +++ b/packages/controls/src/widget_selection.ts @@ -251,7 +251,6 @@ class RadioButtonsView extends DescriptionView { * changed by another view or by a state update from the back-end. */ update(options?: any) { - const view = this; const items: string[] = this.model.get('_options_labels'); const radios = _.pluck( this.container.querySelectorAll('input[type="radio"]'), @@ -271,10 +270,10 @@ class RadioButtonsView extends DescriptionView { if (stale && (options === undefined || options.updated_view !== this)) { // Add items to the DOM. this.container.textContent = ''; - items.forEach(function(item: any, index: number) { + items.forEach((item: any, index: number) => { const label = document.createElement('label'); label.textContent = item; - view.container.appendChild(label); + this.container.appendChild(label); const radio = document.createElement('input'); radio.setAttribute('type', 'radio'); @@ -283,14 +282,14 @@ class RadioButtonsView extends DescriptionView { label.appendChild(radio); }); } - items.forEach(function(item: any, index: number) { + items.forEach((item: any, index: number) => { const item_query = 'input[data-value="' + encodeURIComponent(item) + '"]'; - const radio = view.container.querySelectorAll(item_query); + const radio = this.container.querySelectorAll(item_query); if (radio.length > 0) { const radio_el = radio[0] as HTMLInputElement; - radio_el.checked = view.model.get('index') === index; - radio_el.disabled = view.model.get('disabled'); + radio_el.checked = this.model.get('index') === index; + radio_el.disabled = this.model.get('disabled'); } }); @@ -419,12 +418,11 @@ class ToggleButtonsView extends DescriptionView { * changed by another view or by a state update from the back-end. */ update(options?: any) { - const view = this; const items: string[] = this.model.get('_options_labels'); const icons = this.model.get('icons') || []; const previous_icons = this.model.previous('icons') || []; const previous_bstyle = (ToggleButtonsView.classMap as any)[this.model.previous('button_style')] || ''; - const tooltips = view.model.get('tooltips') || []; + const tooltips = this.model.get('tooltips') || []; const disabled = this.model.get('disabled'); const buttons = this.buttongroup.querySelectorAll('button'); const values = _.pluck(buttons, 'value'); @@ -468,16 +466,16 @@ class ToggleButtonsView extends DescriptionView { if (tooltips[index]) { button.setAttribute('title', tooltips[index]); } - view.update_style_traits(button); - view.buttongroup.appendChild(button); + this.update_style_traits(button); + this.buttongroup.appendChild(button); }); } // Select active button. - items.forEach(function(item: any, index: number) { + items.forEach((item: any, index: number) => { const item_query = '[data-value="' + encodeURIComponent(item) + '"]'; - const button = view.buttongroup.querySelector(item_query); - if (view.model.get('index') === index) { + const button = this.buttongroup.querySelector(item_query); + if (this.model.get('index') === index) { button.classList.add('mod-active'); } else { button.classList.remove('mod-active'); @@ -494,7 +492,7 @@ class ToggleButtonsView extends DescriptionView { update_style_traits(button?: HTMLButtonElement) { for (const name in this._css_state as string[]) { - if (this._css_state.hasOwnProperty(name)) { + if (Object.prototype.hasOwnProperty.call(this._css_state, 'name')) { if (name === 'margin') { this.buttongroup.style[name] = this._css_state[name]; } else if (name !== 'width') { diff --git a/packages/controls/test/src/dummy-manager.ts b/packages/controls/test/src/dummy-manager.ts index 2eeb77163b..baa7cf9e57 100644 --- a/packages/controls/test/src/dummy-manager.ts +++ b/packages/controls/test/src/dummy-manager.ts @@ -52,6 +52,35 @@ class MockComm { _on_close: Function = null; } +class TestWidget extends base.WidgetModel { + defaults() { + return {...super.defaults(), + _model_module: 'test-widgets', + _model_name: 'TestWidget', + _model_module_version: '1.0.0', + _view_module: 'test-widgets', + _view_name: 'TestWidgetView', + _view_module_version: '1.0.0', + _view_count: null as any, + }; + } +} + +class TestWidgetView extends base.WidgetView { + render() { + this._rendered += 1; + super.render(); + } + remove() { + this._removed +=1; + super.remove(); + } + _removed = 0; + _rendered = 0; +} + +const testWidgets = {TestWidget, TestWidgetView}; + export class DummyManager extends base.ManagerBase { constructor() { @@ -97,32 +126,3 @@ class DummyManager extends base.ManagerBase { el: HTMLElement; } - -class TestWidget extends base.WidgetModel { - defaults() { - return {...super.defaults(), - _model_module: 'test-widgets', - _model_name: 'TestWidget', - _model_module_version: '1.0.0', - _view_module: 'test-widgets', - _view_name: 'TestWidgetView', - _view_module_version: '1.0.0', - _view_count: null as any, - }; - } -} - -class TestWidgetView extends base.WidgetView { - render() { - this._rendered += 1; - super.render(); - } - remove() { - this._removed +=1; - super.remove(); - } - _removed = 0; - _rendered = 0; -} - -const testWidgets = {TestWidget, TestWidgetView}; diff --git a/packages/html-manager/src/libembed.ts b/packages/html-manager/src/libembed.ts index 6216657aff..39d7e8933f 100644 --- a/packages/html-manager/src/libembed.ts +++ b/packages/html-manager/src/libembed.ts @@ -1,7 +1,8 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. -declare let __webpack_public_path__: string; +declare let __webpack_public_path__: string; +// eslint-disable-next-line prefer-const __webpack_public_path__ = (window as any).__jupyter_widgets_assets_path__ || __webpack_public_path__; import 'font-awesome/css/font-awesome.css'; @@ -15,11 +16,11 @@ import { } from './index'; // Load json schema validator -const Ajv = require('ajv'); +import Ajv from 'ajv'; const widget_state_schema = require('@jupyter-widgets/schema').v2.state; const widget_view_schema = require('@jupyter-widgets/schema').v2.view; -const ajv = new Ajv() +const ajv = new Ajv(); const model_validate = ajv.compile(widget_state_schema); const view_validate = ajv.compile(widget_view_schema); diff --git a/packages/html-manager/test/src/output_test.ts b/packages/html-manager/test/src/output_test.ts index 132823bf67..4f306ec887 100644 --- a/packages/html-manager/test/src/output_test.ts +++ b/packages/html-manager/test/src/output_test.ts @@ -30,7 +30,6 @@ const newWidget = async (modelState: any): Promise => { describe('Output widget', function() { it('renders text output', async () => { - let elt: HTMLElement; const textValue = 'this-is-a-test\n' const modelState = { _view_module: '@jupyter-widgets/output', @@ -43,7 +42,7 @@ describe('Output widget', function() { ], } - elt = await newWidget(modelState) + const elt = await newWidget(modelState) expect(elt.textContent).to.equal(textValue) }) @@ -70,7 +69,6 @@ describe('Output widget', function() { it('renders widgets', async function() { - let elt; const modelState = { _view_module: "@jupyter-widgets/output", outputs: [ @@ -89,7 +87,7 @@ describe('Output widget', function() { ] }; - elt = document.createElement('div'); + const elt = document.createElement('div'); elt.className = 'widget-subarea'; document.body.appendChild(elt); const manager = new HTMLManager() diff --git a/packages/jupyterlab-manager/src/manager.ts b/packages/jupyterlab-manager/src/manager.ts index dd67c29c20..c3f5fbcb5c 100644 --- a/packages/jupyterlab-manager/src/manager.ts +++ b/packages/jupyterlab-manager/src/manager.ts @@ -243,7 +243,7 @@ class WidgetManager extends ManagerBase implements IDisposable { } const comm = await this._create_comm(this.comm_target_name, comm_id); - let msg_id: string; + let msg_id = ''; const info = new PromiseDelegate(); comm.on_msg((msg: KernelMessage.ICommMsgMsg) => { if ((msg.parent_header as any).msg_id === msg_id diff --git a/packages/jupyterlab-manager/src/output.ts b/packages/jupyterlab-manager/src/output.ts index 32b8fbcdb2..5ab3fdb3b5 100644 --- a/packages/jupyterlab-manager/src/output.ts +++ b/packages/jupyterlab-manager/src/output.ts @@ -96,11 +96,12 @@ class OutputModel extends outputBase.OutputModel { case 'execute_result': case 'display_data': case 'stream': - case 'error': + case 'error': { const model = msg.content as nbformat.IOutput; model.output_type = msgType as nbformat.OutputType; this._outputs.add(model); break; + } case 'clear_output': this.clear_output((msg as KernelMessage.IClearOutputMsg).content.wait); break; diff --git a/packages/jupyterlab-manager/src/plugin.ts b/packages/jupyterlab-manager/src/plugin.ts index e11f82ed53..6870b9cfae 100644 --- a/packages/jupyterlab-manager/src/plugin.ts +++ b/packages/jupyterlab-manager/src/plugin.ts @@ -293,6 +293,7 @@ function activateWidgetExtension( exports: () => { return new Promise((resolve, reject) => { (require as any).ensure(['@jupyter-widgets/controls'], (require: NodeRequire) => { + // eslint-disable-next-line @typescript-eslint/no-var-requires resolve(require('@jupyter-widgets/controls')); }, (err: any) => { diff --git a/packages/jupyterlab-manager/src/typedoc.d.ts b/packages/jupyterlab-manager/src/typedoc.d.ts index 490277c8e2..05ef1903ec 100644 --- a/packages/jupyterlab-manager/src/typedoc.d.ts +++ b/packages/jupyterlab-manager/src/typedoc.d.ts @@ -2,6 +2,6 @@ * TODO: remove the below typings after typedoc understands the lib compiler option * and the @types typing resolution. */ -/// -/// -/// +import "../node_modules/typescript/lib/lib.dom.d.ts"; +import "../node_modules/typescript/lib/lib.es5.d.ts"; +import "../node_modules/typescript/lib/lib.es2015.promise.d.ts";