Skip to content

Commit 60c2d39

Browse files
authored
Merge pull request #2657 from jasongrout/eslint
Move to ESLint and Prettier
2 parents e1d1169 + 523f55a commit 60c2d39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1780
-1563
lines changed

.eslintrc.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/eslint-recommended",
6+
"plugin:@typescript-eslint/recommended"
7+
],
8+
"rules": {
9+
"@typescript-eslint/interface-name-prefix": [
10+
"error", { "prefixWithI": "always" }
11+
],
12+
"@typescript-eslint/no-unused-vars": [
13+
"warn", { "args": "none" }
14+
],
15+
"@typescript-eslint/no-use-before-define": "off",
16+
"@typescript-eslint/camelcase": "off",
17+
"@typescript-eslint/no-explicit-any": "off",
18+
"@typescript-eslint/no-namespace": "off"
19+
},
20+
"parser": "@typescript-eslint/parser",
21+
"plugins": ["@typescript-eslint"]
22+
}

.github/workflows/lint.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v1
11+
- name: Use Node.js 10.x
12+
uses: actions/setup-node@v1
13+
with:
14+
node-version: 10.x
15+
- name: Get yarn cache
16+
id: yarn-cache
17+
run: echo "::set-output name=dir::$(yarn cache dir)"
18+
- uses: actions/cache@v1
19+
with:
20+
path: ${{ steps.yarn-cache.outputs.dir }}
21+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
22+
restore-keys: |
23+
${{ runner.os }}-yarn-
24+
- name: yarn install, build, integrity, test
25+
run: |
26+
yarn install --frozen-lockfile
27+
yarn run build
28+
yarn run integrity
29+
yarn run eslint:check

.github/workflows/testjs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
2525
restore-keys: |
2626
${{ runner.os }}-yarn-
27-
- name: yarn install, build, integrity, test
27+
- name: yarn install, build, test
2828
run: |
29-
yarn install
29+
yarn install --frozen-lockfile
3030
yarn run build
3131
yarn run build:examples
3232
yarn run integrity

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

examples/web3/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"build": "npm run clean && tsc && node scripts/copyfiles.js && webpack",
1111
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo && rimraf built",
1212
"host": "http-server",
13-
"lint": "tslint --project tslint.json --format stylish",
1413
"test": "npm run test:default",
1514
"test:default": "echo \"No test specified\""
1615
},
@@ -36,7 +35,6 @@
3635
"postcss-loader": "^3.0.0",
3736
"rimraf": "^2.6.1",
3837
"style-loader": "^1.1.2",
39-
"tslint": "^5.20.1",
4038
"typescript": "~3.7.4",
4139
"url-loader": "^3.0.0",
4240
"webpack": "^4.41.5"

examples/web3/src/index.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ import {
1010
KernelManager, ServerConnection, KernelMessage
1111
} from '@jupyterlab/services';
1212

13-
let BASEURL = prompt('Notebook BASEURL', 'http://localhost:8888');
14-
let WSURL = 'ws:' + BASEURL.split(':').slice(1).join(':');
13+
const BASEURL = prompt('Notebook BASEURL', 'http://localhost:8888');
14+
const WSURL = 'ws:' + BASEURL.split(':').slice(1).join(':');
1515

