Skip to content

Commit 81d3845

Browse files
committed
code cleanup based on Biome recommendations
1 parent 6d5f0ff commit 81d3845

63 files changed

Lines changed: 230 additions & 196 deletions

Some content is hidden

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

webapp/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"license": "MIT",
1111
"scripts": {
1212
"build": "vite build",
13+
"check": "biome check ./src",
1314
"dev": "vite",
15+
"format": "biome format ./src",
16+
"lint": "biome lint ./src",
1417
"serve": "vite preview",
15-
"start": "vite",
16-
"lint": "biome lint ./src"
18+
"start": "vite"
1719
},
1820
"dependencies": {
1921
"@mdi/js": "7.4.47",

webapp/src/components/Canvas.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { mdiBrightness6 } from '@mdi/js';
2-
import { Component, createEffect, createSignal, onCleanup, onMount } from 'solid-js';
2+
import { type Component, createEffect, createSignal, onCleanup, onMount } from 'solid-js';
33

4-
import { Icon } from './Icon';
5-
import { Tooltip } from './Tooltip';
64
import { Device } from '../config/devices';
7-
import { DisplayBrightness, DisplayOrientation } from '../services/Display';
85
import { WebAppSidebar } from '../extensions/WebApp';
6+
import { DisplayBrightness, DisplayOrientation } from '../services/Display';
7+
import { Icon } from './Icon';
8+
import { Tooltip } from './Tooltip';
99

10-
const [getStrength, setStrength] = createSignal<number>(Math.pow(2, 8) - 1);
10+
const [getStrength, setStrength] = createSignal<number>(2 ** 8 - 1);
1111

1212
export const Strength: Component = () => (
1313
<div class="flex items-center mt-3">
1414
<Icon
1515
class="mr-2"
1616
path={mdiBrightness6}
1717
/>
18-
<Tooltip text={`Brush brightness ${Math.ceil(getStrength() / (Math.pow(2, 8) - 1) * 100)} %`}>
18+
<Tooltip text={`Brush brightness ${Math.ceil(getStrength() / (2 ** 8 - 1) * 100)} %`}>
1919
<input
2020
class="w-full"
21-
max={Math.pow(2, 8) - 1}
21+
max={2 ** 8 - 1}
2222
min="1"
2323
onInput={(e) =>
2424
setStrength(parseFloat(e.currentTarget.value))
@@ -91,7 +91,7 @@ export const Canvas: Component<{
9191
ctx.globalAlpha = 1;
9292
ctx.fillStyle = 'black';
9393
ctx.fillRect(0, 0, canvasRef.width, canvasRef.height);
94-
ctx.globalAlpha = DisplayBrightness() / (Math.pow(2, 8) - 1) / 2 + 0.5;
94+
ctx.globalAlpha = DisplayBrightness() / (2 ** 8 - 1) / 2 + 0.5;
9595
if (Device.LED_GEOMETRY === 'circular') {
9696
for (let x = 0; x < Device.GRID_COLUMNS; ++x) {
9797
for (let y = 0; y < Device.GRID_ROWS; ++y) {
@@ -124,7 +124,7 @@ export const Canvas: Component<{
124124
};
125125

126126
const toColor = (brightness: number) => {
127-
const value = brightness === 0 ? Device.LED_BASE_TONE : (brightness - 1) / (Math.pow(2, 8) - 2) * (Math.pow(2, 8) - 2 - Device.LED_BASE_BRIGHTNESS) + 1 + Device.LED_BASE_BRIGHTNESS;
127+
const value = brightness === 0 ? Device.LED_BASE_TONE : (brightness - 1) / (2 ** 8 - 2) * (2 ** 8 - 2 - Device.LED_BASE_BRIGHTNESS) + 1 + Device.LED_BASE_BRIGHTNESS;
128128
return `rgb(${value},${value},${value})`;
129129
};
130130

webapp/src/components/Clock.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import { mdiClockTimeEightOutline, mdiClockTimeElevenOutline, mdiClockTimeFiveOutline, mdiClockTimeFourOutline, mdiClockTimeNineOutline, mdiClockTimeOneOutline, mdiClockTimeSevenOutline, mdiClockTimeSixOutline, mdiClockTimeTenOutline, mdiClockTimeThreeOutline, mdiClockTimeTwelveOutline, mdiClockTimeTwoOutline } from "@mdi/js";
22
import { createSignal, onCleanup } from "solid-js";
33

4-
const clocks = [
5-
mdiClockTimeTwelveOutline,
6-
mdiClockTimeOneOutline,
7-
mdiClockTimeTwoOutline,
8-
mdiClockTimeThreeOutline,
9-
mdiClockTimeFourOutline,
10-
mdiClockTimeFiveOutline,
11-
mdiClockTimeSixOutline,
12-
mdiClockTimeSevenOutline,
13-
mdiClockTimeEightOutline,
14-
mdiClockTimeNineOutline,
15-
mdiClockTimeTenOutline,
16-
mdiClockTimeElevenOutline,
17-
];
18-
194
const hour = () => {
205
const now = new Date();
216
const hour = now.getHours();
22-
return clocks[(now.getMinutes() >= 30 ? hour + 1 : hour) % 12];
7+
return [
8+
mdiClockTimeTwelveOutline,
9+
mdiClockTimeOneOutline,
10+
mdiClockTimeTwoOutline,
11+
mdiClockTimeThreeOutline,
12+
mdiClockTimeFourOutline,
13+
mdiClockTimeFiveOutline,
14+
mdiClockTimeSixOutline,
15+
mdiClockTimeSevenOutline,
16+
mdiClockTimeEightOutline,
17+
mdiClockTimeNineOutline,
18+
mdiClockTimeTenOutline,
19+
mdiClockTimeElevenOutline,
20+
][(now.getMinutes() >= 30 ? hour + 1 : hour) % 12];
2321
};
2422

2523
const [getIcon, setIcon] = createSignal(hour());

webapp/src/components/File.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const fileImport = (callback: (frames: number[][]) => void) => {
1212
let x = 0;
1313
row.split(",").forEach((column) => {
1414
if (column.length && x < Device.GRID_COLUMNS) {
15-
frame.push(parseInt(column));
15+
frame.push(parseInt(column, 10));
1616
++x;
1717
}
1818
});
@@ -54,13 +54,13 @@ export const fileImport = (callback: (frames: number[][]) => void) => {
5454
const imgData = ctx?.getImageData(0, 0, Device.GRID_COLUMNS, Device.GRID_ROWS);
5555
if (imgData) {
5656
const frame: number[] = [];
57-
for (var i = 0; i < imgData.data.length; i += 4) {
57+
for (let i = 0; i < imgData.data.length; i += 4) {
5858
frame.push(imgData.data[i] + imgData.data[i + 1] + imgData.data[i + 2]);
5959
}
6060
const avg = frame.reduce((p, c, i) => {
6161
return p + (c - p) / (i + 1);
6262
}, 0);
63-
callback([frame.map((i) => (i > avg ? Math.pow(2, 8) - 1 : 0))]);
63+
callback([frame.map((i) => (i > avg ? 2 ** 8 - 1 : 0))]);
6464
}
6565
};
6666
};

webapp/src/components/Icon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from 'solid-js';
1+
import type { Component } from 'solid-js';
22

33
const fill = 'currentColor';
44
const viewBox = '0 0 24 24';

webapp/src/components/Toast.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mdiInformation } from '@mdi/js';
2-
import { createContext, createSignal, ParentComponent, useContext } from 'solid-js';
2+
import { createContext, createSignal, type ParentComponent, useContext } from 'solid-js';
33

44
import { Icon } from './Icon';
55

webapp/src/components/Tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, JSX } from 'solid-js';
1+
import type { Component, JSX } from 'solid-js';
22

33
export const Tooltip: Component<{
44
text: string;

webapp/src/config/devices.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ interface Parameters {
1717
const IkeaFrekvensParameters: Parameters = {
1818
GRID_COLUMNS: 16, // px
1919
GRID_ROWS: 16, // px
20-
LED_BASE_BRIGHTNESS: Math.pow(2, 6),
21-
LED_BASE_TONE: Math.pow(2, 4),
20+
LED_BASE_BRIGHTNESS: 2 ** 6,
21+
LED_BASE_TONE: 2 ** 4,
2222
LED_GEOMETRY: 'circular',
2323
LED_SIZE_HORIZONTAL: 4, // mm
2424
LED_SIZE_VERTICAL: 4, // mm
2525
MANUFACTURER: "IKEA",
2626
MODEL: "Frekvens",
27-
PITCH_HORIZONTAL: 6, // mm
28-
PITCH_VERTICAL: 6, // mm
27+
PITCH_HORIZONTAL: 6, // mm
28+
PITCH_VERTICAL: 6, // mm
2929
}
3030

3131
const IkeaObegransadParameters: Parameters = {
3232
GRID_COLUMNS: 16, // px
3333
GRID_ROWS: 16, // px
34-
LED_BASE_BRIGHTNESS: Math.pow(2, 5),
34+
LED_BASE_BRIGHTNESS: 2 ** 5,
3535
LED_BASE_TONE: 0,
3636
LED_GEOMETRY: 'rectangular',
3737
LED_SIZE_HORIZONTAL: 12.5, // mm

webapp/src/extensions/Infrared.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { mdiRemoteTv, mdiRemoteTvOff } from '@mdi/js';
2-
import { Component, createSignal } from 'solid-js';
2+
import { type Component, createSignal } from 'solid-js';
33

44
import { Icon } from '../components/Icon';
55
import { Tooltip } from '../components/Tooltip';
66
import { EXTENSION_MICROPHONE, EXTENSION_PHOTOCELL, EXTENSION_PLAYLIST } from '../config/modules';
7+
import { name as ExtensionsName } from '../services/Extensions';
8+
import { name as MicName } from './Microphone';
79
import { name as PhotocellName } from './Photocell';
810
import { name as PlaylistName } from './Playlist';
9-
import { name as MicName } from './Microphone';
1011
import { WebSocketWS } from './WebSocket';
11-
import { name as ExtensionsName } from '../services/Extensions';
1212

1313
export const name = 'Infrared';
1414

@@ -55,6 +55,7 @@ export const Actions: Component = () => (
5555
<button
5656
class={`w-full ${getActive() ? 'action-activated' : 'action-deactivated'}`}
5757
onclick={handleActive}
58+
type="button"
5859
>
5960
<Icon path={getActive() ? mdiRemoteTv : mdiRemoteTvOff} />
6061
</button>
@@ -102,6 +103,7 @@ export const MainThird: Component = () => (
102103
<button
103104
class={`mt-3 w-full ${getActive() ? 'action-activated' : 'action-deactivated'}`}
104105
onclick={handleActive}
106+
type="button"
105107
>
106108
<Icon
107109
class="mr-2"

webapp/src/extensions/Message.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { mdiMessage, mdiSend } from '@mdi/js';
22
import Cookies from 'js-cookie';
3-
import { Component, createSignal, For } from 'solid-js';
3+
import { type Component, createSignal, For } from 'solid-js';
44

55
import { Icon } from '../components/Icon';
66
import { Toast } from '../components/Toast';
77
import { Tooltip } from '../components/Tooltip';
88
import { Device } from '../config/devices';
9-
import { WebSocketWS } from './WebSocket';
109
import { name as DisplayName } from '../services/Display';
1110
import { name as ExtensionsName } from '../services/Extensions';
1211
import { FontsList } from '../services/Fonts';
12+
import { WebSocketWS } from './WebSocket';
1313

1414
export const name = 'Message';
1515

@@ -26,7 +26,7 @@ export const receiver = (json: any) => {
2626
const { toast } = Toast();
2727

2828
const event = (message: string) => {
29-
toast(message, Math.pow(2, 7) * (Device.GRID_COLUMNS + message.length * 6.8));
29+
toast(message, 2 ** 7 * (Device.GRID_COLUMNS + message.length * 6.8));
3030
};
3131

3232
export const Link: Component = () => (
@@ -90,9 +90,9 @@ export const MainThird: Component = () => {
9090
<input
9191
class="pr-14 text-right w-full"
9292
min="0"
93-
max={Math.pow(2, 8) - 1}
93+
max={2 ** 8 - 1}
9494
onchange={(e) =>
95-
setRepeat(parseInt(e.currentTarget.value))
95+
setRepeat(parseInt(e.currentTarget.value, 10))
9696
}
9797
type="number"
9898
value={getRepeat()}
@@ -114,7 +114,7 @@ export const MainThird: Component = () => {
114114
>
115115
<For each={FontsList()}>
116116
{
117-
(fontName) => <option selected={fontName == getFont()}>{fontName}</option>
117+
(fontName) => <option selected={fontName === getFont()}>{fontName}</option>
118118
}
119119
</For>
120120
</select>
@@ -123,6 +123,7 @@ export const MainThird: Component = () => {
123123
class="action-positive mt-3 w-full"
124124
disabled={getMessage().length === 0}
125125
onclick={handleSend}
126+
type="button"
126127
>
127128
<Icon
128129
class="mr-2"

0 commit comments

Comments
 (0)