Skip to content

Commit

Permalink
chore(eslint): add sort-imports and import/order
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Jan 19, 2022
1 parent 198e065 commit c056f1e
Show file tree
Hide file tree
Showing 346 changed files with 1,349 additions and 1,339 deletions.
56 changes: 52 additions & 4 deletions .eslint.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const eslintCommon = {
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended",
"plugin:eslint-comments/recommended"
"plugin:eslint-comments/recommended",
],
plugins: ["@netless", "prettier", "@typescript-eslint", "eslint-comments"],
plugins: ["@netless", "prettier", "@typescript-eslint", "import", "eslint-comments"],
rules: {
"array-callback-return": "warn",
"default-case": "off",
Expand Down Expand Up @@ -125,6 +125,47 @@ const eslintCommon = {
"no-whitespace-before-property": "warn",
"require-yield": "warn",
"rest-spread-spacing": ["warn", "never"],
"sort-imports": [
"error",
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
allowSeparatedGroups: false,
},
],
"import/order": [
"error",
{
groups: ["builtin", "external", "parent", "sibling", "index"],
pathGroups: [
{
pattern: "react",
group: "builtin",
position: "before",
},
{
pattern: "antd/es/*/style/index",
group: "index",
position: "after",
},
{
pattern: "*.+(css|less|mp3)",
patternOptions: { matchBase: true },
group: "index",
position: "after",
},
],
alphabetize: {
order: "asc",
caseInsensitive: true,
},
pathGroupsExcludedImportTypes: ["react"],
warnOnUnassignedImports: true,
"newlines-between": "never",
},
],
strict: ["warn", "never"],
"unicode-bom": ["warn", "never"],
"valid-typeof": "warn",
Expand Down Expand Up @@ -195,6 +236,13 @@ const eslintCommon = {
},
],
},
settings: {
"import/resolver": {
node: {
extensions: [".js", ".mjs", ".jsx", ".json", ".wasm", ".ts", "tsx"],
},
},
},
overrides: [
{
// enable the rule specifically for TypeScript files
Expand Down Expand Up @@ -239,8 +287,8 @@ const eslintCommon = {
ignore: [],
},
],
'react/jsx-sort-props': [
'error',
"react/jsx-sort-props": [
"error",
{
callbacksLast: true,
shorthandFirst: true,
Expand Down
1 change: 1 addition & 0 deletions desktop/main-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^3.4.0",
"eslint-webpack-plugin": "^3.0.1",
"file-loader": "^6.2.0",
Expand Down
4 changes: 2 additions & 2 deletions desktop/main-app/src/bootup/init-app-ipc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { appActionAsync, appActionSync } from "../utils/ipc-actions";
import { ipc } from "flat-types";
import { ipcMain } from "electron";
import { ipc } from "flat-types";
import { appActionAsync, appActionSync } from "../utils/ipc-actions";

export default (): void => {
const appActionAsyncKeys = Object.keys(appActionAsync) as Array<keyof ipc.AppActionAsync>;
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/bootup/init-menus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, Menu, MenuItemConstructorOptions } from "electron";
import { Menu, MenuItemConstructorOptions, app } from "electron";
import runtime from "../utils/runtime";

export default (): void => {
Expand Down
4 changes: 2 additions & 2 deletions desktop/main-app/src/bootup/init-url-protocol.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import runtime from "../utils/runtime";
import { app } from "electron";
import { constants } from "flat-types";
import closeAPP from "../utils/close-app";
import runtime from "../utils/runtime";
import { windowManager } from "../window-manager";
import { constants } from "flat-types";
import { CustomWindow } from "../window-manager/abstract";

export default async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/bootup/init-webRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import { protocol, session } from "electron";
import fs from "fs-extra";
import path from "path";
import runtime from "../utils/runtime";

export default (): void => {
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/bootup/init-window.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app } from "electron";
import { windowManager } from "../window-manager";
import { constants } from "flat-types";
import { windowManager } from "../window-manager";

export default (): void => {
app.allowRendererProcessReuse = false;
Expand Down
10 changes: 5 additions & 5 deletions desktop/main-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import bootstrap from "./utils/bootup-flow";
import initEnv from "./bootup/init-env";
import initWindow from "./bootup/init-window";
import initWebRequest from "./bootup/init-webRequest";
import initMenus from "./bootup/init-menus";
import intAppIPC from "./bootup/init-app-ipc";
import initAppListen from "./bootup/init-app-listener";
import initEnv from "./bootup/init-env";
import initMenus from "./bootup/init-menus";
import initOtherListeners from "./bootup/init-other";
import initURLProtocol from "./bootup/init-url-protocol";
import initWebRequest from "./bootup/init-webRequest";
import initWindow from "./bootup/init-window";
import bootstrap from "./utils/bootup-flow";

void bootstrap([
initEnv,
Expand Down
8 changes: 4 additions & 4 deletions desktop/main-app/src/utils/ipc-actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { windowManager } from "../window-manager";
import { ipc } from "flat-types";
import { app, ipcMain, powerSaveBlocker } from "electron";
import runtime from "./runtime";
import { updateService } from "./update-service";
import { ipc } from "flat-types";
import { update } from "flat-types";
import { gt } from "semver";
import { windowManager } from "../window-manager";
import { CustomWindow } from "../window-manager/abstract";
import runtime from "./runtime";
import { updateService } from "./update-service";

const windowActionAsync = (customWindow: CustomWindow): ipc.WindowActionAsync => {
const { window, options } = customWindow;
Expand Down
4 changes: 2 additions & 2 deletions desktop/main-app/src/utils/ipc-emit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ipc } from "flat-types";
import { windowManager } from "../window-manager";
import runtime from "./runtime";
import { constants } from "flat-types";
import { windowManager } from "../window-manager";
import { CustomWindow, IsMultiInstance } from "../window-manager/abstract";
import runtime from "./runtime";

const sendIPC = (customWindow: CustomWindow | null, eventName: string, args: any): void => {
if (customWindow) {
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/utils/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { platform } from "os";
import path from "path";
import { app } from "electron";
import { platform } from "os";
import { runtime as Runtime } from "flat-types";

const isDevelopment = process.env.NODE_ENV === "development";
Expand Down
6 changes: 3 additions & 3 deletions desktop/main-app/src/utils/update-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { autoUpdater, UpdateCheckResult } from "electron-updater";
import runtime from "./runtime";
import { UpdateCheckResult, autoUpdater } from "electron-updater";
import { ProgressInfo } from "electron-updater/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform";
import { ipcEmitByMain } from "./ipc-emit";
import { update } from "flat-types";
import { ipcEmitByMain } from "./ipc-emit";
import runtime from "./runtime";

class UpdateService {
private cancellationToken: UpdateCheckResult["cancellationToken"];
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/utils/window-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ipcEmit } from "./ipc-emit";
import { autoUpdater } from "electron-updater";
import { CustomWindow } from "../window-manager/abstract";
import { ipcEmit } from "./ipc-emit";

export const windowHookClose = (customWindow: CustomWindow): void => {
customWindow.window.on("close", e => {
Expand Down
4 changes: 2 additions & 2 deletions desktop/main-app/src/window-manager/abstract.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { constants } from "flat-types";
import { BrowserWindow, BrowserWindowConstructorOptions } from "electron";
import { constants } from "flat-types";
import {
windowHookClose,
windowHookClosed,
windowOpenDevTools,
windowReadyToShow,
} from "../utils/window-event";
import {
WindowOptions,
defaultBrowserWindowOptions,
defaultWindowOptions,
WindowOptions,
} from "./default-options";

export abstract class AbstractWindow<MULTI_INSTANCE extends boolean> {
Expand Down
6 changes: 3 additions & 3 deletions desktop/main-app/src/window-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WindowManager } from "./window-manager";
import { WindowMain } from "./window-main";
import { constants } from "flat-types";
import { WindowShareScreenTip } from "./window-portal/window-share-screen-tip";
import { WindowMain } from "./window-main";
import { WindowManager } from "./window-manager";
import { WindowPreviewFile } from "./window-portal/window-preview-file";
import { WindowShareScreenTip } from "./window-portal/window-share-screen-tip";

export const windowManager = new WindowManager({
[constants.WindowsName.Main]: new WindowMain(),
Expand Down
8 changes: 4 additions & 4 deletions desktop/main-app/src/window-manager/window-main/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { constants } from "flat-types";
import { AbstractWindow, CustomWindow } from "../abstract";
import runtime from "../../utils/runtime";
import { RxSubject } from "./rx-subject";
import { ipcMain } from "electron";
import { constants } from "flat-types";
import { zip } from "rxjs";
import { ignoreElements, mergeMap } from "rxjs/operators";
import runtime from "../../utils/runtime";
import { AbstractWindow, CustomWindow } from "../abstract";
import { RxSubject } from "./rx-subject";

export class WindowMain extends AbstractWindow<false> {
private readonly subject: RxSubject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Subject } from "rxjs";
import { IpcMainEvent } from "electron";
import { Subject } from "rxjs";

export class RxSubject {
public constructor(
Expand Down
6 changes: 3 additions & 3 deletions desktop/main-app/src/window-manager/window-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { constants, portal } from "flat-types";
import { BrowserWindowConstructorOptions } from "electron";
import { WindowStore } from "./window-store";
import { CustomWindow, AbstractWindows } from "./abstract";
import { constants, portal } from "flat-types";
import { injectionWindowIPCAction } from "../utils/ipc-actions";
import { AbstractWindows, CustomWindow } from "./abstract";
import { WindowStore } from "./window-store";

export class WindowManager<
ABSTRACT_WINDOWS extends AbstractWindows,
Expand Down
2 changes: 1 addition & 1 deletion desktop/main-app/src/window-manager/window-portal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Display, screen } from "electron";
import { windowManager } from "../index";
import { constants } from "flat-types";
import { windowManager } from "../index";

export const getDisplayByMainWindow = (): Display => {
const mainBounds = windowManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractWindow, CustomWindow } from "../abstract";
import { constants } from "flat-types";
import { AbstractWindow, CustomWindow } from "../abstract";

export class WindowPreviewFile extends AbstractWindow<true> {
public constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbstractWindow, CustomWindow } from "../abstract";
import { constants } from "flat-types";
import { AbstractWindow, CustomWindow } from "../abstract";
import { getDisplayByMainWindow, getXCenterPoint } from "./utils";

export class WindowShareScreenTip extends AbstractWindow<false> {
Expand Down
1 change: 1 addition & 0 deletions desktop/renderer-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
Expand Down
2 changes: 1 addition & 1 deletion desktop/renderer-app/scripts/vite-plugin-electron/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { builtinModules } from "module";
import { Plugin as VitePlugin } from "vite";
import { cjs2esm } from "./utils";
import { options } from "./template/options";
import { cjs2esm } from "./utils";

// based on https://github.com/caoxiemeihao/vite-plugins/blob/main/packages/electron/src/index.ts

Expand Down
2 changes: 1 addition & 1 deletion desktop/renderer-app/scripts/vite-plugin-electron/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { build, OutputFile } from "esbuild";
import { readFileSync } from "fs";
import { join } from "path";
import { OutputFile, build } from "esbuild";

// e.g:
// flat/node_modules/electron/index.js?v=19cea64f => flat/node_modules/electron/index.js
Expand Down
4 changes: 2 additions & 2 deletions desktop/renderer-app/src/AppRoutes/AppRouteContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC } from "react";
import { useIsomorphicLayoutEffect } from "react-use";
import { RouteComponentProps } from "react-router-dom";
import { useIsomorphicLayoutEffect } from "react-use";
import { useURLAppLauncher } from "../utils/hooks/use-url-app-launcher";
import { ipcAsyncByMainWindow } from "../utils/ipc";
import { AppRouteErrorBoundary } from "./AppRouteErrorBoundary";
import { useURLAppLauncher } from "../utils/hooks/use-url-app-launcher";

export interface AppRouteContainerProps {
Comp: React.ComponentType<any>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ComponentType } from "react";
import { RouteComponentProps } from "react-router-dom";
import { ErrorPage } from "flat-components";
import { RouteComponentProps } from "react-router-dom";

export interface AppRouteErrorBoundaryProps {
Comp: ComponentType<any>;
Expand Down
14 changes: 7 additions & 7 deletions desktop/renderer-app/src/api-middleware/cloud-recording.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { updateRecordEndTime } from "./flatServer";
import {
cloudRecordAcquire,
CloudRecordStopResult,
cloudRecordStop,
CloudRecordAcquirePayload,
CloudRecordStartPayload,
cloudRecordStart,
CloudRecordQueryResult,
cloudRecordQuery,
cloudRecordUpdateLayout,
CloudRecordStartPayload,
CloudRecordStopResult,
CloudRecordUpdateLayoutPayload,
CloudRecordUpdateLayoutResult,
cloudRecordAcquire,
cloudRecordQuery,
cloudRecordStart,
cloudRecordStop,
cloudRecordUpdateLayout,
} from "./flatServer/agora";

/**
Expand Down
4 changes: 2 additions & 2 deletions desktop/renderer-app/src/api-middleware/flatServer/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Axios, { AxiosRequestConfig } from "axios";
import { RequestErrorCode } from "../../constants/error-code";
import { globalStore } from "../../stores/global-store";
import { FLAT_SERVER_VERSIONS, Status } from "./constants";
import { ServerRequestError } from "../../utils/error/server-request-error";
import { RequestErrorCode } from "../../constants/error-code";
import { FLAT_SERVER_VERSIONS, Status } from "./constants";

export type FlatServerResponse<T> =
| {
Expand Down
6 changes: 3 additions & 3 deletions desktop/renderer-app/src/api-middleware/rtm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EventEmitter } from "events";
import AgoraRTM, { RtmChannel, RtmClient } from "agora-rtm-sdk";
import polly from "polly-js";
import { v4 as uuidv4 } from "uuid";
import { AGORA, NODE_ENV } from "../constants/process";
import { EventEmitter } from "events";
import { RoomStatus } from "./flatServer/constants";
import { generateRTMToken } from "./flatServer/agora";
import { globalStore } from "../stores/global-store";
import { generateRTMToken } from "./flatServer/agora";
import { RoomStatus } from "./flatServer/constants";

export interface RtmRESTfulQueryPayload {
filter: {
Expand Down
4 changes: 2 additions & 2 deletions desktop/renderer-app/src/api-middleware/share-screen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { globalStore } from "../stores/global-store";
import { AGORA } from "../constants/process";
import type AgoraSDK from "agora-electron-sdk";
import { ScreenSymbol } from "agora-electron-sdk/types/Api/native_type";
import { AGORA } from "../constants/process";
import { globalStore } from "../stores/global-store";

export class RTCShareScreen {
public constructor(
Expand Down
Loading

0 comments on commit c056f1e

Please sign in to comment.