Skip to content

Commit

Permalink
Switch to ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Apr 2, 2020
1 parent 79d9dd9 commit 3e3cf14
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 173 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
coverage
**/*.d.ts
47 changes: 47 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:jsdoc/recommended',
'plugin:prettier/recommended',
'plugin:react/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2017,
},
plugins: ['@typescript-eslint', 'jsdoc'],
rules: {
'@typescript-eslint/interface-name-prefix': [
'error',
{ prefixWithI: 'always' },
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false },
],
curly: ['error', 'all'],
'jsdoc/require-param-type': 'off',
'jsdoc/require-property-type': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/no-types': 'warn',
'prefer-arrow-callback': 'error',
},
settings: {
jsdoc: {
mode: 'typescript',
},
react: {
version: 'detect',
},
},
};
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"build:labextension": "npm run clean:labextension && mkdirp ipylab/labextension && cd ipylab/labextension && npm pack ../..",
"clean": "rimraf lib tsconfig.tsbuildinfo",
"clean:labextension": "rimraf ipylab/labextension",
"lint": "jlpm && jlpm run prettier && jlpm run tslint",
"lint:check": "jlpm run prettier:check && jlpm run tslint:check",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"lint": "jlpm && jlpm run prettier && jlpm run eslint",
"lint:check": "jlpm run prettier:check && jlpm run eslint:check",
"prepack": "npm run build",
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\" \"!dist/**\" \"!docs/**\"",
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\" \"!dist/**\" \"!docs/**\"",
"tslint": "tslint --fix -c tslint.json --project tsconfig.json \"**/*{.ts,.tsx}\"",
"tslint:check": "tslint -c tslint.json --project tsconfig.json \"**/*{.ts,.tsx}\"",
"watch": "npm-run-all -p watch:*",
"watch:lib": "tsc -w"
},
Expand Down Expand Up @@ -74,24 +74,27 @@
"@types/expect.js": "^0.3.29",
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.6",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"css-loader": "^3.2.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-jsdoc": "^22.1.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"expect.js": "^0.3.1",
"fs-extra": "^7.0.0",
"husky": "^3.1.0",
"lint-staged": "^9.4.3",
"mkdirp": "^0.5.1",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.3",
"prettier": "^1.19.1",
"prettier": "^2.0.2",
"rimraf": "^2.6.2",
"source-map-loader": "^0.2.4",
"style-loader": "^1.0.0",
"ts-loader": "^5.2.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"tslint-react": "^4.1.0",
"typescript": "~3.7.2"
"typescript": "~3.8.3"
},
"jupyterlab": {
"extension": "lib/plugin"
Expand Down
6 changes: 3 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
JupyterFrontEndPlugin,
JupyterFrontEnd,
ILabShell
ILabShell,
} from '@jupyterlab/application';

import { ICommandPalette } from '@jupyterlab/apputils';
Expand Down Expand Up @@ -37,9 +37,9 @@ const extension: JupyterFrontEndPlugin<void> = {
registry.registerWidget({
name: MODULE_NAME,
version: MODULE_VERSION,
exports: widgetExports
exports: widgetExports,
});
}
},
};

export default extension;
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Jeremy Tuloup
// Distributed under the terms of the Modified BSD License.

// tslint:disable-next-line: no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const data = require('../package.json');

