Skip to content

Commit 325a2eb

Browse files
committed
add eslint
1 parent 4c66766 commit 325a2eb

File tree

8 files changed

+1405
-35
lines changed

8 files changed

+1405
-35
lines changed

.eslintrc.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extends:
2+
- eslint:recommended
3+
- plugin:react/recommended
4+
- plugin:react/jsx-runtime
5+
- plugin:import/recommended
6+
- plugin:jsx-a11y/recommended
7+
- prettier
8+
9+
env:
10+
es2022: true
11+
browser: true
12+
13+
parserOptions:
14+
ecmaVersion: latest
15+
# sourceType: module
16+
ecmaFeatures:
17+
jsx: true
18+
19+
settings:
20+
import/resolver:
21+
node:
22+
paths: src
23+
extensions: [.js, .jsx]
24+
react:
25+
version: detect
26+
27+
rules:
28+
no-console: 1
29+
quotes: [2, single, { avoidEscape: true }]
30+
import/order:
31+
[
32+
2,
33+
{
34+
alphabetize: { order: asc, caseInsensitive: true },
35+
groups: [builtin, external, internal, [parent, sibling, index]],
36+
newlines-between: always,
37+
},
38+
]

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,27 @@
1212
"start": "vite",
1313
"build": "vite build",
1414
"preview": "vite preview",
15+
"format": "prettier --write src/ && eslint --fix src/",
1516
"deploy": "gh-pages -d dist",
1617
"predeploy": "yarn build"
1718
},
1819
"dependencies": {
1920
"react": "^18.2.0",
20-
"react-dom": "^18.2.0"
21+
"react-dom": "^18.2.0",
22+
"spectacle": "^9.6.0"
2123
},
2224
"devDependencies": {
2325
"@types/react": "^18.0.27",
2426
"@types/react-dom": "^18.0.10",
2527
"@vitejs/plugin-react": "^3.1.0",
28+
"eslint": "^8.34.0",
29+
"eslint-config-prettier": "^8.6.0",
30+
"eslint-plugin-import": "^2.27.5",
31+
"eslint-plugin-jsx-a11y": "^6.7.1",
32+
"eslint-plugin-react": "^7.32.2",
2633
"gh-pages": "^5.0.0",
2734
"prettier": "^2.8.3",
28-
"spectacle": "^9.6.0",
35+
"prop-types": "^15.8.1",
2936
"vite": "^4.1.0"
3037
},
3138
"prettier": {

src/components/Image/index.jsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { useState, useEffect, useRef } from 'react';
1+
import PropTypes from 'prop-types';
2+
import { useEffect, useRef } from 'react';
23

34
import loadingImg from '../../assets/loading.svg';
45
import './Image.css';
56

7+
const propTypes = {
8+
image: PropTypes.object, // ImageBitmap type,
9+
size: PropTypes.number,
10+
};
11+
612
function Image({ image, size }) {
713
const canvasRef = useRef();
814

@@ -22,10 +28,11 @@ function Image({ image, size }) {
2228

2329
return (
2430
<div className={`image ${done ? 'done' : ''}`}>
25-
<img src={loadingImg} className="loading" />
31+
<img src={loadingImg} className="loading" alt="Loading" />
2632
<canvas ref={canvasRef} style={{ width: `${w}px`, height: `${h}px` }} />
2733
</div>
2834
);
2935
}
3036

37+
Image.propTypes = propTypes;
3138
export default Image;

src/components/Slides/index.jsx

+14-16
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function Slides() {
5959

6060
<FlexBox alignItems="flex-end" justifyContent="unset" flexGrow={1}>
6161
<Text fontSize="0.85em" mb="0 !important" pb="0 !important">
62-
Aymen Elawad / 2023
62+
Aymen / 2023
6363
</Text>
6464
</FlexBox>
6565
</Slide>
@@ -137,7 +137,7 @@ function Slides() {
137137
<UnorderedList>
138138
<Appear>
139139
<ListItem>
140-
Some can be moved as a "Transferable Object"
140+
Some can be moved as a &quot;Transferable Object&quot;
141141
</ListItem>
142142
</Appear>
143143
</UnorderedList>
@@ -190,15 +190,15 @@ function Slides() {
190190

191191
<FlexBox justifyContent="space-around">
192192
<CodePane language="js" theme={syntax} showLineNumbers={false}>{`
193-
// main.js
194-
const worker = new Worker('worker.js')
193+
// main.js
194+
const worker = new Worker('worker.js')
195195
196-
worker.postMessage(10)
196+
worker.postMessage(10)
197197
198-
worker.onmessage = (e) => {
199-
console.log(e.data)
200-
}
201-
`}</CodePane>
198+
worker.onmessage = (e) => {
199+
console.log(e.data)
200+
}
201+
`}</CodePane>
202202

203203
<Appear>
204204
<CodePane language="js" theme={syntax} showLineNumbers={false}>{`
@@ -224,7 +224,7 @@ function Slides() {
224224
</Slide>
225225

226226
<Slide>
227-
<Heading>Info</Heading>
227+
<Heading>Resources</Heading>
228228

229229
<Text mb="2em !important">
230230
<Link
@@ -238,30 +238,28 @@ function Slides() {
238238

239239
<Appear>
240240
<Text fontSize="1em">
241-
Web Workers
241+
Browser
242242
<br />
243243
<Link
244244
href="https://developer.mozilla.org/docs/Web/API/Web_Workers_API"
245245
textDecoration="none"
246246
color="inherit"
247247
fontSize="1.5em"
248248
>
249-
developer.mozilla.org/docs/Web/API/Web_Workers_API
249+
Web Workers
250250
</Link>
251251
</Text>
252-
</Appear>
253252

254-
<Appear>
255253
<Text fontSize="1em">
256-
Node Worker Threads
254+
Node
257255
<br />
258256
<Link
259257
href="https://nodejs.org/api/worker_threads.html#worker-threads"
260258
textDecoration="none"
261259
color="inherit"
262260
fontSize="1.5em"
263261
>
264-
nodejs.org/api/worker_threads.html
262+
Worker Threads
265263
</Link>
266264
</Text>
267265
</Appear>

src/main.jsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ import Slides from './components/Slides';
88
const app = window.location.search === '?app';
99

1010
createRoot(document.getElementById('root')).render(
11-
<StrictMode>
12-
{app ? <App /> : <Slides />}
13-
</StrictMode>
11+
<StrictMode>{app ? <App /> : <Slides />}</StrictMode>
1412
);

src/worker-pool.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import resize from './resize';
22

3-
const maxCount = navigator.hardwareConcurrency;
43
const workers = [];
54
const callbacks = new Map();
65
let index = -1;
@@ -21,7 +20,8 @@ async function start(id, file, size, cb) {
2120
}
2221

2322
function setCount(c = 0) {
24-
const count = c > maxCount ? maxCount : c;
23+
const max = counts.at(-1);
24+
const count = c > max ? max : Math.max(0, c);
2525

2626
// Remove Workers
2727
while (count < workers.length) {
@@ -54,9 +54,10 @@ function reset(count) {
5454
}
5555

5656
const counts = (() => {
57-
const sqrt = Math.ceil(Math.sqrt(maxCount) + 1);
58-
const keys = Array(sqrt).keys();
59-
return [...keys].map((i) => 2 ** i).filter((i) => i <= maxCount);
57+
const limit = navigator.hardwareConcurrency;
58+
const sqrt = Math.ceil(Math.sqrt(limit) + 1);
59+
const keys = [...Array(sqrt).keys()];
60+
return keys.map((i) => 2 ** i).filter((i) => i <= limit);
6061
})();
6162

6263
export { start, setCount, reset, counts };

vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineConfig } from 'vite';
21
import react from '@vitejs/plugin-react';
2+
import { defineConfig } from 'vite';
33

44
export default defineConfig({
55
base: './',

0 commit comments

Comments
 (0)