Skip to content

Commit 3df0ef8

Browse files
committed
Fix linting
1 parent 0efa851 commit 3df0ef8

File tree

8 files changed

+189
-130
lines changed

8 files changed

+189
-130
lines changed

.eslintrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
plugins: ['@typescript-eslint'],
1414
rules: {
1515
'@typescript-eslint/naming-convention': [
16-
'error',
16+
'warn',
1717
{
1818
'selector': 'interface',
1919
'format': ['PascalCase'],
@@ -33,7 +33,8 @@ module.exports = {
3333
{ avoidEscape: true, allowTemplateLiterals: false }
3434
],
3535
curly: ['error', 'all'],
36-
eqeqeq: 'error',
36+
semi: ['warn', 'never'],
37+
eqeqeq: 'warn',
3738
'prefer-arrow-callback': 'error'
3839
}
3940
};

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
**/lib
44
**/package.json
55
jupyter_bokeh
6+
src/extension.ts

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"singleQuote": true,
33
"trailingComma": "none",
4-
"arrowParens": "avoid"
4+
"arrowParens": "avoid",
5+
"semi": false
56
}

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {extension} from "./plugin"
1+
import { extension } from './plugin'
22
export default extension
33

4-
export * from "./widgets"
4+
export * from './widgets'

src/manager.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {IDisposable} from "@lumino/disposable"
2-
import {DocumentRegistry} from "@jupyterlab/docregistry"
1+
import { IDisposable } from '@lumino/disposable'
2+
import { DocumentRegistry } from '@jupyterlab/docregistry'
33

