Skip to content

Commit 0e4a4cd

Browse files
authored
Add eslint and prettier + fix pytest error (#78)
* add eslint and prettier * add eslintrc * get eslint working interface-name-prefix has been removed from recommended so it was causing errors. I also fixed a few mistakes I made * run lint * fixing py.test error
1 parent fa68a1e commit 0e4a4cd

File tree

11 files changed

+81
-37
lines changed

11 files changed

+81
-37
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ before_script:
2727
script:
2828
- py.test
2929
- npm test
30+
- npm run lint:check
3031
# Check docs can be build + links
3132
- pushd docs
3233
- make html
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
coverage
4+
**/*.d.ts
5+
tests
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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/no-unused-vars': ['warn', { args: 'none' }],
16+
'@typescript-eslint/no-explicit-any': 'off',
17+
'@typescript-eslint/no-namespace': 'off',
18+
'@typescript-eslint/no-use-before-define': 'off',
19+
'@typescript-eslint/quotes': [
20+
'error',
21+
'single',
22+
{ avoidEscape: true, allowTemplateLiterals: false }
23+
],
24+
curly: ['error', 'all'],
25+
eqeqeq: 'error',
26+
'prefer-arrow-callback': 'error'
27+
}
28+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
**/node_modules
3+
**/lib
4+
**/package.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

{{cookiecutter.github_project_name}}/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"clean:lib": "rimraf lib",
3939
"clean:labextension": "rimraf {{ cookiecutter.python_package_name }}/labextension",
4040
"clean:nbextension": "rimraf {{ cookiecutter.python_package_name }}/nbextension/static/index.js",
41+
"lint": "eslint . --ext .ts,.tsx --fix",
42+
"lint:check": "eslint . --ext .ts,.tsx",
4143
"prepack": "npm run build:lib",
4244
"test": "npm run test:firefox",
4345
"test:chrome": "karma start --browsers=Chrome tests/karma.conf.js",
@@ -58,8 +60,13 @@
5860
"@types/mocha": "^5.2.5",
5961
"@types/node": "^10.11.6",
6062
"@types/webpack-env": "^1.13.6",
63+
"@typescript-eslint/eslint-plugin": "^3.6.0",
64+
"@typescript-eslint/parser": "^3.6.0",
6165
"acorn": "^7.2.0",
6266
"css-loader": "^3.2.0",
67+
"eslint": "^7.4.0",
68+
"eslint-config-prettier": "^6.11.0",
69+
"eslint-plugin-prettier": "^3.1.4",
6370
"expect.js": "^0.3.1",
6471
"fs-extra": "^7.0.0",
6572
"karma": "^3.1.0",
@@ -73,6 +80,7 @@
7380
"mkdirp": "^0.5.1",
7481
"mocha": "^5.2.0",
7582
"npm-run-all": "^4.1.3",
83+
"prettier": "^2.0.5",
7684
"rimraf": "^2.6.2",
7785
"source-map-loader": "^0.2.4",
7886
"style-loader": "^1.0.0",

{{cookiecutter.github_project_name}}/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
],
9191
extras_require = {
9292
'test': [
93-
'pytest>=3.6',
93+
'pytest>=4.6',
9494
'pytest-cov',
9595
'nbval',
9696
],

{{cookiecutter.github_project_name}}/src/extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
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/{{ cookiecutter.python_package_name }}';
11+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12+
(window as any).__webpack_public_path__ =
13+
document.querySelector('body')!.getAttribute('data-base-url') +
14+
'nbextensions/{{ cookiecutter.python_package_name }}';
1215

1316
export * from './index';

{{cookiecutter.github_project_name}}/src/plugin.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
11
// Copyright (c) {{ cookiecutter.author_name }}
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 = '{{ cookiecutter.npm_package_name }}:plugin';
2315

2416
/**
2517
* The example plugin.
2618
*/
27-
const examplePlugin: IPlugin<Application<Widget>, void> = {
19+
const examplePlugin: IPlugin<Application<Widget>, void> = ({
2820
id: EXTENSION_ID,
2921
requires: [IJupyterWidgetRegistry],
3022
activate: activateWidgetExtension,
31-
autoStart: true
32-
} as unknown as IPlugin<Application<Widget>, void>;
23+
autoStart: true,
24+
} as unknown) as IPlugin<Application<Widget>, void>;
3325
// the "as unknown as ..." typecast above is solely to support JupyterLab 1
3426
// and 2 in the same codebase and should be removed when we migrate to Lumino.
3527

3628
export default examplePlugin;
3729

38-
3930
/**
4031
* Activate the widget extension.
4132
*/
42-
function activateWidgetExtension(app: Application<Widget>, registry: IJupyterWidgetRegistry): void {
33+
function activateWidgetExtension(
34+
app: Application<Widget>,
35+
registry: IJupyterWidgetRegistry
36+
): void {
4337
registry.registerWidget({
4438
name: MODULE_NAME,
4539
version: MODULE_VERSION,

{{cookiecutter.github_project_name}}/src/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) {{ cookiecutter.author_name }}
22
// Distributed under the terms of the Modified BSD License.
33

4+
// eslint-disable-next-line @typescript-eslint/no-var-requires
45
const data = require('../package.json');
56

67
/**

0 commit comments

Comments
 (0)