1
0
Fork 0
forked from Mirrors/gomuks

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, "react-refresh": reactRefresh,
"import": pluginImport, "import": pluginImport,
}, },
settings: {
"import/extensions": [".ts", ".tsx", ".css"],
},
rules: { rules: {
...reactHooks.configs.recommended.rules, ...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": [ "react-refresh/only-export-components": [
"warn", "warn",
{allowConstantExport: true}, {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", { "indent": ["error", "tab", {
"FunctionDeclaration": {"parameters": "first"}, "FunctionDeclaration": {"parameters": "first"},
"FunctionExpression": {"parameters": "first"}, "FunctionExpression": {"parameters": "first"},

View file

@ -15,12 +15,12 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import { useEffect, useMemo } from "react" import { useEffect, useMemo } from "react"
import { ScaleLoader } from "react-spinners" import { ScaleLoader } from "react-spinners"
import { useEventAsState } from "./util/eventdispatcher.ts"
import Client from "./api/client.ts" import Client from "./api/client.ts"
import WSClient from "./api/wsclient.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 { 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() { function App() {
const client = useMemo(() => new Client(new WSClient("/_gomuks/websocket")), []) 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 // 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/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import { CachedEventDispatcher } from "../util/eventdispatcher.ts" import { CachedEventDispatcher } from "../util/eventdispatcher.ts"
import type {
EventRowID,
EventType,
RoomID,
ClientState,
RPCEvent,
} from "./types"
import type RPCClient from "./rpc.ts" import type RPCClient from "./rpc.ts"
import { StateStore } from "./statestore.ts" import { StateStore } from "./statestore.ts"
import type {
ClientState,
EventRowID,
EventType,
RPCEvent,
RoomID,
} from "./types"
export default class Client { export default class Client {
readonly state = new CachedEventDispatcher<ClientState>() readonly state = new CachedEventDispatcher<ClientState>()

View file

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

View file

@ -22,12 +22,12 @@ import type {
EventID, EventID,
EventRowID, EventRowID,
EventType, EventType,
EventsDecryptedData,
LazyLoadSummary, LazyLoadSummary,
RoomID, RoomID,
TimelineRowTuple,
EventsDecryptedData,
SyncCompleteData, SyncCompleteData,
SyncRoom, SyncRoom,
TimelineRowTuple,
} from "./types" } from "./types"
function arraysAreEqual<T>(arr1?: T[], arr2?: T[]): boolean { 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 // 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/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import {
DeviceID,
EventType,
RoomID,
UserID,
} from "./mxtypes.ts"
import { import {
DBEvent, DBEvent,
DBRoom, DBRoom,
EventRowID, EventRowID,
TimelineRowTuple, TimelineRowTuple,
} from "./hitypes.ts" } from "./hitypes.ts"
import {
DeviceID,
EventType,
RoomID,
UserID,
} from "./mxtypes.ts"
export interface RPCCommand<T> { export interface RPCCommand<T> {
command: string command: string

View file

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

View file

@ -13,11 +13,11 @@
// //
// You should have received a copy of the GNU Affero General Public License // 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/>. // 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 type { RoomID } from "../api/types"
import RoomList from "./roomlist/RoomList.tsx"
import RoomView from "./RoomView.tsx"
import { ClientContext } from "./ClientContext.ts" import { ClientContext } from "./ClientContext.ts"
import RoomView from "./RoomView.tsx"
import RoomList from "./roomlist/RoomList.tsx"
import "./MainScreen.css" import "./MainScreen.css"
const MainScreen = () => { const MainScreen = () => {

View file

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

View file

@ -13,9 +13,9 @@
// //
// You should have received a copy of the GNU Affero General Public License // 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/>. // 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 { RoomListEntry } from "../../api/statestore.ts"
import type { DBEvent } from "../../api/types/hitypes.ts" import type { DBEvent } from "../../api/types/hitypes.ts"
import { getMediaURL } from "../../api/media.ts"
export interface RoomListEntryProps { export interface RoomListEntryProps {
room: RoomListEntry room: RoomListEntry

View file

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

View file

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

View file

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