Skip to content

Commit

Permalink
Ban circular dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <sebastian@malton.name>
  • Loading branch information
Nokel81 committed Aug 5, 2021
1 parent 476aa74 commit d1344b4
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 167 deletions.
18 changes: 16 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
*/

const packageJson = require("./package.json");
const isInVscode = Boolean(process.env.VSCODE_PID);

module.exports = {
ignorePatterns: [
"**/node_modules/**/*",
"**/dist/**/*",
"**/static/**/*",
"**/site/**/*",
],
settings: {
react: {
Expand Down Expand Up @@ -94,6 +96,8 @@ module.exports = {
parser: "@typescript-eslint/parser",
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
],
plugins: [
"header",
Expand All @@ -114,6 +118,10 @@ module.exports = {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-unused-vars": "off",
"import/no-cycle": [2, {
ignoreExternal: true,
maxDepth: isInVscode ? 10 : undefined, // This should speed up VScode locally
}],
"unused-imports/no-unused-imports-ts": "error",
"unused-imports/no-unused-vars-ts": [
"warn", {
Expand All @@ -129,7 +137,6 @@ module.exports = {
"avoidEscape": true,
"allowTemplateLiterals": true,
}],
"react/prop-types": "off",
"semi": "off",
"@typescript-eslint/semi": ["error"],
"linebreak-style": ["error", "unix"],
Expand Down Expand Up @@ -160,6 +167,8 @@ module.exports = {
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
],
parserOptions: {
ecmaVersion: 2018,
Expand All @@ -168,6 +177,7 @@ module.exports = {
},
rules: {
"header/header": [2, "./license-header"],
"react/prop-types": "off",
"no-invalid-this": "off",
"@typescript-eslint/no-invalid-this": ["error"],
"@typescript-eslint/explicit-function-return-type": "off",
Expand All @@ -182,6 +192,11 @@ module.exports = {
"@typescript-eslint/no-empty-function": "off",
"react/display-name": "off",
"@typescript-eslint/no-unused-vars": "off",
"import/no-cycle": [2, {
ignoreExternal: true,
// The following should speed up VScode but running `yarn lint` manually or in CI will still completely ban it
maxDepth: isInVscode ? 10 : undefined,
}],
"unused-imports/no-unused-imports-ts": "error",
"unused-imports/no-unused-vars-ts": [
"warn", {
Expand All @@ -197,7 +212,6 @@ module.exports = {
"avoidEscape": true,
"allowTemplateLiterals": true,
}],
"react/prop-types": "off",
"semi": "off",
"@typescript-eslint/semi": ["error"],
"linebreak-style": ["error", "unix"],
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dev: binaries/client build-extensions static/build/LensDev.html
yarn dev

.PHONY: lint
lint:
lint: node_modules
yarn lint

.PHONY: release-version
Expand Down
36 changes: 36 additions & 0 deletions extensions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

module.exports = {
"overrides": [
{
files: [
"**/*.ts",
"**/*.tsx",
],
rules: {
"import/no-unresolved": ["error", {
ignore: ["@k8slens/extensions"]
}],
}
}
]
};
9 changes: 8 additions & 1 deletion extensions/metrics-cluster-feature/package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
},
"moduleNameMapper": {
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.ts",
"\\.(svg)$": "<rootDir>/__mocks__/imageMock.ts",
"src/(.*)": "<rootDir>/__mocks__/windowMock.ts"
"\\.(svg)$": "<rootDir>/__mocks__/imageMock.ts"
},
"modulePathIgnorePatterns": [
"<rootDir>/dist",
Expand Down Expand Up @@ -313,7 +312,7 @@
"@types/webpack-env": "^1.15.2",
"@types/webpack-node-externals": "^1.7.1",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.0.0",
"@typescript-eslint/parser": "^4.29.0",
"ace-builds": "^1.4.12",
"ansi_up": "^5.0.0",
"chart.js": "^2.9.4",
Expand All @@ -330,6 +329,7 @@
"esbuild-loader": "^2.13.1",
"eslint": "^7.7.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-unused-imports": "^1.0.1",
Expand Down
3 changes: 1 addition & 2 deletions src/common/catalog-entities/kubernetes-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
*/

import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityAddMenuContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityAddMenuContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus, CatalogCategory, CatalogCategorySpec } from "../catalog";
import { clusterActivateHandler, clusterDeleteHandler, clusterDisconnectHandler } from "../cluster-ipc";
import { ClusterStore } from "../cluster-store";
import { requestMain } from "../ipc";
import { CatalogCategory, CatalogCategorySpec } from "../catalog";
import { addClusterURL } from "../routes";
import { app } from "electron";
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
Expand Down
8 changes: 5 additions & 3 deletions src/common/user-store/preferences-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import moment from "moment-timezone";
import path from "path";
import os from "os";
import { ThemeStore } from "../../renderer/theme.store";
import type { ThemeId } from "../../renderer/theme.store";
import { ObservableToggleSet } from "../utils";

export const defaultThemeName: ThemeId = "lens-dark";

export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
filePath: string;
}
Expand Down Expand Up @@ -56,10 +58,10 @@ const shell: PreferenceDescription<string | undefined> = {

const colorTheme: PreferenceDescription<string> = {
fromStore(val) {
return val || ThemeStore.defaultTheme;
return val || defaultThemeName;
},
toStore(val) {
if (!val || val === ThemeStore.defaultTheme) {
if (!val || val === defaultThemeName) {
return undefined;
}

Expand Down
3 changes: 1 addition & 2 deletions src/common/user-store/user-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import { app, remote } from "electron";
import semver from "semver";
import { action, computed, observable, reaction, makeObservable } from "mobx";
import { BaseStore } from "../base-store";
import migrations from "../../migrations/user-store";
import migrations, { fileNameMigration } from "../../migrations/user-store";
import { getAppVersion } from "../utils/app-version";
import { kubeConfigDefaultPath } from "../kube-helpers";
import { appEventBus } from "../event-bus";
import path from "path";
import { fileNameMigration } from "../../migrations/user-store";
import { ObservableToggleSet, toJS } from "../../renderer/utils";
import { DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
import logger from "../../main/logger";
Expand Down
3 changes: 2 additions & 1 deletion src/main/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { VersionDetector } from "./cluster-detectors/version-detector";
import { DetectorRegistry } from "./cluster-detectors/detector-registry";
import plimit from "p-limit";
import { toJS } from "../common/utils";
import { initialNodeShellImage, ClusterState, ClusterMetadataKey, ClusterRefreshOptions, ClusterStatus, ClusterMetricsResourceType, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel } from "../common/cluster-types";
import type { ClusterId, ClusterMetadata, ClusterMetricsResourceType, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, ClusterRefreshOptions, ClusterState, UpdateClusterModel } from "../common/cluster-types";
import { ClusterStatus, ClusterMetadataKey, initialNodeShellImage } from "../common/cluster-types";

/**
* Cluster
Expand Down
2 changes: 1 addition & 1 deletion src/main/helm/helm-release-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import * as tempy from "tempy";
import tempy from "tempy";
import fse from "fs-extra";
import * as yaml from "js-yaml";
import { promiseExec } from "../promise-exec";
Expand Down
2 changes: 1 addition & 1 deletion src/main/resource-applier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { exec } from "child_process";
import fs from "fs";
import * as yaml from "js-yaml";
import path from "path";
import * as tempy from "tempy";
import tempy from "tempy";
import logger from "./logger";
import { appEventBus } from "../common/event-bus";
import { cloneJsonObject } from "../common/utils";
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/hotbar-store/5.0.0-beta.5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { MigrationDeclaration } from "../helpers";
export default {
version: "5.0.0-beta.5",
run(store) {
const hotbars: Hotbar[] = store.get("hotbars");
const hotbars: Hotbar[] = store.get("hotbars") ?? [];

hotbars.forEach((hotbar, hotbarIndex) => {
hotbar.items.forEach((item, itemIndex) => {
Expand Down
1 change: 0 additions & 1 deletion src/renderer/api/__tests__/catalog-entity-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

import { CatalogEntityRegistry } from "../catalog-entity-registry";
import "../../../common/catalog-entities";
import { catalogCategoryRegistry } from "../../../common/catalog/catalog-category-registry";
import { CatalogCategory, CatalogEntityData, CatalogEntityKindData } from "../catalog-entity";
import { WebLink } from "../../../common/catalog-entities";
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/+preferences/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import moment from "moment-timezone";
import { computed, observable, reaction, makeObservable } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";

import { isWindows } from "../../../common/vars";
import { isWindows, sentryDsn } from "../../../common/vars";
import { AppPreferenceRegistry, RegisteredAppPreference } from "../../../extensions/registries/app-preference-registry";
import { UserStore } from "../../../common/user-store";
import { ThemeStore } from "../../theme.store";
Expand All @@ -41,7 +41,6 @@ import { FormSwitch, Switcher } from "../switch";
import { KubeconfigSyncs } from "./kubeconfig-syncs";
import { SettingLayout } from "../layout/setting-layout";
import { Checkbox } from "../checkbox";
import { sentryDsn } from "../../../common/vars";

enum Pages {
Application = "application",
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/dock/dock.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export class DockStore implements DockStorageState {

if (newTab?.kind === TabKind.TERMINAL) {
// close the dock when selected sibling inactive terminal tab
// eslint-disable-next-line import/no-cycle
const { TerminalStore } = await import("./terminal.store");

if (!TerminalStore.getInstance(false)?.isConnected(newTab.id)) this.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { apiManager } from "../../api/api-manager";
import { crdStore } from "../+custom-resources/crd.store";
import { KubeObjectMenu } from "../kube-object-menu";
import { KubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import logger from "../../../main/logger";
import { CrdResourceDetails } from "../+custom-resources";
import { KubeObjectMeta } from "../kube-object-meta";
import { hideDetails, kubeDetailsUrlParam } from "../kube-detail-params";
Expand Down Expand Up @@ -62,7 +61,7 @@ export class KubeObjectDetails extends React.Component {
.getStore(this.path)
?.getByPath(this.path);
} catch (error) {
logger.error(`[KUBE-OBJECT-DETAILS]: failed to get store or object: ${error}`, { path: this.path });
console.error(`[KUBE-OBJECT-DETAILS]: failed to get store or object: ${error}`, { path: this.path });

return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/menu/menu-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { observer } from "mobx-react";
import { boundMethod, cssNames } from "../../utils";
import { ConfirmDialog } from "../confirm-dialog";
import { Icon, IconProps } from "../icon";
import { Menu, MenuItem, MenuProps } from "../menu";
import { Menu, MenuItem, MenuProps } from "./menu";
import uniqueId from "lodash/uniqueId";
import isString from "lodash/isString";
import { RenderDelay } from "../render-delay/render-delay";
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/table/react-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*/

import styles from "./react-table.module.css";
import React from "react";
import { useCallback, useMemo } from "react";
import React, { useCallback, useMemo } from "react";
import { useFlexLayout, useSortBy, useTable, UseTableOptions } from "react-table";
import { Icon } from "../icon";
import { cssNames } from "../../utils";
Expand Down
11 changes: 0 additions & 11 deletions src/renderer/utils/createStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { app, remote } from "electron";
import { comparer, observable, reaction, toJS, when } from "mobx";
import fse from "fs-extra";
import { StorageHelper } from "./storageHelper";
import { ClusterStore } from "../../common/cluster-store";
import logger from "../../main/logger";
import { getHostedClusterId } from "../../common/utils";

Expand Down Expand Up @@ -73,11 +72,6 @@ export function createAppStorage<T>(key: string, defaultValue: T, clusterId?: st
equals: comparer.structural, // save only when something really changed
});

// remove json-file when cluster deleted
if (clusterId !== undefined) {
when(() => ClusterStore.getInstance(false)?.removedClusters.has(clusterId)).then(removeFile);
}

async function saveFile(state: Record<string, any> = {}) {
logger.info(`${logPrefix} saving ${filePath}`);

Expand All @@ -90,11 +84,6 @@ export function createAppStorage<T>(key: string, defaultValue: T, clusterId?: st
});
}
}

function removeFile() {
logger.debug(`${logPrefix} removing ${filePath}`);
fse.unlink(filePath).catch(Function);
}
}

return new StorageHelper<T>(key, {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/utils/storageHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Helper for working with storages (e.g. window.localStorage, NodeJS/file-system, etc.)

import { action, comparer, makeObservable, observable, toJS, when, } from "mobx";
import produce, { Draft } from "immer";
import { Draft, produce } from "immer";
import { isEqual, isFunction, isPlainObject } from "lodash";
import logger from "../../main/logger";

Expand Down

0 comments on commit d1344b4

Please sign in to comment.