Skip to content

Commit d5613e1

Browse files
shiffmanjoeyklee
authored andcommitted
Fixing an issue with prettier and eslint (#324)
* Fixing an issue with prettier and eslint There is a conflict between arrow syntax rules in airbnb eslint configuration and the way default prettier works in VSCode. These additional setting should help anyone using VSCode with autoformat + prettier to not run into problems building the library. I am open to better ways of handling this of course! (Note the changes in ImageClassifier are trivial and just testing). * adding eslint-config-prettier as dev dependency * trivial change to run tests again
1 parent 94626fb commit d5613e1

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "airbnb-base",
2+
"extends": ["airbnb-base", "prettier"],
33
"globals": {
44
"fetch": false,
55
"document": true

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ examples/es6/node_modules
33
experiments/node_modules
44
node_modules
55
**/npm-debug.log
6-
.vscode
76
*.DS_STORE
87
experiments
98
manual-test

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"prettier.trailingComma": "all",
3+
"prettier.printWidth": 100,
4+
"prettier.arrowParens": "avoid"
5+
}

package-lock.json

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"cz-conventional-changelog": "2.1.0",
4444
"eslint": "4.18.2",
4545
"eslint-config-airbnb-base": "12.1.0",
46+
"eslint-config-prettier": "^4.1.0",
4647
"eslint-loader": "2.0.0",
4748
"eslint-plugin-import": "2.9.0",
4849
"extract-text-webpack-plugin": "4.0.0-beta.0",

src/ImageClassifier/index.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018 ml5
1+
// Copyright (c) 2019 ml5
22
//
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
@@ -58,7 +58,7 @@ class ImageClassifier {
5858
await tf.nextFrame();
5959

6060
if (this.video && this.video.readyState === 0) {
61-
await new Promise((resolve) => {
61+
await new Promise(resolve => {
6262
this.video.onloadeddata = () => resolve();
6363
});
6464
}
@@ -81,17 +81,28 @@ class ImageClassifier {
8181
numberOfClasses = inputNumOrCallback;
8282
} else if (inputNumOrCallback instanceof HTMLImageElement) {
8383
imgToPredict = inputNumOrCallback;
84-
} else if (typeof inputNumOrCallback === 'object' && inputNumOrCallback.elt instanceof HTMLImageElement) {
84+
} else if (
85+
typeof inputNumOrCallback === 'object' &&
86+
inputNumOrCallback.elt instanceof HTMLImageElement
87+
) {
8588
imgToPredict = inputNumOrCallback.elt; // Handle p5.js image
8689
} else if (inputNumOrCallback instanceof HTMLCanvasElement) {
8790
imgToPredict = inputNumOrCallback;
88-
} else if (typeof inputNumOrCallback === 'object' && inputNumOrCallback.elt instanceof HTMLCanvasElement) {
91+
} else if (
92+
typeof inputNumOrCallback === 'object' &&
93+
inputNumOrCallback.elt instanceof HTMLCanvasElement
94+
) {
8995
imgToPredict = inputNumOrCallback.elt; // Handle p5.js image
90-
} else if (typeof inputNumOrCallback === 'object' && inputNumOrCallback.canvas instanceof HTMLCanvasElement) {
96+
} else if (
97+
typeof inputNumOrCallback === 'object' &&
98+
inputNumOrCallback.canvas instanceof HTMLCanvasElement
99+
) {
91100
imgToPredict = inputNumOrCallback.canvas; // Handle p5.js image
92101
} else if (!(this.video instanceof HTMLVideoElement)) {
93102
// Handle unsupported input
94-
throw new Error('No input image provided. If you want to classify a video, pass the video element in the constructor. ');
103+
throw new Error(
104+
'No input image provided. If you want to classify a video, pass the video element in the constructor. ',
105+
);
95106
}
96107

97108
if (typeof numOrCallback === 'number') {
@@ -126,7 +137,10 @@ const imageClassifier = (modelName, videoOrOptionsOrCallback, optionsOrCallback,
126137

127138
if (videoOrOptionsOrCallback instanceof HTMLVideoElement) {
128139
video = videoOrOptionsOrCallback;
129-
} else if (typeof videoOrOptionsOrCallback === 'object' && videoOrOptionsOrCallback.elt instanceof HTMLVideoElement) {
140+
} else if (
141+
typeof videoOrOptionsOrCallback === 'object' &&
142+
videoOrOptionsOrCallback.elt instanceof HTMLVideoElement
143+
) {
130144
video = videoOrOptionsOrCallback.elt; // Handle a p5.js video element
131145
} else if (typeof videoOrOptionsOrCallback === 'object') {
132146
options = videoOrOptionsOrCallback;

0 commit comments

Comments
 (0)