Skip to content

Commit

Permalink
fix eslint warnings reported
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektas committed Jan 7, 2020
1 parent 5221e4d commit 59d8492
Show file tree
Hide file tree
Showing 50 changed files with 509 additions and 502 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"@typescript-eslint/interface-name-prefix": [
"error", { "prefixWithI": "always" }
],
"@typescript-eslint/no-unused-vars": [
"warn", { "args": "none" }
],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-explicit-any": "off",
Expand Down
2 changes: 1 addition & 1 deletion examples/web3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', async function(event) {
// Run backend code to create the widgets. You could also create the
// widgets in the frontend, like the other widget examples demonstrate.
const execution = kernel.requestExecute({ code: code });
execution.onIOPub = (msg) => {
execution.onIOPub = (msg): void => {
// If we have a display message, display the widget.
if (KernelMessage.isDisplayDataMsg(msg)) {
const widgetData: any = msg.content.data['application/vnd.jupyter.widget-view+json'];
Expand Down
2 changes: 1 addition & 1 deletion examples/web3/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WidgetManager extends HTMLManager {
});
}

display_view(msg: any, view: DOMWidgetView, options: any) {
display_view(msg: any, view: DOMWidgetView, options: any): Promise<base.DOMWidgetView> {
return Promise.resolve(view).then((view) => {
pWidget.Widget.attach(view.pWidget, this.el);
view.on('remove', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/backbone-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import * as utils from './utils';
// anyone who needs to know about the change in state. The heart of the beast.
// This *MUST* be called with the model as the `this` context.
export
function set(key: string|{}, val: any, options: any) {
function set(key: string|{}, val: any, options: any): any {
/* tslint:disable:no-invalid-this */
if (key == null) {
return this;
Expand Down
8 changes: 5 additions & 3 deletions packages/base/src/manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
PROTOCOL_VERSION
} from './version';

import { ReadonlyPartialJSONValue } from '@lumino/coreutils';

const PROTOCOL_MAJOR_VERSION = PROTOCOL_VERSION.split('.', 1)[0];

/**
Expand Down Expand Up @@ -467,7 +469,7 @@ abstract class ManagerBase<T> {
* Disconnect the widget manager from the kernel, setting each model's comm
* as dead.
*/
disconnect() {
disconnect(): void {
Object.keys(this._models).forEach((i) => {
this._models[i].then(model => { model.comm_live = false; });
});
Expand Down Expand Up @@ -521,7 +523,7 @@ abstract class ManagerBase<T> {
*
* @returns {*} A copy of the state, with its 'state' attribute filtered
*/
protected filterExistingModelState(serialized_state: any) {
protected filterExistingModelState(serialized_state: any): any {
let models = serialized_state.state as {[key: string]: any};
models = Object.keys(models)
.filter((model_id) => {
Expand Down Expand Up @@ -559,7 +561,7 @@ interface IStateOptions {
* @jupyter-widgets/schema package.
*/
export
function serialize_state(models: WidgetModel[], options: IStateOptions = {}) {
function serialize_state(models: WidgetModel[], options: IStateOptions = {}): ReadonlyPartialJSONValue {
const state: {[key: string]: any} = {};
models.forEach(model => {
const model_id = model.model_id;
Expand Down
16 changes: 8 additions & 8 deletions packages/base/src/nativeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const matchesSelector = ElementProto.matches ||
ElementProto['mozMatchesSelector'] ||
ElementProto['msMatchesSelector'] ||
ElementProto['oMatchesSelector'] ||
function matches(selector: string) {
function matches(selector: string): boolean {
/* tslint:disable:no-invalid-this */
const matches = (this.document || this.ownerDocument).querySelectorAll(selector);
let i = matches.length;
Expand All @@ -63,21 +63,21 @@ interface IDOMEvent {

export
class NativeView<T extends Backbone.Model> extends Backbone.View<T> {
_removeElement() {
_removeElement(): void {
this.undelegateEvents();
if (this.el.parentNode) {
this.el.parentNode.removeChild(this.el);
}
}

// Apply the `element` to the view.
_setElement(element: HTMLElement) {
_setElement(element: HTMLElement): void {
this.el = element;
}

// Set a hash of attributes to the view's `el`. We use the "prop" version
// if available, falling back to `setAttribute` for the catch-all.
_setAttributes(attrs: {[key: string]: string}) {
_setAttributes(attrs: {[key: string]: string}): void {
for (const attr in attrs) {
attr in this.el ? this.el[attr] = attrs[attr] : this.el.setAttribute(attr, attrs[attr]);
}
Expand All @@ -97,7 +97,7 @@ class NativeView<T extends Backbone.Model> extends Backbone.View<T> {
* https://github.com/jquery/jquery/blob/7d21f02b9ec9f655583e898350badf89165ed4d5/src/event.js#L442
* for some similar exceptional cases).
*/
delegate(eventName: string, selector: any, listener: any) {
delegate(eventName: string, selector: any, listener: any): any {
if (typeof selector !== 'string') {
listener = selector;
selector = null;
Expand All @@ -111,7 +111,7 @@ class NativeView<T extends Backbone.Model> extends Backbone.View<T> {
}

const root = this.el;
const handler = selector ? function (e: Event) {
const handler = selector ? function (e: Event): any {
let node = (e.target as HTMLElement) || (e.srcElement as HTMLElement);
for (; node && node !== root; node = node.parentNode as HTMLElement) {
if (matchesSelector.call(node, selector)) {
Expand All @@ -132,7 +132,7 @@ class NativeView<T extends Backbone.Model> extends Backbone.View<T> {

// Remove a single delegated event. Either `eventName` or `selector` must
// be included, `selector` and `listener` are optional.
undelegate(eventName: string, selector?: any, listener?: any) {
undelegate(eventName: string, selector?: any, listener?: any): NativeView<T> {
if (typeof selector === 'function') {
listener = selector;
selector = null;
Expand Down Expand Up @@ -160,7 +160,7 @@ class NativeView<T extends Backbone.Model> extends Backbone.View<T> {
}

// Remove all events created with `delegate` from `el`
undelegateEvents() {
undelegateEvents(): NativeView<T> {
if (this.el && this._domEvents) {
const len = this._domEvents.length;
for (let i = 0; i < len; i++) {
Expand Down
20 changes: 10 additions & 10 deletions packages/base/src/services-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace shims {
* Hookup kernel events.
* @param {Kernel.IKernel} jsServicesKernel - @jupyterlab/services Kernel.IKernel instance
*/
init_kernel(jsServicesKernel: Kernel.IKernelConnection) {
init_kernel(jsServicesKernel: Kernel.IKernelConnection): void {
this.kernel = jsServicesKernel; // These aren't really the same.
this.jsServicesKernel = jsServicesKernel;
}
Expand All @@ -120,7 +120,7 @@ namespace shims {
* @param {(Comm, object) => void} f - callback that is called when the
* comm is made. Signature of f(comm, msg).
*/
register_target(target_name: string, f: (comm: Comm, data: {}) => void) {
register_target(target_name: string, f: (comm: Comm, data: {}) => void): void {
const handle = this.jsServicesKernel.registerCommTarget(target_name,
(jsServicesComm, msg) => {
// Create the comm.
Expand All @@ -143,7 +143,7 @@ namespace shims {
* Unregisters a comm target
* @param {string} target_name
*/
unregister_target(target_name: string, f: (comm: Comm, data: {}) => void) {
unregister_target(target_name: string, f: (comm: Comm, data: {}) => void): void {
const handle = this.targets[target_name];
handle.dispose();
delete this.targets[target_name];
Expand All @@ -152,7 +152,7 @@ namespace shims {
/**
* Register a comm in the mapping
*/
register_comm(comm: Comm) {
register_comm(comm: Comm): string {
this.comms[comm.comm_id] = Promise.resolve(comm);
comm.kernel = this.kernel;
return comm.comm_id;
Expand All @@ -178,15 +178,15 @@ namespace shims {
* Comm id
* @return {string}
*/
get comm_id() {
get comm_id(): string {
return this.jsServicesComm.commId;
}

/**
* Target name
* @return {string}
*/
get target_name() {
get target_name(): string {
return this.jsServicesComm.targetName;
}

Expand Down Expand Up @@ -251,22 +251,22 @@ namespace shims {
* @param @jupyterlab/services IKernelFuture instance
* @param callbacks
*/
_hookupCallbacks(future: Kernel.IShellFuture, callbacks: ICallbacks) {
_hookupCallbacks(future: Kernel.IShellFuture, callbacks: ICallbacks): void {
if (callbacks) {
future.onReply = function(msg) {
future.onReply = function(msg): void {
if (callbacks.shell && callbacks.shell.reply) {
callbacks.shell.reply(msg);
}
// TODO: Handle payloads. See https://github.com/jupyter/notebook/blob/master/notebook/static/services/kernels/kernel.js#L923-L947
};

future.onStdin = function(msg) {
future.onStdin = function(msg): void {
if (callbacks.input) {
callbacks.input(msg);
}
};

future.onIOPub = function(msg) {
future.onIOPub = function(msg): void {
if (callbacks.iopub) {
if (callbacks.iopub.status && msg.header.msg_type === 'status') {
callbacks.iopub.status(msg);
Expand Down
10 changes: 5 additions & 5 deletions packages/base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function difference(a: string[], b: string[]): string[] {
* Compare two objects deeply to see if they are equal.
*/
export
function isEqual(a: any, b: any) {
function isEqual(a: any, b: any): boolean {
return _isEqual(a, b);
}

Expand All @@ -34,7 +34,7 @@ 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, ...args: any[]) {
const assign = (Object as any).assign || function(t: any, ...args: any[]): any {
for (let i = 1; i < args.length; i++) {
const s = args[i];
for (const p in s) {
Expand Down Expand Up @@ -113,7 +113,7 @@ function resolvePromisesDict<V>(d: Dict<PromiseLike<V>>): Promise<Dict<V>> {
*/
export
function reject(message: string, log: boolean) {
return function promiseRejection(error: any) {
return function promiseRejection(error: any): never {
if (log) {
console.error(new Error(message));
}
Expand All @@ -131,7 +131,7 @@ function reject(message: string, log: boolean) {
* Will lead to {a: 1, b: {data: array1}, c: [0, array2]}
*/
export
function put_buffers(state: any, buffer_paths: (string | number)[][], buffers: DataView[]) {
function put_buffers(state: any, buffer_paths: (string | number)[][], buffers: DataView[]): void {
for (let i=0; i < buffer_paths.length; i++) {
const buffer_path = buffer_paths[i];
// say we want to set state[x][y][z] = buffers[i]
Expand Down Expand Up @@ -162,7 +162,7 @@ function remove_buffers(state: any): {state: any; buffers: ArrayBuffer[]; buffer
// if we need to remove an object from a list, we need to clone that list, otherwise we may modify
// the internal state of the widget model
// however, we do not want to clone everything, for performance
function remove(obj: any, path: (string | number)[]) {
function remove(obj: any, path: (string | number)[]): any {
if (obj.toJSON) {
// We need to get the JSON form of the object before recursing.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/viewlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class ViewList<T> {
this.initialize(create_view, remove_view, context);
}

initialize(create_view: (model: any, index: any) => T | Promise<T>, remove_view: (view: T) => void, context: any) {
initialize(create_view: (model: any, index: any) => T | Promise<T>, remove_view: (view: T) => void, context: any): void {
this._handler_context = context || this;
this._models = [];
this.views = []; // list of promises for views
this._create_view = create_view;
this._remove_view = remove_view || function(view) { (view as any).remove(); };
this._remove_view = remove_view || function(view): void { (view as any).remove(); };
}

/**
Expand Down
Loading

0 comments on commit 59d8492

Please sign in to comment.