44
/**
55
* A micro manager that contains the document context
@@ -16,19 +16,21 @@ export class ContextManager implements IDisposable {
1616
}
1717

1818
get context(): Context {
19-
if (this._context != null)
19+
if (this._context != null) {
2020
return this._context
21-
else
22-
throw new Error("context was already disposed")
21+
} else {
22+
throw new Error('context was already disposed')
23+
}
2324
}
2425

2526
get isDisposed(): boolean {
2627
return this._context == null
2728
}
2829

2930
dispose(): void {
30-
if (this.isDisposed)
31+
if (this.isDisposed) {
3132
return
33+
}
3234
this._context = null
3335
}
3436
}

src/plugin.ts

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
1-
import {DocumentRegistry} from "@jupyterlab/docregistry"
2-
import {INotebookModel, NotebookPanel} from "@jupyterlab/notebook"
3-
import {JupyterFrontEndPlugin, JupyterFrontEnd} from "@jupyterlab/application"
4-
import {IJupyterWidgetRegistry} from "@jupyter-widgets/base"
5-
import {IDisposable, DisposableDelegate} from "@lumino/disposable"
1+
import { DocumentRegistry } from '@jupyterlab/docregistry'
2+
import { INotebookModel, NotebookPanel } from '@jupyterlab/notebook'
3+
import { JupyterFrontEndPlugin, JupyterFrontEnd } from '@jupyterlab/application'
4+
import { IJupyterWidgetRegistry } from '@jupyter-widgets/base'
5+
import { IDisposable, DisposableDelegate } from '@lumino/disposable'
66

7-
import {ContextManager} from "./manager"
7+
import { ContextManager } from './manager'
88
import {
99
BokehJSExec,
1010
BokehJSLoad,
1111
BOKEHJS_EXEC_MIME_TYPE,
12-
BOKEHJS_LOAD_MIME_TYPE} from "./renderer"
12+
BOKEHJS_LOAD_MIME_TYPE
13+
} from './renderer'
1314

14-
export type INBWidgetExtension = DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel>
15+
export type INBWidgetExtension = DocumentRegistry.IWidgetExtension<
16+
NotebookPanel,
17+
INotebookModel
18+
>
1519

1620
export class NBWidgetExtension implements INBWidgetExtension {
17-
createNew(nb: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
21+
createNew(
22+
nb: NotebookPanel,
23+
context: DocumentRegistry.IContext<INotebookModel>
24+
): IDisposable {
1825
const manager = new ContextManager(context)
1926

20-
nb.content.rendermime.addFactory({
21-
safe: false,
22-
mimeTypes: [BOKEHJS_LOAD_MIME_TYPE],
23-
createRenderer: (options) => new BokehJSLoad(options),
24-
}, 0)
27+
nb.content.rendermime.addFactory(
28+
{
29+
safe: false,
30+
mimeTypes: [BOKEHJS_LOAD_MIME_TYPE],
31+
createRenderer: options => new BokehJSLoad(options)
32+
},
33+
0
34+
)
2535

2636
// the rank has to be -1, so that the priority is higher than the
2737
// default javascript mime extension (rank=0)
28-
nb.content.rendermime.addFactory({
29-
safe: false,
30-
mimeTypes: [BOKEHJS_EXEC_MIME_TYPE],
31-
createRenderer: (options) => new BokehJSExec(options, manager),
32-
}, -1)
38+
nb.content.rendermime.addFactory(
39+
{
40+
safe: false,
41+
mimeTypes: [BOKEHJS_EXEC_MIME_TYPE],
42+
createRenderer: options => new BokehJSExec(options, manager)
43+
},
44+
-1
45+
)
3346

3447
return new DisposableDelegate(() => {
3548
if (nb.content.rendermime) {
@@ -40,24 +53,24 @@ export class NBWidgetExtension implements INBWidgetExtension {
4053
}
4154
}
4255

43-
import {name, version} from "./metadata"
44-
import {BokehModel, BokehView} from "./widgets"
56+
import { name, version } from './metadata'
57+
import { BokehModel, BokehView } from './widgets'
4558

4659
export const extension: JupyterFrontEndPlugin<void> = {
4760
id: name,
4861
requires: [IJupyterWidgetRegistry],
4962
activate: (app: JupyterFrontEnd, widgets: IJupyterWidgetRegistry) => {
5063
// this adds the Bokeh widget extension onto Notebooks specifically
51-
app.docRegistry.addWidgetExtension("Notebook", new NBWidgetExtension())
64+
app.docRegistry.addWidgetExtension('Notebook', new NBWidgetExtension())
5265

5366
widgets.registerWidget({
5467
name,
5568
version,
5669
exports: {
5770
BokehModel: BokehModel as any,
58-
BokehView: BokehView as any,
59-
},
71+
BokehView: BokehView as any
72+
}
6073
})
6174
},
62-
autoStart: true,
75+
autoStart: true
6376
}

src/renderer.ts

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import {IRenderMime} from "@jupyterlab/rendermime-interfaces"
2-
import {KernelMessage, Kernel} from "@jupyterlab/services"
3-
import {ReadonlyJSONObject} from "@lumino/coreutils"
4-
import {Widget} from "@lumino/widgets"
5-
import {ContextManager} from "./manager"
1+
import { IRenderMime } from '@jupyterlab/rendermime-interfaces'
2+
import { KernelMessage, Kernel } from '@jupyterlab/services'
3+
import { ReadonlyJSONObject } from '@lumino/coreutils'
4+
import { Widget } from '@lumino/widgets'
5+
import { ContextManager } from './manager'
66

77
export declare interface KernelProxy {
88
// copied from https://github.com/jupyterlab/jupyterlab/blob/master/packages/services/src/kernel/default.ts#L605
9-
registerCommTarget(targetName: string, callback: (comm: Kernel.IComm, msg: KernelMessage.ICommOpenMsg) => void): void
9+
registerCommTarget(
10+
targetName: string,
11+
callback: (comm: Kernel.IComm, msg: KernelMessage.ICommOpenMsg) => void
12+
): void
1013
}
1114

1215
declare const Bokeh: any
1316

14-
function poll(fn: () => boolean, wait: number = 1000, interval: number = 100): Promise<void> {
17+
function poll(fn: () => boolean, wait = 1000, interval = 100): Promise<void> {
1518
return new Promise((resolve, reject) => {
1619
if (fn()) {
1720
resolve()
@@ -24,7 +27,7 @@ function poll(fn: () => boolean, wait: number = 1000, interval: number = 100): P
2427
wait -= interval
2528
if (wait <= 0) {
2629
clearInterval(id)
27-
reject(new Error("timeout"))
30+
reject(new Error('timeout'))
2831
}
2932
}, interval)
3033
}
@@ -34,10 +37,10 @@ function poll(fn: () => boolean, wait: number = 1000, interval: number = 100): P
3437
/**
3538
* The MIME types for BokehJS.
3639
*/
37-
const HTML_MIME_TYPE = "text/html"
38-
const JS_MIME_TYPE = "application/javascript"
39-
export const BOKEHJS_LOAD_MIME_TYPE = "application/vnd.bokehjs_load.v0+json"
40-
export const BOKEHJS_EXEC_MIME_TYPE = "application/vnd.bokehjs_exec.v0+json"
40+
const HTML_MIME_TYPE = 'text/html'
41+
const JS_MIME_TYPE = 'application/javascript'
42+
export const BOKEHJS_LOAD_MIME_TYPE = 'application/vnd.bokehjs_load.v0+json'
43+
export const BOKEHJS_EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json'
4144

