Skip to content

Commit

Permalink
more lint + prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbandes committed Nov 15, 2023
1 parent 2109227 commit 157a49c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 34 deletions.
4 changes: 2 additions & 2 deletions tests/conformance/scripts/run-tests/runners/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export abstract class IndexedReadTestRunner {
messages: [],
statistics: [],
};
const knownSchemaIds: Set<number> = new Set();
const knownChannelIds: Set<number> = new Set();
const knownSchemaIds = new Set<number>();
const knownChannelIds = new Set<number>();
for (const record of testCase.records) {
switch (record.type) {
case "Schema":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class TypescriptIndexedReaderTestRunner extends IndexedReadTestRu
async runReadTest(filePath: string): Promise<IndexedReadTestResult> {
const handle = await fs.open(filePath, "r");
try {
return await this._run(handle);
return await this.#run(handle);
} finally {
await handle.close();
}
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class TypescriptIndexedReaderTestRunner extends IndexedReadTestRu
return true;
}

private async _run(fileHandle: fs.FileHandle): Promise<IndexedReadTestResult> {
async #run(fileHandle: fs.FileHandle): Promise<IndexedReadTestResult> {
let buffer = new ArrayBuffer(4096);
const readable = {
size: async () => BigInt((await fileHandle.stat()).size),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { WriteTestRunner } from "./TestRunner";
type JsonValue<T> = T extends number | bigint | string
? string
: T extends Uint8Array
? number[]
: T extends Map<infer K, infer V>
? K extends number | bigint | string
? Record<JsonValue<K>, JsonValue<V>>
: never
: never;
? number[]
: T extends Map<infer K, infer V>
? K extends number | bigint | string
? Record<JsonValue<K>, JsonValue<V>>
: never
: never;

type JsonRecord<R extends keyof McapTypes.McapRecords> = {
type: R;
Expand Down
44 changes: 30 additions & 14 deletions website/src/components/McapRecordingDemo/McapRecordingDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const RADIANS_PER_DEGREE = Math.PI / 180;

// Adapted from https://github.com/mrdoob/three.js/blob/master/src/math/Quaternion.js
function deviceOrientationToPose(
event: DeviceOrientationEvent
event: DeviceOrientationEvent,
): ProtobufObject<PoseInFrame> {
const alpha = (event.alpha ?? 0) * RADIANS_PER_DEGREE; // z angle
const beta = (event.beta ?? 0) * RADIANS_PER_DEGREE; // x angle
Expand Down Expand Up @@ -133,7 +133,9 @@ export function McapRecordingDemo(): JSX.Element {
if (!recording) {
return;
}
const timeout = setTimeout(() => setRecording(false), 30000);
const timeout = setTimeout(() => {
setRecording(false);
}, 30000);
return () => {
clearTimeout(timeout);
};
Expand Down Expand Up @@ -165,7 +167,7 @@ export function McapRecordingDemo(): JSX.Element {
return () => {
window.removeEventListener(
"deviceorientation",
handleDeviceOrientationEvent
handleDeviceOrientationEvent,
);
};
}, [addPoseMessage, recording, recordOrientation]);
Expand All @@ -178,7 +180,9 @@ export function McapRecordingDemo(): JSX.Element {

const cleanup = startVideoStream({
video,
onStart: () => setVideoStarted(true),
onStart: () => {
setVideoStarted(true);
},
onError: (err) => {
console.error(err);
setVideoPermissionError(true);
Expand All @@ -201,7 +205,9 @@ export function McapRecordingDemo(): JSX.Element {
const stopCapture = startVideoCapture({
video,
frameDurationSec: 1 / 30,
onFrame: (blob) => addCameraImage(blob),
onFrame: (blob) => {
addCameraImage(blob);
},
});
return () => {
stopCapture();
Expand Down Expand Up @@ -234,7 +240,7 @@ export function McapRecordingDemo(): JSX.Element {
.catch(console.error);
}
},
[recordOrientation, recording]
[recordOrientation, recording],
);

const onDownloadClick = useCallback(
Expand All @@ -249,7 +255,7 @@ export function McapRecordingDemo(): JSX.Element {
// Create a date+time string in the local timezone to use as the filename
const date = new Date();
const localTime = new Date(
date.getTime() - date.getTimezoneOffset() * 60_000
date.getTime() - date.getTimezoneOffset() * 60_000,
)
.toISOString()
.replace(/\..+$/, "")
Expand All @@ -264,7 +270,7 @@ export function McapRecordingDemo(): JSX.Element {
setShowDownloadInfo(true);
})();
},
[state]
[state],
);

return (
Expand All @@ -282,15 +288,19 @@ export function McapRecordingDemo(): JSX.Element {
<input
type="checkbox"
checked={recordVideo}
onChange={(event) => setRecordVideo(event.target.checked)}
onChange={(event) => {
setRecordVideo(event.target.checked);
}}
/>
Camera
</label>
<label>
<input
type="checkbox"
checked={recordMouse}
onChange={(event) => setRecordMouse(event.target.checked)}
onChange={(event) => {
setRecordMouse(event.target.checked);
}}
/>
Mouse position
</label>
Expand All @@ -299,7 +309,9 @@ export function McapRecordingDemo(): JSX.Element {
<input
type="checkbox"
checked={recordOrientation}
onChange={(event) => setRecordOrientation(event.target.checked)}
onChange={(event) => {
setRecordOrientation(event.target.checked);
}}
/>
Orientation
</label>
Expand All @@ -319,7 +331,9 @@ export function McapRecordingDemo(): JSX.Element {
aria-label="Close"
className={cx("clean-btn", styles.downloadInfoCloseButton)}
type="button"
onClick={() => setShowDownloadInfo(false)}
onClick={() => {
setShowDownloadInfo(false);
}}
>
<span aria-hidden="true">&times;</span>
</button>
Expand Down Expand Up @@ -352,7 +366,7 @@ export function McapRecordingDemo(): JSX.Element {
className={cx(
"button",
"button--success",
styles.downloadButton
styles.downloadButton,
)}
onClick={onDownloadClick}
>
Expand Down Expand Up @@ -428,7 +442,9 @@ export function McapRecordingDemo(): JSX.Element {
) : (
<span
className={styles.videoPlaceholderText}
onClick={() => setRecordVideo(true)}
onClick={() => {
setRecordVideo(true);
}}
>
Enable “Camera” to record video
</span>
Expand Down
4 changes: 2 additions & 2 deletions website/src/components/McapRecordingDemo/Recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export class Recorder extends EventEmitter<RecorderEvents> {
const poseChannel = await addProtobufChannel(
this.#writer,
"pose",
foxgloveMessageSchemas.PoseInFrame
foxgloveMessageSchemas.PoseInFrame,
);
const cameraChannel = await addProtobufChannel(
this.#writer,
"camera",
foxgloveMessageSchemas.CompressedImage
foxgloveMessageSchemas.CompressedImage,
);

this.#emit();
Expand Down
10 changes: 5 additions & 5 deletions website/src/components/McapRecordingDemo/addProtobufChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export type ProtobufChannelInfo = {
export async function addProtobufChannel(
writer: McapWriter,
topic: string,
rootSchema: FoxgloveMessageSchema
rootSchema: FoxgloveMessageSchema,
): Promise<ProtobufChannelInfo> {
const schemaName = `foxglove.${rootSchema.name}`;

const root = new protobufjs.Root();
root.addJSON(
protobufjs.common.get("google/protobuf/timestamp.proto")!.nested!
protobufjs.common.get("google/protobuf/timestamp.proto")!.nested!,
);
root.addJSON(
protobufjs.common.get("google/protobuf/duration.proto")!.nested!
protobufjs.common.get("google/protobuf/duration.proto")!.nested!,
);

function addMessageSchema(msgSchema: FoxgloveMessageSchema) {
const nestedEnums = Object.values(foxgloveEnumSchemas).filter(
(enumSchema) => enumSchema.parentSchemaName === msgSchema.name
(enumSchema) => enumSchema.parentSchemaName === msgSchema.name,
);
const protoSrc = generateProto(msgSchema, nestedEnums);
const parseResult = protobufjs.parse(protoSrc, { keepCase: true });
Expand All @@ -51,7 +51,7 @@ export async function addProtobufChannel(
// protobufjs does not generate dependency fields, so fix them up manually
if (file.name == undefined || file.name.length === 0) {
throw new Error(
`Missing filename for ${file.package ?? "(unknown package)"}`
`Missing filename for ${file.package ?? "(unknown package)"}`,
);
}
if (file.name !== "google_protobuf.proto") {
Expand Down
6 changes: 3 additions & 3 deletions website/src/components/McapRecordingDemo/videoCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function startVideoStream(params: VideoStreamParams): () => void {
stream = videoStream;
params.video.srcObject = videoStream;
await params.video.play();
if (canceled) {
if (canceled as boolean) {
return;
}
params.onStart();
Expand Down Expand Up @@ -68,7 +68,7 @@ export function startVideoCapture(params: VideoCaptureParams): () => void {

async function startVideoCaptureAsync(
params: VideoCaptureParams,
signal: AbortSignal
signal: AbortSignal,
) {
const { video, onFrame, frameDurationSec } = params;
const canvas = document.createElement("canvas");
Expand All @@ -93,7 +93,7 @@ async function startVideoCaptureAsync(
framePromise = undefined;
},
"image/jpeg",
0.8
0.8,
);
});
}, frameDurationSec * 1000);
Expand Down

0 comments on commit 157a49c

Please sign in to comment.