Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit a40dc79

Browse files
authored
Add rule to use import and import type (#83)
This PR just adds rule `@typescript-eslint/consistent-type-imports` in eslint. (also sorts rules in .eslintrc and fixes code using `yarn lint:fix`) This rule helps understand if imported thing is just type, or part of actual logic.
1 parent 3e62906 commit a40dc79

18 files changed

+60
-62
lines changed

.eslintrc

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
"eslint:recommended",
77
"plugin:@typescript-eslint/eslint-recommended",
88
"plugin:@typescript-eslint/recommended",
9-
"prettier"
9+
"prettier",
1010
],
1111
"rules": {
12-
"react-hooks/rules-of-hooks": "error",
13-
"react-hooks/exhaustive-deps": "error",
14-
"@typescript-eslint/no-empty-function": "off",
1512
"@typescript-eslint/ban-ts-comment": "off",
13+
"@typescript-eslint/consistent-type-imports": "error",
14+
"@typescript-eslint/no-empty-function": "off",
1615
"@typescript-eslint/no-unused-vars": [
1716
"warn",
1817
{
1918
"argsIgnorePattern": "^_",
2019
"varsIgnorePattern": "^_",
21-
"caughtErrorsIgnorePattern": "^_"
22-
}
20+
"caughtErrorsIgnorePattern": "^_",
21+
},
2322
],
2423
"no-console": ["error", { "allow": ["warn", "error"] }],
25-
"react-refresh/only-export-components": ["warn", { "allowConstantExport": true }]
26-
}
24+
"react-hooks/exhaustive-deps": "error",
25+
"react-hooks/rules-of-hooks": "error",
26+
"react-refresh/only-export-components": ["warn", { "allowConstantExport": true }],
27+
},
2728
}

examples/minimal-react/src/components/App.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import VideoPlayer from "./VideoPlayer";
2-
import { SCREEN_SHARING_MEDIA_CONSTRAINTS, Client } from "@fishjam-dev/react-client";
2+
import type { Client } from "@fishjam-dev/react-client";
3+
import { SCREEN_SHARING_MEDIA_CONSTRAINTS } from "@fishjam-dev/react-client";
34
import { useState } from "react";
45
import { useConnect, useDisconnect, useClient, useStatus, useTracks } from "./client";
56

examples/minimal-react/src/components/VideoPlayer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { RefObject, useEffect, useRef } from "react";
1+
import type { RefObject } from "react";
2+
import { useEffect, useRef } from "react";
23

34
type Props = {
45
stream: MediaStream | null | undefined;

examples/minimal-react/src/components/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { create } from "@fishjam-dev/react-client";
2-
import { PeerMetadata, TrackMetadata } from "./App";
2+
import type { PeerMetadata, TrackMetadata } from "./App";
33

44
// Create a Membrane client instance
55
// remember to use FishjamContextProvider

examples/use-camera-and-microphone-example/src/Badge.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PeerStatus } from "@fishjam-dev/react-client";
1+
import type { PeerStatus } from "@fishjam-dev/react-client";
22

33
type Props = {
44
status: PeerStatus;

examples/use-camera-and-microphone-example/src/DeviceControls.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PeerStatus, UseMicrophoneResult, UseCameraResult, UseScreenShareResult } from "@fishjam-dev/react-client";
2-
import { TrackMetadata } from "./fishjamSetup";
1+
import type { PeerStatus, UseMicrophoneResult, UseCameraResult, UseScreenShareResult } from "@fishjam-dev/react-client";
2+
import type { TrackMetadata } from "./fishjamSetup";
33

44
type DeviceControlsProps = {
55
status: PeerStatus;

examples/use-camera-and-microphone-example/src/DeviceSelector.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ChangeEvent, useState } from "react";
1+
import type { ChangeEvent } from "react";
2+
import { useState } from "react";
23