4245
/**
4346
* Load BokehJS and CSS into the DOM
@@ -48,7 +51,7 @@ export class BokehJSLoad extends Widget implements IRenderMime.IRenderer {
4851

4952
constructor(_options: IRenderMime.IRendererOptions) {
5053
super()
51-
this._script_element = document.createElement("script")
54+
this._script_element = document.createElement('script')
5255
}
5356

5457
renderModel(model: IRenderMime.IMimeModel): Promise<void> {
@@ -76,7 +79,7 @@ export class BokehJSExec extends Widget implements IRenderMime.IRenderer {
7679

7780
constructor(_options: IRenderMime.IRendererOptions, manager: ContextManager) {
7881
super()
79-
this._script_element = document.createElement("script")
82+
this._script_element = document.createElement('script')
8083
this._manager = manager
8184
}
8285

@@ -87,31 +90,38 @@ export class BokehJSExec extends Widget implements IRenderMime.IRenderer {
8790
// I'm a static document
8891
const data = model.data[this._js_mimetype] as string
8992
this._script_element.textContent = data
90-
await poll(() => typeof Bokeh !== "undefined")
93+
await poll(() => typeof Bokeh !== 'undefined')
9194
this._document_id = metadata.id as string
92-
const {_manager} = this
95+
const { _manager } = this
9396
const kernel_proxy: KernelProxy = {
9497
registerCommTarget(targetName, callback) {
9598
const kernel = _manager!.context.sessionContext.session?.kernel
96-
if (kernel != null)
99+
if (kernel != null) {
97100
kernel.registerCommTarget(targetName, callback)
98-
},
101+
}
102+
}
99103
}
100104
Bokeh.embed.kernels[this._document_id] = kernel_proxy
101-
_manager!.context.sessionContext.statusChanged.connect((_session, status) => {
102-
if (status == "restarting" || status === "dead") {
103-
delete Bokeh.embed.kernels[this._document_id!]
104-
}
105-
}, this)
105+
_manager!.context.sessionContext.statusChanged.connect(
106+
(_session, status) => {
107+
if (status == 'restarting' || status === 'dead') {
108+
delete Bokeh.embed.kernels[this._document_id!]
109+
}
110+
},
111+
this
112+
)
106113
} else if (metadata.server_id !== undefined) {
107114
// I'm a server document
108115
this._server_id = metadata.server_id as string
109116
const data = model.data[this._html_mimetype] as string
110-
const d = document.createElement("div")
117+
const d = document.createElement('div')
111118
d.innerHTML = data
112119
const script_attrs: NamedNodeMap = d.children[0].attributes
113120
for (const i in script_attrs) {
114-
this._script_element.setAttribute(script_attrs[i].name, script_attrs[i].value)
121+
this._script_element.setAttribute(
122+
script_attrs[i].name,
123+
script_attrs[i].value
124+
)
115125
}
116126
this._script_element.textContent = d.textContent
117127
}
@@ -120,18 +130,20 @@ export class BokehJSExec extends Widget implements IRenderMime.IRenderer {
120130
}
121131

122132
dispose(): void {
123-
if (this.isDisposed)
133+
if (this.isDisposed) {
124134
return
135+
}
125136

126-
super.dispose();
137+
super.dispose()
127138

128139
if (this._server_id) {
129-
const content: KernelMessage.IExecuteRequestMsg["content"] = {
130-
code: `import bokeh.io.notebook as ion; ion.destroy_server("${this._server_id}")`,
140+
const content: KernelMessage.IExecuteRequestMsg['content'] = {
141+
code: `import bokeh.io.notebook as ion; ion.destroy_server("${this._server_id}")`
131142
}
132143
const kernel = this._manager!.context.sessionContext.session?.kernel
133-
if (kernel != null)
144+
if (kernel != null) {
134145
kernel.requestExecute(content, true)
146+
}
135147
this._server_id = null
136148
} else if (this._document_id) {
137149
if (Bokeh.embed.kernels !== undefined) {

0 commit comments

Comments
 (0)