web/eslint: add better import order rules

This commit is contained in:
Tulir Asokan 2024-10-10 02:03:01 +03:00
parent 09ca63742f
commit 0dc278523a
13 changed files with 48 additions and 32 deletions

View file

@ -19,13 +19,29 @@ export default tseslint.config(
"react-refresh": reactRefresh,
"import": pluginImport,
},
settings: {
"import/extensions": [".ts", ".tsx", ".css"],
},
rules: {
...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": [
"warn",
{allowConstantExport: true},
],
"import/order": "error",
"import/order": ["error", {
"newlines-between": "never",
"alphabetize": {"order": "asc", "orderImportKind": "asc"},
"named": true,
"warnOnUnassignedImports": true,
"pathGroups": [{
"pattern": "*.css",
"patternOptions": {"matchBase": true},
"group": "sibling",
"position": "after",
}],
}],
"import/first": "error",
"import/newline-after-import": "error",
"indent": ["error", "tab", {
"FunctionDeclaration": {"parameters": "first"},
"FunctionExpression": {"parameters": "first"},
@ -43,7 +59,7 @@ export default tseslint.config(
}],
"array-bracket-spacing": ["error", "never"],
"one-var-declaration-per-line": ["error", "initializations"],
"quotes": ["error", "double", { allowTemplateLiterals: true }],
"quotes": ["error", "double", {allowTemplateLiterals: true}],
"semi": ["error", "never"],
"comma-dangle": ["error", "always-multiline"],
"max-len": ["warn", 120],

View file

@ -15,12 +15,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { useEffect, useMemo } from "react"
import { ScaleLoader } from "react-spinners"
import { useEventAsState } from "./util/eventdispatcher.ts"
import Client from "./api/client.ts"
import WSClient from "./api/wsclient.ts"
import { LoginScreen, VerificationScreen } from "./ui/login"
import MainScreen from "./ui/MainScreen.tsx"
import { ClientContext } from "./ui/ClientContext.ts"
import MainScreen from "./ui/MainScreen.tsx"
import { LoginScreen, VerificationScreen } from "./ui/login"
import { useEventAsState } from "./util/eventdispatcher.ts"
function App() {
const client = useMemo(() => new Client(new WSClient("/_gomuks/websocket")), [])

View file

@ -14,15 +14,15 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { CachedEventDispatcher } from "../util/eventdispatcher.ts"
import type {
EventRowID,
EventType,
RoomID,
ClientState,
RPCEvent,
} from "./types"
import type RPCClient from "./rpc.ts"
import { StateStore } from "./statestore.ts"
import type {
ClientState,
EventRowID,
EventType,
RPCEvent,
RoomID,
} from "./types"
export default class Client {
readonly state = new CachedEventDispatcher<ClientState>()

View file

@ -22,11 +22,11 @@ import type {
EventRowID,
EventType,
PaginationResponse,
RPCCommand,
RPCEvent,
RoomID,
TimelineRowID,
UserID,
RPCCommand,
RPCEvent,
} from "./types"
export interface ConnectionEvent {

View file

@ -22,12 +22,12 @@ import type {
EventID,
EventRowID,
EventType,
EventsDecryptedData,
LazyLoadSummary,
RoomID,
TimelineRowTuple,
EventsDecryptedData,
SyncCompleteData,
SyncRoom,
TimelineRowTuple,
} from "./types"
function arraysAreEqual<T>(arr1?: T[], arr2?: T[]): boolean {

View file

@ -13,18 +13,18 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import {
DeviceID,
EventType,
RoomID,
UserID,
} from "./mxtypes.ts"
import {
DBEvent,
DBRoom,
EventRowID,
TimelineRowTuple,
} from "./hitypes.ts"
import {
DeviceID,
EventType,
RoomID,
UserID,
} from "./mxtypes.ts"
export interface RPCCommand<T> {
command: string

View file

@ -13,8 +13,8 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import type { RPCCommand } from "./types"
import RPCClient from "./rpc.ts"
import type { RPCCommand } from "./types"
export default class WSClient extends RPCClient {
#conn: WebSocket | null = null

View file

@ -13,11 +13,11 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { useState, use } from "react"
import { use, useState } from "react"
import type { RoomID } from "../api/types"
import RoomList from "./roomlist/RoomList.tsx"
import RoomView from "./RoomView.tsx"
import { ClientContext } from "./ClientContext.ts"
import RoomView from "./RoomView.tsx"
import RoomList from "./roomlist/RoomList.tsx"
import "./MainScreen.css"
const MainScreen = () => {

View file

@ -16,8 +16,8 @@
import React, { use, useState } from "react"
import { RoomStateStore } from "../api/statestore.ts"
import { useNonNullEventAsState } from "../util/eventdispatcher.ts"
import TimelineView from "./timeline/TimelineView.tsx"
import { ClientContext } from "./ClientContext.ts"
import TimelineView from "./timeline/TimelineView.tsx"
import "./RoomView.css"
interface RoomViewProps {

View file

@ -13,9 +13,9 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { getMediaURL } from "../../api/media.ts"
import type { RoomListEntry } from "../../api/statestore.ts"
import type { DBEvent } from "../../api/types/hitypes.ts"
import { getMediaURL } from "../../api/media.ts"
export interface RoomListEntryProps {
room: RoomListEntry

View file

@ -16,10 +16,10 @@
import React from "react"
import { RoomStateStore } from "../../api/statestore.ts"
import { DBEvent, MemberEventContent } from "../../api/types"
import { EventContentProps } from "./content/props.ts"
import HiddenEvent from "./content/HiddenEvent.tsx"
import "./TimelineEvent.css"
import MessageBody from "./content/MessageBody.tsx"
import { EventContentProps } from "./content/props.ts"
import "./TimelineEvent.css"
export interface TimelineEventProps {
room: RoomStateStore

View file

@ -15,8 +15,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import sanitizeHtml from "sanitize-html"
import { ContentURI } from "../../../api/types"
import { getMediaURL } from "../../../api/media.ts"
import { ContentURI } from "../../../api/types"
import { sanitizeHtmlParams } from "../../../util/html.ts"
import { EventContentProps } from "./props.ts"

View file

@ -1,5 +1,5 @@
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react-swc"
import { defineConfig } from "vite"
export default defineConfig({
plugins: [react()],