34
type Props = {
45
name: string;

examples/use-camera-and-microphone-example/src/VideoPlayer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { RefObject, useEffect, useRef } from "react";
1+
import type { RefObject } from "react";
2+
import { useEffect, useRef } from "react";
23

34
type Props = {
45
stream: MediaStream | null | undefined;

examples/use-camera-and-microphone-example/src/fishjamSetup.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { z } from "zod";
2-
import { ClientEvents, create } from "@fishjam-dev/react-client";
2+
import type { ClientEvents } from "@fishjam-dev/react-client";
3+
import { create } from "@fishjam-dev/react-client";
34
import { useEffect, useState } from "react";
45

56
const peerMetadataSchema = z.object({

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Client.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import EventEmitter from "events";
2-
import TypedEmitter from "typed-emitter";
3-
import {
2+
import type TypedEmitter from "typed-emitter";
3+
import type {
44
AuthErrorReason,
55
BandwidthLimit,
66
Component,
77
ConnectConfig,
88
CreateConfig,
9-
FishjamClient,
109
MessageEvents,
1110
Peer,
1211
SimulcastConfig,
1312
TrackBandwidthLimit,
1413
TrackContext,
1514
TrackEncoding,
1615
} from "@fishjam-dev/ts-client";
17-
import { PeerId, PeerState, PeerStatus, Track, TrackId, TrackWithOrigin } from "./state.types";
18-
import { DeviceManager, DeviceManagerEvents } from "./DeviceManager";
19-
import { MediaDeviceType, ScreenShareManager, ScreenShareManagerConfig } from "./ScreenShareManager";
20-
import {
16+
import { FishjamClient } from "@fishjam-dev/ts-client";
17+
import type { PeerId, PeerState, PeerStatus, Track, TrackId, TrackWithOrigin } from "./state.types";
18+
import type { DeviceManagerEvents } from "./DeviceManager";
19+
import { DeviceManager } from "./DeviceManager";
20+
import type { MediaDeviceType, ScreenShareManagerConfig } from "./ScreenShareManager";
21+
import { ScreenShareManager } from "./ScreenShareManager";
22+
import type {
2123
DeviceManagerConfig,
2224
DeviceState,
2325
InitMediaConfig,

src/DeviceManager.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import type {
22
AudioOrVideoType,
33
CurrentDevices,
44
DeviceError,
@@ -9,14 +9,10 @@ import {
99
GetMedia,
1010
InitMediaConfig,
1111
Media,
12-
NOT_FOUND_ERROR,
13-
OVERCONSTRAINED_ERROR,
14-
parseError,
15-
PERMISSION_DENIED,
1612
StorageConfig,
17-
UNHANDLED_ERROR,
1813
UseUserMediaStartConfig,
1914
} from "./types";
15+
import { NOT_FOUND_ERROR, OVERCONSTRAINED_ERROR, parseError, PERMISSION_DENIED, UNHANDLED_ERROR } from "./types";
2016

2117
import { loadObject, saveObject } from "./localStorage";
2218
import {
@@ -27,8 +23,8 @@ import {
2723
} from "./constraints";
2824

2925
import EventEmitter from "events";
30-
import TypedEmitter from "typed-emitter";
31-
import { TrackType } from "./ScreenShareManager";
26+
import type TypedEmitter from "typed-emitter";
27+
import type { TrackType } from "./ScreenShareManager";
3228

3329
const removeExact = (
3430
trackConstraints: boolean | MediaTrackConstraints | undefined,

src/ScreenShareManager.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import EventEmitter from "events";
2-
import TypedEmitter from "typed-emitter";
3-
import { AudioOrVideoType, DeviceError, DevicesStatus, parseError } from "./types";
2+
import type TypedEmitter from "typed-emitter";
3+
import type { AudioOrVideoType, DeviceError, DevicesStatus } from "./types";
4+
import { parseError } from "./types";
45

56
export type TrackType = "audio" | "video" | "audiovideo";
67
export type MediaDeviceType = "displayMedia" | "userMedia";

src/create.tsx

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import {
2-
createContext,
3-
JSX,
4-
ReactNode,
5-
useCallback,
6-
useContext,
7-
useEffect,
8-
useMemo,
9-
useRef,
10-
useSyncExternalStore,
11-
} from "react";
1+
import type { JSX, ReactNode } from "react";
2+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
123
import type { Selector, State } from "./state.types";
13-
import { PeerStatus, TrackId, TrackWithOrigin } from "./state.types";
14-
import { ConnectConfig, CreateConfig } from "@fishjam-dev/ts-client";
15-
import {
4+
import type { PeerStatus, TrackId, TrackWithOrigin } from "./state.types";
5+
import type { ConnectConfig, CreateConfig } from "@fishjam-dev/ts-client";
6+
import type {
167
DeviceManagerConfig,
178
UseCameraAndMicrophoneResult,
189
UseCameraResult,
@@ -21,8 +12,9 @@ import {
2112
UseSetupMediaConfig,
2213
UseSetupMediaResult,
2314
} from "./types";
24-
import { Client, ClientApi, ClientEvents } from "./Client";
25-
import { MediaDeviceType, ScreenShareManagerConfig } from "./ScreenShareManager";
15+
import type { ClientApi, ClientEvents } from "./Client";
16+
import { Client } from "./Client";
17+
import type { MediaDeviceType, ScreenShareManagerConfig } from "./ScreenShareManager";
2618

2719
export type FishjamContextProviderProps = {
2820
children: ReactNode;

src/state.types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { TrackEncoding, VadStatus, SimulcastConfig } from "@fishjam-dev/ts-client";
2-
import { UseUserMediaState } from "./types";
3-
import { UseCameraAndMicrophoneResult } from "./types";
4-
import { Client } from "./Client";
5-
import { DeviceManager } from "./DeviceManager";
6-
import { ScreenShareManager } from "./ScreenShareManager";
2+
import type { UseUserMediaState } from "./types";
3+
import type { UseCameraAndMicrophoneResult } from "./types";
4+
import type { Client } from "./Client";
5+
import type { DeviceManager } from "./DeviceManager";
6+
import type { ScreenShareManager } from "./ScreenShareManager";
77

88
export type TrackId = string;
99
export type PeerId = string;

src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { SimulcastConfig, TrackBandwidthLimit } from "@fishjam-dev/ts-client";
2-
import { ScreenShareManagerConfig } from "./ScreenShareManager";
3-
import { Track } from "./state.types";
1+
import type { SimulcastConfig, TrackBandwidthLimit } from "@fishjam-dev/ts-client";
2+
import type { ScreenShareManagerConfig } from "./ScreenShareManager";
3+
import type { Track } from "./state.types";
44

55
export type AudioOrVideoType = "audio" | "video";
66

tests/globalSetupState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StartedDockerComposeEnvironment } from "testcontainers";
1+
import type { StartedDockerComposeEnvironment } from "testcontainers";
22

33
export type SetupState = {
44
fishjamContainer: StartedDockerComposeEnvironment | null;

tests/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { expect, Page, test } from "@playwright/test";
1+
import type { Page } from "@playwright/test";
2+
import { expect, test } from "@playwright/test";
23

34
export const joinRoomAndAddScreenShare = async (page: Page, roomId: string): Promise<string> =>
45
test.step("Join room and add track", async () => {

0 commit comments

Comments
 (0)