Skip to content

Commit

Permalink
Update to newer ESLint plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Mar 15, 2021
1 parent 39dbecb commit fedd282
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 254 deletions.
17 changes: 13 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
"prettier"
],
"rules": {
"@typescript-eslint/interface-name-prefix": [
"@typescript-eslint/naming-convention": [
"error",
{ "prefixWithI": "always" }
{
"selector": "interface",
"format": ["PascalCase"],
"custom": {
"regex": "^I[A-Z]",
"match": true
}
}
],
"@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",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-namespace": "off"
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/camelcase": "off"
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
Expand Down
25 changes: 17 additions & 8 deletions jupyterlab_widgets/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
tsconfigRootDir: __dirname
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/interface-name-prefix': [
'@typescript-eslint/naming-convention': [
'error',
{ prefixWithI: 'always' }
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z]',
match: true,
},
},
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false }
{ avoidEscape: true, allowTemplateLiterals: false },
],
curly: ['error', 'all'],
eqeqeq: 'error',
'prefer-arrow-callback': 'error'
}
'prefer-arrow-callback': 'error',
},
};
12 changes: 6 additions & 6 deletions jupyterlab_widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@
"@jupyterlab/builder": "^3.0.0",
"@jupyterlab/cells": "^3.0.0",
"@types/semver": "^6.0.1",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"typescript": "~4.2.3"
},
Expand Down
33 changes: 17 additions & 16 deletions jupyterlab_widgets/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
WidgetModel,
WidgetView,
put_buffers,
ICallbacks
ICallbacks,
} from '@jupyter-widgets/base';

import {
ManagerBase,
serialize_state,
IStateOptions
IStateOptions,
} from '@jupyter-widgets/base-manager';

import { IDisposable } from '@lumino/disposable';
Expand Down Expand Up @@ -51,7 +51,8 @@ export const WIDGET_STATE_MIMETYPE =
/**
* A widget manager that returns Lumino widgets.
*/
export abstract class LabWidgetManager extends ManagerBase
export abstract class LabWidgetManager
extends ManagerBase
implements IDisposable {
constructor(rendermime: IRenderMimeRegistry) {
super();
Expand All @@ -66,8 +67,8 @@ export abstract class LabWidgetManager extends ManagerBase
iopub: {
output: (msg: KernelMessage.IIOPubMessage): void => {
this._onUnhandledIOPubMessage.emit(msg);
}
}
},
},
};
}