1616
document.addEventListener('DOMContentLoaded', async function(event) {
1717

1818
// Connect to the notebook webserver.
19-
let connectionInfo = ServerConnection.makeSettings({
19+
const connectionInfo = ServerConnection.makeSettings({
2020
baseUrl: BASEURL,
2121
wsUrl: WSURL
2222
});
23-
let kernelManager = new KernelManager({serverSettings: connectionInfo});
24-
let kernel = await kernelManager.startNew();
23+
const kernelManager = new KernelManager({serverSettings: connectionInfo});
24+
const kernel = await kernelManager.startNew();
2525

2626
// Create a codemirror instance
27-
let code = require('../widget_code.json').join('\n');
28-
let inputarea = document.getElementsByClassName('inputarea')[0] as HTMLElement;
27+
const code = require('../widget_code.json').join('\n');
28+
const inputarea = document.getElementsByClassName('inputarea')[0] as HTMLElement;
2929
CodeMirror(inputarea, {
3030
value: code,
3131
mode: 'python',
@@ -36,18 +36,18 @@ document.addEventListener('DOMContentLoaded', async function(event) {
3636
});
3737

3838
// Create the widget area and widget manager
39-
let widgetarea = document.getElementsByClassName('widgetarea')[0] as HTMLElement;
40-
let manager = new WidgetManager(kernel, widgetarea);
39+
const widgetarea = document.getElementsByClassName('widgetarea')[0] as HTMLElement;
40+
const manager = new WidgetManager(kernel, widgetarea);
4141

4242
// Run backend code to create the widgets. You could also create the
4343
// widgets in the frontend, like the other widget examples demonstrate.
44-
let execution = kernel.requestExecute({ code: code });
45-
execution.onIOPub = (msg) => {
44+
const execution = kernel.requestExecute({ code: code });
45+
execution.onIOPub = (msg): void => {
4646
// If we have a display message, display the widget.
4747
if (KernelMessage.isDisplayDataMsg(msg)) {
48-
let widgetData: any = msg.content.data['application/vnd.jupyter.widget-view+json'];
48+
const widgetData: any = msg.content.data['application/vnd.jupyter.widget-view+json'];
4949
if (widgetData !== undefined && widgetData.version_major === 2) {
50-
let model = manager.get_model(widgetData.model_id);
50+
const model = manager.get_model(widgetData.model_id);
5151
if (model !== undefined) {
5252
model.then(model => {
5353
manager.display_model(msg, model);

examples/web3/src/manager.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@ class WidgetManager extends HTMLManager {
2020
this.el = el;
2121

2222
kernel.registerCommTarget(this.comm_target_name, async (comm, msg) => {
23-
let oldComm = new base.shims.services.Comm(comm);
23+
const oldComm = new base.shims.services.Comm(comm);
2424
await this.handle_comm_open(oldComm, msg);
2525
});
2626
}
2727

28-
display_view(msg: any, view: DOMWidgetView, options: any) {
28+
display_view(msg: any, view: DOMWidgetView, options: any): Promise<HTMLElement> {
2929
return Promise.resolve(view).then((view) => {
3030
pWidget.Widget.attach(view.pWidget, this.el);
3131
view.on('remove', function() {
3232
console.log('view removed', view);
3333
});
34-
return view;
34+
// We will resolve this lie in another PR.
35+
return view as any;
3536
});
3637
}
3738

3839
/**
3940
* Create a comm.
4041
*/
4142
async _create_comm(target_name: string, model_id: string, data?: any, metadata?: any): Promise<base.shims.services.Comm> {
42-
let comm = this.kernel.createComm(target_name, model_id);
43+
const comm = this.kernel.createComm(target_name, model_id);
4344
if (data || metadata) {
4445
comm.open(data, metadata);
4546
}

examples/web3/tslint.json

-3
This file was deleted.

package.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@
1010
"build:examples": "lerna run build --scope \"@jupyter-widgets/example-*\" --include-filtered-dependencies",
1111
"clean": "lerna run clean",
1212
"integrity": "node scripts/package-integrity.js",
13+
"eslint": "eslint . --fix --ignore-path .gitignore --ext .ts,.tsx",
14+
"eslint:check": "eslint . --ignore-path .gitignore --ext .ts,.tsx",
1315
"lint": "lerna run lint",
16+
"integrity2": "node buildutils/lib/integrity.js",
17+
"lint2": "yarn && yarn run prettier && yarn run eslint",
18+
"lint:check": "yarn run prettier:check && yarn run eslint:check",
19+
"prettier": "prettier --ignore-path .gitignore --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
20+
"prettier:check": "prettier --ignore-path .gitignore --check '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
21+
"sort-package-json": "lerna exec --parallel sort-package-json && sort-package-json",
1422
"publish": "yarn run clean && yarn run build && lerna publish -m \"Publish npm packages\"",
1523
"update-dependency": "update-dependency --lerna",
1624
"updated": "lerna updated"
1725
},
1826
"devDependencies": {
1927
"@jupyterlab/buildutils": "^2.0.0-beta.2",
20-
"lerna": "^3.2.1"
28+
"@typescript-eslint/eslint-plugin": "^2.14.0",
29+
"@typescript-eslint/parser": "^2.14.0",
30+
"eslint": "^6.5.0",
31+
"eslint-plugin-prettier": "^3.1.2",
32+
"lerna": "^3.20.2",
33+
"prettier": "^1.19.1",
34+
"sort-package-json": "~1.35"
2135
}
2236
}

packages/base/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"build:test": "tsc --project test && webpack --config test/webpack.conf.js",
2222
"clean": "npm run clean:src",
2323
"clean:src": "rimraf lib && rimraf tsconfig.tsbuildinfo",
24-
"lint": "tslint --project tslint.json --format stylish",
2524
"prepublish": "npm run clean && npm run build",
2625
"test": "npm run test:unit",
2726
"test:coverage": "npm run build:test && webpack --config test/webpack-cov.conf.js && karma start test/karma-cov.conf.js",
@@ -69,7 +68,6 @@
6968
"rimraf": "^2.6.1",
7069
"sinon": "^7.3.2",
7170
"sinon-chai": "^3.3.0",
72-
"tslint": "^5.20.1",
7371
"typescript": "~3.7.4",
7472
"webpack": "^4.41.5"
7573
}

packages/base/src/backbone-patch.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import * as utils from './utils';
4343
// anyone who needs to know about the change in state. The heart of the beast.
4444
// This *MUST* be called with the model as the `this` context.
4545
export
46-
function set(key: string|{}, val: any, options: any) {
46+
function set(key: string|{}, val: any, options: any): any {
4747
/* tslint:disable:no-invalid-this */
4848
if (key == null) {
4949
return this;
@@ -66,10 +66,10 @@ function set(key: string|{}, val: any, options: any) {
6666
}
6767

6868
// Extract attributes and options.
69-
let unset = options.unset;
70-
let silent = options.silent;
71-
let changes = [];
72-
let changing = this._changing;
69+
const unset = options.unset;
70+
const silent = options.silent;
71+
const changes = [];
72+
const changing = this._changing;
7373
this._changing = true;
7474

7575
if (!changing) {
@@ -78,12 +78,12 @@ function set(key: string|{}, val: any, options: any) {
7878
this.changed = {};
7979
}
8080

81-
let current = this.attributes;
82-
let changed = this.changed;
83-
let prev = this._previousAttributes;
81+
const current = this.attributes;
82+
const changed = this.changed;
83+
const prev = this._previousAttributes;
8484

8585
// For each `set` attribute, update or delete the current value.
86-
for (let attr in attrs) {
86+
for (const attr in attrs) {
8787
val = attrs[attr];
8888
// EDIT: the following two lines use our isEqual instead of _.isEqual
8989
if (!utils.isEqual(current[attr], val)) {

0 commit comments

Comments
 (0)