Skip to content

Commit

Permalink
lint: Disallow utils index imports
Browse files Browse the repository at this point in the history
This keeps leading to issues due to circular imports.
Import from specific files instead, index just reexports
  • Loading branch information
Vendicated committed Nov 7, 2022
1 parent 955573d commit f7d9be9
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 30 deletions.
49 changes: 47 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"root": true,
"parser": "@typescript-eslint/parser",
"ignorePatterns": ["dist", "browser"],
"plugins": ["header", "simple-import-sort", "unused-imports"],
"plugins": [
"@typescript-eslint",
"header",
"simple-import-sort",
"unused-imports"
],
"rules": {
// Since it's only been a month and Vencord has already been stolen
// by random skids who rebranded it to "AlphaCord" and erased all license
Expand Down Expand Up @@ -88,6 +93,46 @@
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",

"unused-imports/no-unused-imports": "error"
"unused-imports/no-unused-imports": "error",

"@typescript-eslint/no-restricted-imports": [
"error",
{
"paths": [
// shrug, couldn't find a better way since the pattern one doesn't work:
// ["utils", "!utils/*"]
{
"name": "./utils",
"message": "Do not import from index. This might cause issues. Import from the specific file instead.",
"allowTypeImports": true
},
{
"name": "../utils",
"message": "Do not import from index. This might cause issues. Import from the specific file instead.",
"allowTypeImports": true
},
{
"name": "../../utils",
"message": "Do not import from index. This might cause issues. Import from the specific file instead.",
"allowTypeImports": true
},
{
"name": "../../../utils",
"message": "Do not import from index. This might cause issues. Import from the specific file instead.",
"allowTypeImports": true
},
{
"name": "../../../../utils",
"message": "Do not import from index. This might cause issues. Import from the specific file instead.",
"allowTypeImports": true
},
{
"name": "../../../../../utils",
"message": "Do not import from index. This might cause issues. Import from the specific file instead.",
"allowTypeImports": true
}
]
}
]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.8",
"@types/yazl": "^2.4.2",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.39.0",
"discord-types": "^1.3.26",
"esbuild": "^0.15.5",
Expand Down
141 changes: 139 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions src/Vencord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@

export * as Api from "./api";
export * as Plugins from "./plugins";
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
export * as Util from "./utils";
export * as QuickCss from "./utils/quickCss";
export * as Updater from "./utils/updater";
export * as Webpack from "./webpack";

import { popNotice, showNotice } from "./api/Notices";
import { PlainSettings, Settings } from "./api/settings";
import { patches, PMLogger, startAllPlugins } from "./plugins";

export { PlainSettings, Settings };

import "./webpack/patchWebpack";
import "./utils/quickCss";
import "./webpack/patchWebpack";

import { popNotice, showNotice } from "./api/Notices";
import { PlainSettings, Settings } from "./api/settings";
import { patches, PMLogger, startAllPlugins } from "./plugins";
import { checkForUpdates, UpdateLogger } from "./utils/updater";
import { onceReady } from "./webpack";
import { Router } from "./webpack/common";
Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { LazyComponent } from "../utils";
import Logger from "../utils/logger";
import { LazyComponent } from "../utils/misc";
import { Margins, React } from "../webpack/common";
import { ErrorCard } from "./ErrorCard";

Expand Down
2 changes: 1 addition & 1 deletion src/components/Monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import monacoHtml from "~fileContent/monacoWin.html";

import { IpcEvents } from "../utils";
import { debounce } from "../utils/debounce";
import IpcEvents from "../utils/IpcEvents";
import { Queue } from "../utils/Queue";
import { find } from "../webpack/webpack";

Expand Down
2 changes: 1 addition & 1 deletion src/components/PatchHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { makeCodeblock } from "../utils";
import { debounce } from "../utils/debounce";
import { makeCodeblock } from "../utils/misc";
import { Button, Clipboard, Forms, Margins, Parser, React, Switch, TextInput } from "../webpack/common";
import { search } from "../webpack/webpack";
import { CheckedTextInput } from "./CheckedTextInput";
Expand Down
3 changes: 2 additions & 1 deletion src/components/PluginSettings/PluginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { Constructor } from "type-fest";

import { generateId } from "../../api/Commands";
import { useSettings } from "../../api/settings";
import { LazyComponent, lazyWebpack, proxyLazy } from "../../utils";
import { LazyComponent, lazyWebpack } from "../../utils/misc";
import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "../../utils/modal";
import { proxyLazy } from "../../utils/proxyLazy";
import { OptionType, Plugin } from "../../utils/types";
import { filters, findByCode } from "../../webpack";
import { Button, FluxDispatcher, Forms, React, Text, Tooltip, UserStore, UserUtils } from "../../webpack/common";
Expand Down
5 changes: 3 additions & 2 deletions src/components/PluginSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import Plugins from "~plugins";
import { showNotice } from "../../api/Notices";
import { Settings, useSettings } from "../../api/settings";
import { startDependenciesRecursive, startPlugin, stopPlugin } from "../../plugins";
import { Logger, Modals } from "../../utils";
import { ChangeList } from "../../utils/ChangeList";
import Logger from "../../utils/logger";
import { classes, LazyComponent, lazyWebpack } from "../../utils/misc";
import { openModalLazy } from "../../utils/modal";
import { Plugin } from "../../utils/types";
import { filters, findByCode } from "../../webpack";
import { Alerts, Button, Forms, Margins, Parser, React, Select, Switch, Text, TextInput, Toasts, Tooltip } from "../../webpack/common";
Expand Down Expand Up @@ -88,7 +89,7 @@ function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLe
}

function openModal() {
Modals.openModalLazy(async () => {
openModalLazy(async () => {
return modalProps => {
return <PluginModal {...modalProps} plugin={plugin} onRestartNeeded={() => onRestartNeeded(plugin.name)} />;
};
Expand Down
Loading

0 comments on commit f7d9be9

Please sign in to comment.