Expand All @@ -76,7 +77,7 @@ export abstract class LabWidgetManager extends ManagerBase
*/
protected _handleKernelChanged({
oldValue,
newValue
newValue,
}: Session.ISessionConnection.IKernelChangedArgs): void {
if (oldValue) {
oldValue.removeCommTarget(this.comm_target_name, this._handleCommOpen);
Expand Down Expand Up @@ -108,7 +109,7 @@ export abstract class LabWidgetManager extends ManagerBase

// For each comm id that we do not know about, create the comm, and request the state.
const widgets_info = await Promise.all(
Object.keys(comm_ids).map(async comm_id => {
Object.keys(comm_ids).map(async (comm_id) => {
try {
await this.get_model(comm_id);
// If we successfully get the model, do no more.
Expand Down Expand Up @@ -140,7 +141,7 @@ export abstract class LabWidgetManager extends ManagerBase
});
msg_id = comm.send(
{
method: 'request_state'
method: 'request_state',
},
this.callbacks(undefined)
);
Expand All @@ -156,7 +157,7 @@ export abstract class LabWidgetManager extends ManagerBase
// asynchronously, so promises to every widget reference should be available
// by the time they are used.
await Promise.all(
widgets_info.map(async widget_info => {
widgets_info.map(async (widget_info) => {
if (!widget_info) {
return;
}
Expand All @@ -166,7 +167,7 @@ export abstract class LabWidgetManager extends ManagerBase
model_name: content.data.state._model_name,
model_module: content.data.state._model_module,
model_module_version: content.data.state._model_module_version,
comm: widget_info.comm
comm: widget_info.comm,
},
content.data.state
);
Expand Down Expand Up @@ -204,7 +205,7 @@ export abstract class LabWidgetManager extends ManagerBase
throw new Error('No current kernel');
}
const reply = await kernel.requestCommInfo({
target_name: this.comm_target_name
target_name: this.comm_target_name,
});
if (reply.content.status === 'ok') {
return (reply.content as any).comms;
Expand Down Expand Up @@ -340,7 +341,7 @@ export abstract class LabWidgetManager extends ManagerBase
super.register_model(model_id, modelPromise);

// Update the synchronous model map
modelPromise.then(model => {
modelPromise.then((model) => {
this._modelsSync.set(model_id, model);
model.once('comm:close', () => {
this._modelsSync.delete(model_id);
Expand Down Expand Up @@ -424,7 +425,7 @@ export class KernelWidgetManager extends LabWidgetManager {
this._handleKernelChanged({
name: 'kernel',
oldValue: null,
newValue: kernel
newValue: kernel,
});
this.restoreWidgets();
}
Expand Down Expand Up @@ -507,7 +508,7 @@ export class WidgetManager extends LabWidgetManager {
this._handleKernelChanged({
name: 'kernel',
oldValue: null,
newValue: context.sessionContext.session?.kernel
newValue: context.sessionContext.session?.kernel,
});
}

Expand All @@ -527,7 +528,7 @@ export class WidgetManager extends LabWidgetManager {
private _saveState(): void {
const state = this.get_state_sync({ drop_defaults: true });
this._context.model.metadata.set('widgets', {
'application/vnd.jupyter.widget-state+json': state
'application/vnd.jupyter.widget-state+json': state,
});
}

Expand All @@ -539,7 +540,7 @@ export class WidgetManager extends LabWidgetManager {
// We only want to restore widgets from the kernel, not ones saved in the notebook.
this.restoreWidgets(this._context!.model, {
loadKernel: true,
loadNotebook: false
loadNotebook: false,
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions jupyterlab_widgets/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class OutputModel extends outputBase.OutputModel {
* Register a new kernel
*/
_handleKernelChanged({
oldValue
oldValue,
}: Session.ISessionConnection.IKernelChangedArgs): void {
const msgId = this.get('msg_id');
if (msgId && oldValue) {
Expand Down Expand Up @@ -184,7 +184,7 @@ export class OutputView extends outputBase.OutputView {
this._outputView = new OutputArea({
rendermime: this.model.widget_manager.rendermime,
contentFactory: OutputArea.defaultContentFactory,
model: this.model.outputs
model: this.model.outputs,
});
// TODO: why is this a readonly property now?
// this._outputView.model = this.model.outputs;
Expand Down
36 changes: 18 additions & 18 deletions jupyterlab_widgets/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
INotebookModel,
INotebookTracker,
Notebook,
NotebookPanel
NotebookPanel,
} from '@jupyterlab/notebook';

import {
JupyterFrontEndPlugin,
JupyterFrontEnd
JupyterFrontEnd,
} from '@jupyterlab/application';

import { IMainMenu } from '@jupyterlab/mainmenu';
Expand Down Expand Up @@ -83,7 +83,7 @@ function* outputViews(
): Generator<WidgetRenderer, void, unknown> {
const linkedViews = filter(
app.shell.widgets(),
w => w.id.startsWith('LinkedOutputView-') && (w as any).path === path
(w) => w.id.startsWith('LinkedOutputView-') && (w as any).path === path
);
for (const view of toArray(linkedViews)) {
for (const outputs of toArray(view.children())) {
Expand Down Expand Up @@ -112,7 +112,7 @@ export function registerWidgetManager(
let wManager = Private.widgetManagerProperty.get(context);
if (!wManager) {
wManager = new WidgetManager(context, rendermime, SETTINGS);
WIDGET_REGISTRY.forEach(data => wManager!.register(data));
WIDGET_REGISTRY.forEach((data) => wManager!.register(data));
Private.widgetManagerProperty.set(context, wManager);
}

Expand All @@ -127,7 +127,7 @@ export function registerWidgetManager(
{
safe: false,
mimeTypes: [WIDGET_VIEW_MIMETYPE],
createRenderer: options => new WidgetRenderer(options, wManager)
createRenderer: (options) => new WidgetRenderer(options, wManager),
},
0
);
Expand All @@ -149,7 +149,7 @@ const plugin: JupyterFrontEndPlugin<base.IJupyterWidgetRegistry> = {
optional: [INotebookTracker, ISettingRegistry, IMainMenu, ILoggerRegistry],
provides: base.IJupyterWidgetRegistry,
activate: activateWidgetExtension,
autoStart: true
autoStart: true,
};

export default plugin;
Expand Down Expand Up @@ -190,7 +190,7 @@ function activateWidgetExtension(
}
const data: nbformat.IOutput = {
...msg.content,
output_type: msg.header.msg_type
output_type: msg.header.msg_type,
};
logger.rendermime = nb.content.rendermime;
logger.log({ type: 'output', data, level });
Expand All @@ -215,13 +215,13 @@ function activateWidgetExtension(
{
safe: false,
mimeTypes: [WIDGET_VIEW_MIMETYPE],
createRenderer: options => new WidgetRenderer(options)
createRenderer: (options) => new WidgetRenderer(options),
},
0
);

if (tracker !== null) {
tracker.forEach(panel => {
tracker.forEach((panel) => {
registerWidgetManager(
panel.context,
panel.content.rendermime,
Expand Down Expand Up @@ -251,20 +251,20 @@ function activateWidgetExtension(
// Add a command for automatically saving (jupyter-)widget state.
commands.addCommand('@jupyter-widgets/jupyterlab-manager:saveWidgetState', {
label: 'Save Widget State Automatically',
execute: args => {
execute: (args) => {
return settingRegistry
.set(plugin.id, 'saveState', !SETTINGS.saveState)
.catch((reason: Error) => {
console.error(`Failed to set ${plugin.id}: ${reason.message}`);
});
},
isToggled: () => SETTINGS.saveState
isToggled: () => SETTINGS.saveState,
});
}

if (menu) {
menu.settingsMenu.addGroup([
{ command: '@jupyter-widgets/jupyterlab-manager:saveWidgetState' }
{ command: '@jupyter-widgets/jupyterlab-manager:saveWidgetState' },
]);
}

Expand All @@ -279,8 +279,8 @@ function activateWidgetExtension(
LayoutModel: base.LayoutModel,
LayoutView: base.LayoutView,
StyleModel: base.StyleModel,
StyleView: base.StyleView
}
StyleView: base.StyleView,
},
});

WIDGET_REGISTRY.push({
Expand All @@ -300,19 +300,19 @@ function activateWidgetExtension(
'@jupyter-widgets/controls'
);
});
}
},
});

WIDGET_REGISTRY.push({
name: '@jupyter-widgets/output',
version: OUTPUT_WIDGET_VERSION,
exports: { OutputModel, OutputView }
exports: { OutputModel, OutputView },
});

return {
registerWidget(data: base.IWidgetRegistryData): void {
WIDGET_REGISTRY.push(data);
}
},
};
}

Expand All @@ -325,6 +325,6 @@ namespace Private {
WidgetManager | undefined
>({
name: 'widgetManager',
create: (owner: DocumentRegistry.Context): undefined => undefined
create: (owner: DocumentRegistry.Context): undefined => undefined,
});
}
Loading

0 comments on commit fedd282

Please sign in to comment.