Skip to content

Commit b724334

Browse files
committed
Add linters
1 parent 5a23eb1 commit b724334

File tree

15 files changed

+3713
-1161
lines changed

15 files changed

+3713
-1161
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
dist
3+
coverage
4+
**/*.d.ts
5+
ui-tests
6+
docs

.eslintrc.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
extends: [
3+
'eslint:recommended',
4+
'plugin:@typescript-eslint/eslint-recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
'plugin:prettier/recommended'
7+
],
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: {
10+
project: 'tsconfig.json',
11+
sourceType: 'module'
12+
},
13+
plugins: ['@typescript-eslint'],
14+
rules: {
15+
'@typescript-eslint/naming-convention': [
16+
'error',
17+
{
18+
selector: 'interface',
19+
format: ['PascalCase'],
20+
custom: {
21+
regex: '^I[A-Z]',
22+
match: true
23+
}
24+
}
25+
],
26+
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
27+
'@typescript-eslint/no-explicit-any': 'off',
28+
'@typescript-eslint/no-namespace': 'off',
29+
'@typescript-eslint/no-use-before-define': 'off',
30+
'@typescript-eslint/quotes': [
31+
'error',
32+
'single',
33+
{ avoidEscape: true, allowTemplateLiterals: false }
34+
],
35+
curly: ['error', 'all'],
36+
eqeqeq: 'error',
37+
'prefer-arrow-callback': 'error'
38+
}
39+
};

.github/workflows/main.yml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defaults:
1313
shell: bash -l {0}
1414

1515
jobs:
16-
run:
16+
lint:
1717
runs-on: ${{ matrix.os }}
1818

1919
strategy:
@@ -36,22 +36,6 @@ jobs:
3636
auto-activate-base: false
3737
channels: conda-forge
3838

39-
- name: Install ipycanvas
40-
run: pip install -e .
41-
42-
- name: Check installation files
43-
run: |
44-
test -d $CONDA_PREFIX/share/jupyter/nbextensions/ipycanvas
45-
test -f $CONDA_PREFIX/share/jupyter/nbextensions/ipycanvas/extension.js
46-
test -f $CONDA_PREFIX/share/jupyter/nbextensions/ipycanvas/index.js
47-
test -d $CONDA_PREFIX/share/jupyter/labextensions/ipycanvas
48-
test -f $CONDA_PREFIX/share/jupyter/labextensions/ipycanvas/package.json
49-
50-
- name: Check nbextension and labextension
51-
run: |
52-
jupyter nbextension list 2>&1 | grep -ie "ipycanvas/extension.*enabled" -
53-
jupyter labextension list 2>&1 | grep -ie "ipycanvas.*enabled.*ok" -
54-
5539
- name: Test PEP8
5640
run: black --check ipycanvas
5741

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
dist
3+
**/node_modules
4+
**/lib
5+
**/package.json
6+
ui-tests
7+
ipycanvas
8+
docs

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"arrowParens": "avoid",
5+
"endOfLine": "auto"
6+
}

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ If you have any question, or if you want to share what you do with ipycanvas, [s
2626

2727
Or join the gitter channel: [![Join the chat at https://gitter.im/martinRenou/ipycanvas](https://badges.gitter.im/martinRenou/ipycanvas.svg)](https://gitter.im/martinRenou/ipycanvas?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2828

29-
3029
## Installation
3130

3231
You can install using `pip`:
@@ -48,24 +47,30 @@ conda install -c conda-forge yarn
4847
jupyter labextension install @jupyter-widgets/jupyterlab-manager ipycanvas
4948
```
5049

51-
A development installation guide, can be found [here](https://ipycanvas.readthedocs.io/en/latest/installation.html#development-installation)
50+
A development installation guide, can be found [here](https://ipycanvas.readthedocs.io/en/latest/installation.html#development-installation)
5251

5352
## Examples
5453

5554
### Create John Conway's Game Of Life
55+
5656
![John Conway's Game Of Life](docs/source/images/ipycanvas_gameoflife.png)
5757

5858
### Give a "hand-drawn" style to your drawings using the RoughCanvas
59+
5960
![RoughCanvas](docs/source/images/ipycanvas_rough.png)
6061

6162
### Draw Particles from IPython
63+
6264
![Particles](docs/source/images/ipycanvas_particles.png)
6365

6466
### Custom Sprites
67+
6568
![Sprites](docs/source/images/ipycanvas_sprites.png)
6669

6770
### Draw data directly from a NumPy array
71+
6872
![NumPy](docs/source/images/ipycanvas_binary.png)
6973

7074
### Create your own plotting library **fully** in Python
75+
7176
![Plotting](docs/source/images/ipycanvas_scatter.png)

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
"clean:lib": "rimraf lib",
4040
"clean:nbextension": "rimraf ipycanvas/nbextension/static/index.js",
4141
"clean:labextension": "rimraf ipycanvas/labextension",
42+
"lint": "yarn prettier && yarn eslint",
43+
"lint:check": "yarn prettier:check && yarn eslint:check",
44+
"prettier": "yarn prettier:base --write --list-different",
45+
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
46+
"prettier:check": "yarn prettier:base --check",
4247
"prepack": "yarn run build",
4348
"watch:lib": "tsc -w",
4449
"watch:nbextension": "webpack --watch"
@@ -55,10 +60,16 @@
5560
"@phosphor/widgets": "^1.6.0",
5661
"@types/node": "^10.11.6",
5762
"@types/webpack-env": "^1.13.6",
63+
"@typescript-eslint/eslint-plugin": "^4.8.1",
64+
"@typescript-eslint/parser": "^4.8.1",
5865
"acorn": "^6.2.0",
66+
"eslint": "^7.3.1",
67+
"eslint-config-prettier": "^6.11.0",
68+
"eslint-plugin-prettier": "^3.1.4",
5969
"expect.js": "^0.3.1",
6070
"fs-extra": "^7.0.0",
6171
"mkdirp": "^0.5.1",
72+
"prettier": "^2.0.5",
6273
"rimraf": "^2.6.2",
6374
"source-map-loader": "^0.2.4",
6475
"ts-loader": "^5.2.1",

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// Some static assets may be required by the custom widget javascript. The base
99
// url for the notebook is not known at build time and is therefore computed
1010
// dynamically.
11-
(window as any).__webpack_public_path__ = document.querySelector('body')!.getAttribute('data-base-url') + 'nbextensions/ipycanvas';
11+
(window as any).__webpack_public_path__ =
12+
document.querySelector('body')!.getAttribute('data-base-url') +
13+
'nbextensions/ipycanvas';
1214

1315
export * from './index';

src/plugin.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
// Copyright (c) Martin Renou
22
// Distributed under the terms of the Modified BSD License.
33

4-
import {
5-
Application, IPlugin
6-
} from '@phosphor/application';
4+
import { Application, IPlugin } from '@phosphor/application';
75

8-
import {
9-
Widget
10-
} from '@phosphor/widgets';
6+
import { Widget } from '@phosphor/widgets';
117

12-
import {
13-
IJupyterWidgetRegistry
14-
} from '@jupyter-widgets/base';
8+
import { IJupyterWidgetRegistry } from '@jupyter-widgets/base';
159

1610
import * as widgetExports from './widget';
1711

18-
import {
19-
MODULE_NAME, MODULE_VERSION
20-
} from './version';
12+
import { MODULE_NAME, MODULE_VERSION } from './version';
2113

2214
const EXTENSION_ID = 'ipycanvas:plugin';
2315

@@ -32,14 +24,16 @@ const ipycanvasPlugin: IPlugin<Application<Widget>, void> = {
3224

3325
export default ipycanvasPlugin;
3426

35-
3627
/**
3728
* Activate the widget extension.
3829
*/
39-
function activateWidgetExtension(app: Application<Widget>, registry: IJupyterWidgetRegistry): void {
30+
function activateWidgetExtension(
31+
app: Application<Widget>,
32+
registry: IJupyterWidgetRegistry
33+
): void {
4034
registry.registerWidget({
4135
name: MODULE_NAME,
4236
version: MODULE_VERSION,
43-
exports: widgetExports,
37+
exports: widgetExports
4438
});
4539
}

src/utils.ts

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export function getTypedArray(dataview: any, metadata: any) {
44
return new Int8Array(dataview.buffer);
55
break;
66
case 'uint8':
7-
return new Uint8Array(dataview.buffer);
8-
break;
7+
return new Uint8Array(dataview.buffer);
8+
break;
99
case 'int16':
1010
return new Int16Array(dataview.buffer);
1111
break;
@@ -34,18 +34,30 @@ export function getTypedArray(dataview: any, metadata: any) {
3434
type Scalar = null | boolean | number | string;
3535

3636
namespace Scalar {
37-
export
38-
function isScalar(x: any): x is Scalar {
39-
return x === null || typeof x === "boolean" || typeof x === "number" || typeof x === "string";
37+
export function isScalar(x: any): x is Scalar {
38+
return (
39+
x === null ||
40+
typeof x === 'boolean' ||
41+
typeof x === 'number' ||
42+
typeof x === 'string'
43+
);
4044
}
4145
}
4246

43-
type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
47+
type TypedArray =
48+
| Int8Array
49+
| Uint8Array
50+
| Int16Array
51+
| Uint16Array
52+
| Int32Array
53+
| Uint32Array
54+
| Uint8ClampedArray
55+
| Float32Array
56+
| Float64Array;
4457

4558
// Buffered argument
46-
export
47-
abstract class Arg {
48-
abstract getItem(idx: number) : any;
59+
export abstract class Arg {
60+
abstract getItem(idx: number): any;
4961

5062
length: number;
5163
}
@@ -58,7 +70,7 @@ class ScalarArg extends Arg {
5870
this.length = Infinity;
5971
}
6072

61-
getItem(idx: number) : any {
73+
getItem(idx: number): any {
6274
return this.value;
6375
}
6476

@@ -73,30 +85,28 @@ class BufferArg extends Arg {
7385
this.length = this.value.length;
7486
}
7587

76-
getItem(idx: number) : any {
88+
getItem(idx: number): any {
7789
return this.value[idx];
7890
}
7991

8092
value: TypedArray;
8193
}
8294

83-
export
84-
function getArg(metadata: any, buffers: any) : Arg {
95+
export function getArg(metadata: any, buffers: any): Arg {
8596
if (Scalar.isScalar(metadata)) {
8697
return new ScalarArg(metadata);
8798
}
8899

89100
if (metadata['idx'] !== undefined) {
90-
return new BufferArg(metadata, buffers[metadata['idx']])
101+
return new BufferArg(metadata, buffers[metadata['idx']]);
91102
}
92103

93104
throw 'Could not process argument ' + metadata;
94105
}
95106

96-
export
97-
async function toBlob(canvas: HTMLCanvasElement) : Promise<Blob> {
107+
export async function toBlob(canvas: HTMLCanvasElement): Promise<Blob> {
98108
return new Promise<Blob>((resolve, reject) => {
99-
canvas.toBlob((blob) => {
109+
canvas.toBlob(blob => {
100110
if (blob == null) {
101111
return reject('Unable to create blob');
102112
}
@@ -106,35 +116,37 @@ async function toBlob(canvas: HTMLCanvasElement) : Promise<Blob> {
106116
});
107117
}
108118

109-
export
110-
async function toBytes(canvas: HTMLCanvasElement) : Promise<Uint8ClampedArray> {
119+
export async function toBytes(
120+
canvas: HTMLCanvasElement
121+
): Promise<Uint8ClampedArray> {
111122
const blob = await toBlob(canvas);
112123

113124
return new Promise<Uint8ClampedArray>((resolve, reject) => {
114125
const reader = new FileReader();
115126

116127
reader.onloadend = () => {
117-
if (typeof reader.result == 'string' || reader.result == null) {
118-
return reject('Unable to read blob');
119-
}
128+
if (typeof reader.result == 'string' || reader.result == null) {
129+
return reject('Unable to read blob');
130+
}
120131

121-
const bytes = new Uint8ClampedArray(reader.result);
122-
resolve(bytes);
132+
const bytes = new Uint8ClampedArray(reader.result);
133+
resolve(bytes);
123134
};
124135
reader.readAsArrayBuffer(blob);
125136
});
126137
}
127138

128-
export
129-
async function fromBytes(array: Uint8ClampedArray) : Promise<HTMLImageElement> {
139+
export async function fromBytes(
140+
array: Uint8ClampedArray
141+
): Promise<HTMLImageElement> {
130142
const blob = new Blob([array]);
131143

132144
return new Promise<HTMLImageElement>((resolve, reject) => {
133145
const img = new Image();
134146

135147
img.onload = () => {
136148
resolve(img);
137-
}
149+
};
138150

139151
img.src = URL.createObjectURL(blob);
140152
});

0 commit comments

Comments
 (0)