Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): fix lint errors+warnings #110

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:storybook/recommended",
"plugin:tailwindcss/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"tailwindcss/no-custom-classname": "off",
pongstr marked this conversation as resolved.
Show resolved Hide resolved
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
Expand Down
5 changes: 4 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{}
{
"tabWidth": 2,
"semi": true
}
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-tailwindcss": "^3.17.5",
"postcss": "^8.4.38",
"prettier": "3.3.2",
"run-script-os": "^1.1.6",
Expand Down
12 changes: 6 additions & 6 deletions src/AboutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ export const AboutModal = ({ open, onClose }: AboutModalProps) => {
const ref = useModalRef(open, true);

return (
<GenericModal ref={ref} className="min-w-min w-[70vw]" onClose={onClose}>
<div className="flex justify-between items-start">
<GenericModal ref={ref} className="w-[70vw] min-w-min" onClose={onClose}>
<div className="flex items-start justify-between">
<p>
The ZMK Project:{" "}
<ExternalLink href="https://zmk.dev/">website</ExternalLink>,{" "}
Expand All @@ -193,20 +193,20 @@ export const AboutModal = ({ open, onClose }: AboutModalProps) => {
</ExternalLink>
</p>
<button
className="p-1.5 rounded-md bg-gray-100 text-black hover:bg-gray-300"
className="rounded-md bg-gray-100 p-1.5 text-black hover:bg-gray-300"
onClick={onClose}
>
Close
</button>
</div>
<div>
<p className="py-1 mr-2">
<p className="mr-2 py-1">
ZMK Studio is made possible thanks to the generous donation of time
from our contributors, as well as the financial sponsorship from the
following vendors:
</p>
</div>
<div className="grid gap-2 auto-rows-auto grid-cols-[auto_minmax(min-content,1fr)] justify-items-center items-center">
<div className="grid auto-rows-auto grid-cols-[auto_minmax(min-content,1fr)] items-center justify-items-center gap-2">
{sponsors.map((s) => {
const heightVariants = {
[SponsorSize.Large]: "h-16",
Expand All @@ -218,7 +218,7 @@ export const AboutModal = ({ open, onClose }: AboutModalProps) => {
<React.Fragment key={s.level}>
<label>{s.level}</label>
<div
className={`grid grid-rows-1 gap-x-1 auto-cols-fr grid-flow-col justify-items-center items-center ${
className={`grid auto-cols-fr grid-flow-col grid-rows-1 items-center justify-items-center gap-x-1 ${
heightVariants[s.size]
}`}
>
Expand Down
70 changes: 36 additions & 34 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "./tauri/serial";
import Keyboard from "./keyboard/Keyboard";
import { UndoRedoContext, useUndoRedo } from "./undoRedo";
import { usePub, useSub } from "./usePubSub";
import { emitter, useSub } from "./usePubSub";
import { LockState } from "@zmkfirmware/zmk-studio-ts-client/core";
import { LockStateContext } from "./rpc/LockStateContext";
import { UnlockModal } from "./UnlockModal";
Expand Down Expand Up @@ -68,19 +68,17 @@ const TRANSPORTS: TransportFactory[] = [

async function listen_for_notifications(
notification_stream: ReadableStream<Notification>,
signal: AbortSignal
signal: AbortSignal,
): Promise<void> {
let reader = notification_stream.getReader();
const reader = notification_stream.getReader();
const onAbort = () => {
reader.cancel();
reader.releaseLock();
};
signal.addEventListener("abort", onAbort, { once: true });
do {
let pub = usePub();

try {
let { done, value } = await reader.read();
const { done, value } = await reader.read();
if (done) {
break;
}
Expand All @@ -90,10 +88,10 @@ async function listen_for_notifications(
}

console.log("Notification", value);
pub("rpc_notification", value);
await emitter.emit("rpc_notification", value);

const subsystem = Object.entries(value).find(
([_k, v]) => v !== undefined
([_k, v]) => v !== undefined,
);
if (!subsystem) {
continue;
Expand All @@ -109,28 +107,29 @@ async function listen_for_notifications(
const [eventName, eventData] = event;
const topic = ["rpc_notification", subId, eventName].join(".");

pub(topic, eventData);
await emitter.emit(topic, eventData);
} catch (e) {
signal.removeEventListener("abort", onAbort);
reader.releaseLock();
throw e;
}
// eslint-disable-next-line no-constant-condition
} while (true);

signal.removeEventListener("abort", onAbort);
reader.releaseLock();
notification_stream.cancel();
await notification_stream.cancel();
}

async function connect(
transport: RpcTransport,
setConn: Dispatch<ConnectionState>,
setConnectedDeviceName: Dispatch<string | undefined>,
signal: AbortSignal
signal: AbortSignal,
) {
let conn = await create_rpc_connection(transport, { signal });
const conn = create_rpc_connection(transport, { signal });

let details = await Promise.race([
const details = await Promise.race([
call_rpc(conn, { core: { getDeviceInfo: true } })
.then((r) => r?.core?.getDeviceInfo)
.catch((e) => {
Expand Down Expand Up @@ -171,12 +170,13 @@ function App() {
const [connectionAbort, setConnectionAbort] = useState(new AbortController());

const [lockState, setLockState] = useState<LockState>(
LockState.ZMK_STUDIO_CORE_LOCK_STATE_LOCKED
LockState.ZMK_STUDIO_CORE_LOCK_STATE_LOCKED,
);

useSub("rpc_notification.core.lockStateChanged", (ls) => {
setLockState(ls);
});
useSub<LockState>(
"rpc_notification.core.lockStateChanged",
(ls) => void setLockState(ls),
);

useEffect(() => {
if (!conn) {
Expand All @@ -189,32 +189,32 @@ function App() {
return;
}

let locked_resp = await call_rpc(conn.conn, {
const locked_resp = await call_rpc(conn.conn, {
core: { getLockState: true },
});

setLockState(
locked_resp.core?.getLockState ||
LockState.ZMK_STUDIO_CORE_LOCK_STATE_LOCKED
LockState.ZMK_STUDIO_CORE_LOCK_STATE_LOCKED,
);
}

updateLockState();
}, [conn, setLockState]);
updateLockState().then(console.info).catch(console.error);
}, [conn, reset, setLockState]);

const save = useCallback(() => {
async function doSave() {
if (!conn.conn) {
return;
}

let resp = await call_rpc(conn.conn, { keymap: { saveChanges: true } });
const resp = await call_rpc(conn.conn, { keymap: { saveChanges: true } });
if (!resp.keymap?.saveChanges || resp.keymap?.saveChanges.err) {
console.error("Failed to save changes", resp.keymap?.saveChanges);
}
}

doSave();
doSave().then(console.info).catch(console.error);
}, [conn]);

const discard = useCallback(() => {
Expand All @@ -223,7 +223,7 @@ function App() {
return;
}

let resp = await call_rpc(conn.conn, {
const resp = await call_rpc(conn.conn, {
keymap: { discardChanges: true },
});
if (!resp.keymap?.discardChanges) {
Expand All @@ -234,16 +234,16 @@ function App() {
setConn({ conn: conn.conn });
}

doDiscard();
}, [conn]);
doDiscard().then(console.info).catch(console.error);
}, [conn.conn, reset]);

const resetSettings = useCallback(() => {
async function doReset() {
if (!conn.conn) {
return;
}

let resp = await call_rpc(conn.conn, {
const resp = await call_rpc(conn.conn, {
core: { resetSettings: true },
});
if (!resp.core?.resetSettings) {
Expand All @@ -254,8 +254,8 @@ function App() {
setConn({ conn: conn.conn });
}

doReset();
}, [conn]);
doReset().then(console.info).catch(console.error);
}, [conn.conn, reset]);

const disconnect = useCallback(() => {
async function doDisconnect() {
Expand All @@ -268,16 +268,18 @@ function App() {
setConnectionAbort(new AbortController());
}

doDisconnect();
}, [conn]);
doDisconnect().then(console.info).catch(console.error);
}, [conn.conn, connectionAbort]);

const onConnect = useCallback(
(t: RpcTransport) => {
const ac = new AbortController();
setConnectionAbort(ac);
connect(t, setConn, setConnectedDeviceName, ac.signal);
connect(t, setConn, setConnectedDeviceName, ac.signal)
.then(console.info)
.catch(console.error);
},
[setConn, setConnectedDeviceName, setConnectedDeviceName]
[setConn, setConnectedDeviceName],
);

return (
Expand All @@ -295,7 +297,7 @@ function App() {
open={showLicenseNotice}
onClose={() => setShowLicenseNotice(false)}
/>
<div className="bg-base-100 text-base-content h-full max-h-[100vh] w-full max-w-[100vw] inline-grid grid-cols-[auto] grid-rows-[auto_1fr_auto] overflow-hidden">
<div className="inline-grid size-full max-h-screen max-w-[100vw] grid-cols-[auto] grid-rows-[auto_1fr_auto] overflow-hidden bg-base-100 text-base-content">
<AppHeader
connectedDeviceLabel={connectedDeviceName}
canUndo={canUndo}
Expand Down
6 changes: 3 additions & 3 deletions src/AppFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export const AppFooter = ({
onShowLicenseNotice,
}: AppFooterProps) => {
return (
<div className="grid justify-center p-1 bg-base-200">
<div className="grid justify-center bg-base-200 p-1">
<div>
<span>&copy; 2024 - The ZMK Contributors</span> -{" "}
<a className="hover:text-primary hover:cursor-pointer" onClick={onShowAbout}>
<a className="hover:cursor-pointer hover:text-primary" onClick={onShowAbout}>
About ZMK Studio
</a>{" "}
-{" "}
<a className="hover:text-primary hover:cursor-pointer" onClick={onShowLicenseNotice}>
<a className="hover:cursor-pointer hover:text-primary" onClick={onShowLicenseNotice}>
License NOTICE
</a>
</div>
Expand Down
Loading