/**
Expand Down
2 changes: 1 addition & 1 deletion src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export {
ShellModel,
SplitPanelModel,
SplitPanelView,
TitleModel
TitleModel,
};
23 changes: 13 additions & 10 deletions src/widgets/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@ import { IDisposable } from '@lumino/disposable';

import { MODULE_NAME, MODULE_VERSION } from '../version';

/**
* The model for a command registry.
*/
export class CommandRegistryModel extends WidgetModel {
defaults() {
defaults(): any {
return {
...super.defaults(),
_model_name: CommandRegistryModel.model_name,
_model_module: CommandRegistryModel.model_module,
_model_module_version: CommandRegistryModel.model_module_version
_model_module_version: CommandRegistryModel.model_module_version,
};
}

initialize(attributes: any, options: any) {
initialize(attributes: any, options: any): void {
this.commands = CommandRegistryModel._commands;
super.initialize(attributes, options);
this.on('msg:custom', this._onMessage.bind(this));
this.on('comm_live_update', () => {
if (this.comm_live) {
return;
}
this._customCommands.values().forEach(command => command.dispose());
this._customCommands.values().forEach((command) => command.dispose());
this._sendCommandList();
});
this._sendCommandList();
}

private _onMessage(msg: any) {
private _onMessage(msg: any): void {
switch (msg.func) {
case 'execute':
this._execute(msg.payload);
Expand All @@ -51,13 +54,13 @@ export class CommandRegistryModel extends WidgetModel {
}
}

private _sendCommandList() {
private _sendCommandList(): void {
this.commands.notifyCommandChanged();
this.set('_commands', this.commands.listCommands());
this.save_changes();
}

private _execute(payload: any) {
private _execute(payload: any): void {
const { id, args } = payload;
void this.commands.execute(id, args);
}
Expand All @@ -78,13 +81,13 @@ export class CommandRegistryModel extends WidgetModel {
return;
}
this.send({ event: 'execute', id }, {});
}
},
});
this._customCommands.set(id, command);
this._sendCommandList();
}

private _removeCommand(payload: any) {
private _removeCommand(payload: any): void {
const { id } = payload;
if (this._customCommands.has(id)) {
this._customCommands.get(id).dispose();
Expand All @@ -93,7 +96,7 @@ export class CommandRegistryModel extends WidgetModel {
}

static serializers: ISerializers = {
...WidgetModel.serializers
...WidgetModel.serializers,
};

static model_name = 'CommandRegistryModel';
Expand Down
10 changes: 5 additions & 5 deletions src/widgets/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { JupyterFrontEnd } from '@jupyterlab/application';
import {
DOMWidgetModel,
ISerializers,
WidgetModel
WidgetModel,
} from '@jupyter-widgets/base';

import { MODULE_NAME, MODULE_VERSION } from '../version';

export class JupyterFrontEndModel extends WidgetModel {
defaults() {
defaults(): any {
return {
...super.defaults(),
_model_name: JupyterFrontEndModel.model_name,
_model_module: JupyterFrontEndModel.model_module,
_model_module_version: JupyterFrontEndModel.model_module_version
_model_module_version: JupyterFrontEndModel.model_module_version,
};
}

initialize(attributes: any, options: any) {
initialize(attributes: any, options: any): void {
this.app = JupyterFrontEndModel._app;
super.initialize(attributes, options);
this.send({ event: 'lab_ready' }, {});
Expand All @@ -30,7 +30,7 @@ export class JupyterFrontEndModel extends WidgetModel {
}

static serializers: ISerializers = {
...DOMWidgetModel.serializers
...DOMWidgetModel.serializers,
};

static model_name = 'JupyterFrontEndModel';
Expand Down
14 changes: 7 additions & 7 deletions src/widgets/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
import {
DOMWidgetModel,
ISerializers,
WidgetModel
WidgetModel,
} from '@jupyter-widgets/base';

import { MODULE_NAME, MODULE_VERSION } from '../version';
import { ICommandPalette } from '@jupyterlab/apputils';

export class CommandPaletteModel extends WidgetModel {
defaults() {
defaults(): any {
return {
...super.defaults(),
_model_name: CommandPaletteModel.model_name,
_model_module: CommandPaletteModel.model_module,
_model_module_version: CommandPaletteModel.model_module_version
_model_module_version: CommandPaletteModel.model_module_version,
};
}

initialize(attributes: any, options: any) {
initialize(attributes: any, options: any): void {
this.palette = CommandPaletteModel._palette;
super.initialize(attributes, options);

this.on('msg:custom', this._onMessage.bind(this));
}

private _onMessage(msg: any) {
private _onMessage(msg: any): void {
switch (msg.func) {
case 'addItem':
this._addItem(msg.payload);
Expand All @@ -37,7 +37,7 @@ export class CommandPaletteModel extends WidgetModel {
}
}

private _addItem(payload: any) {
private _addItem(payload: any): void {
if (!this.palette) {
// no-op if no palette
return;
Expand All @@ -47,7 +47,7 @@ export class CommandPaletteModel extends WidgetModel {
}

static serializers: ISerializers = {
...DOMWidgetModel.serializers
...DOMWidgetModel.serializers,
};

static model_name = 'CommandPaletteModel';
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { VBoxModel } from '@jupyter-widgets/controls';
import { MODULE_NAME, MODULE_VERSION } from '../version';

export class PanelModel extends VBoxModel {
defaults() {
defaults(): any {
return {
...super.defaults(),
_model_name: PanelModel.model_name,
_model_module: PanelModel.model_module,
_model_module_version: PanelModel.model_module_version,
_view_name: null
_view_name: null,
};
}

Expand Down
Loading

0 comments on commit 3e3cf14

Please sign in to comment.