Skip to content

Commit

Permalink
Require all Prop interfaces to be explicitly named, prefer interface …
Browse files Browse the repository at this point in the history
…over type

- Also export all prop types

Signed-off-by: Sebastian Malton <sebastian@malton.name>
  • Loading branch information
Nokel81 committed Feb 3, 2022
1 parent 0017f51 commit a96005b
Show file tree
Hide file tree
Showing 196 changed files with 628 additions and 633 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ module.exports = {
"named": "never",
"asyncArrow": "always",
}],
"@typescript-eslint/naming-convention": ["error",
{
"selector": "interface",
"format": ["PascalCase"],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid",
"custom": {
"regex": "^Props$",
"match": false,
},
},
{
"selector": "typeAlias",
"format": ["PascalCase"],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid",
"custom": {
"regex": "^(Props|State)$",
"match": false,
},
},
],
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
"unused-imports/no-unused-imports-ts": process.env.PROD === "true" ? "error" : "warn",
"unused-imports/no-unused-vars-ts": [
"warn", {
Expand Down
4 changes: 2 additions & 2 deletions docs/extensions/guides/renderer-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,11 @@ const {

type Pod = Renderer.K8sApi.Pod;

interface Props {
interface PodsDetailsListProps {
pods?: Pod[];
}

export class PodsDetailsList extends React.Component<Props> {
export class PodsDetailsList extends React.Component<PodsDetailsListProps> {
getTableRow = (pod: Pod) => {
return (
<TableRow key={index} nowrap>
Expand Down
6 changes: 3 additions & 3 deletions docs/extensions/guides/resource-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ To allow the end-user to control the life cycle of this cluster feature the foll
}
} = Renderer;
interface Props {
interface ExampleClusterFeatureSettingsProps {
cluster: Common.Catalog.KubernetesCluster;
}
@observer
export class ExampleClusterFeatureSettings extends React.Component<Props> {
constructor(props: Props) {
export class ExampleClusterFeatureSettings extends React.Component<ExampleClusterFeatureSettingsProps> {
constructor(props: ExampleClusterFeatureSettingsProps) {
super(props);
makeObservable(this);
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/metrics-cluster-feature/src/metrics-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ const {
},
} = Renderer;

interface Props {
export interface MetricsSettingsProps {
cluster: Common.Catalog.KubernetesCluster;
}

@observer
export class MetricsSettings extends React.Component<Props> {
constructor(props: Props) {
export class MetricsSettings extends React.Component<MetricsSettingsProps> {
constructor(props: MetricsSettingsProps) {
super(props);
makeObservable(this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/__tests__/kube-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ users:
command: foo
`;

interface kubeconfig {
interface Kubeconfig {
apiVersion: string,
clusters: [{
name: string,
Expand All @@ -66,7 +66,7 @@ interface kubeconfig {
preferences: {}
}

let mockKubeConfig: kubeconfig;
let mockKubeConfig: Kubeconfig;

describe("kube helpers", () => {
describe("validateKubeconfig", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/common/app-event-bus/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import { EventEmitter } from "../event-emitter";

export type AppEvent = {
export interface AppEvent {
name: string;
action: string;
params?: object;
};
}

export const appEventBus = new EventEmitter<[AppEvent]>();
4 changes: 2 additions & 2 deletions src/common/catalog-entities/web-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface WebLinkStatus extends CatalogEntityStatus {
phase: WebLinkStatusPhase;
}

export type WebLinkSpec = {
export interface WebLinkSpec {
url: string;
};
}

export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus, WebLinkSpec> {
public static readonly apiVersion = "entity.k8slens.dev/v1alpha1";
Expand Down
4 changes: 2 additions & 2 deletions src/common/k8s-api/endpoints/crd.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { crdResourcesURL } from "../../routes";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
import type { KubeJsonApiData } from "../kube-json-api";

type AdditionalPrinterColumnsCommon = {
interface AdditionalPrinterColumnsCommon {
name: string;
type: "integer" | "number" | "string" | "boolean" | "date";
priority: number;
description: string;
};
}

export type AdditionalPrinterColumnsV1 = AdditionalPrinterColumnsCommon & {
jsonPath: string;
Expand Down
4 changes: 2 additions & 2 deletions src/common/k8s-api/kube-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function ensureObjectSelfLink(api: KubeApi<KubeObject>, object: KubeJsonA

export type KubeApiWatchCallback = (data: IKubeWatchEvent<KubeJsonApiData>, error: any) => void;

export type KubeApiWatchOptions = {
export interface KubeApiWatchOptions {
namespace: string;
callback?: KubeApiWatchCallback;
abortController?: AbortController
Expand All @@ -225,7 +225,7 @@ export type KubeApiWatchOptions = {

// timeout in seconds
timeout?: number;
};
}

export type KubeApiPatchType = "merge" | "json" | "strategic";

Expand Down
3 changes: 2 additions & 1 deletion src/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ export * from "./splitArray";
export * from "./tar";
export * from "./toJS";
export * from "./type-narrowing";
export * from "./types";
export * from "./wait-for-path";

export type { Tuple } from "./tuple";

import * as iter from "./iter";
import * as array from "./array";
import * as tuple from "./tuple";
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

type StaticThis<T, R extends any[]> = { new(...args: R): T };
interface StaticThis<T, R extends any[]> { new(...args: R): T }

export class Singleton {
private static instances = new WeakMap<object, Singleton>();
Expand Down
10 changes: 8 additions & 2 deletions src/common/utils/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import * as array from "../utils/array";
/**
* A strict N-tuple of type T
*/
export type Tuple<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
type _TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : _TupleOf<T, N, [T, ...R]>;
export type Tuple<T, N extends number> = N extends N
? number extends N
? T[]
: TupleOfImpl<T, N, []>
: never;
type TupleOfImpl<T, N extends number, R extends unknown[]> = R["length"] extends N
? R
: TupleOfImpl<T, N, [T, ...R]>;

/**
* Iterates over `sources` yielding full tuples until one of the tuple arrays
Expand Down
10 changes: 0 additions & 10 deletions src/common/utils/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/extensions/renderer-api/kube-object-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

export type KubeObjectStatus = {
export interface KubeObjectStatus {
level: KubeObjectStatusLevel;
text: string;
timestamp?: string;
};
}

export enum KubeObjectStatusLevel {
INFO = 1,
Expand Down
4 changes: 2 additions & 2 deletions src/main/cluster-detectors/base-cluster-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import type { RequestPromiseOptions } from "request-promise-native";
import type { Cluster } from "../../common/cluster/cluster";
import { k8sRequest } from "../k8s-request";

export type ClusterDetectionResult = {
export interface ClusterDetectionResult {
value: string | number | boolean
accuracy: number
};
}

export class BaseClusterDetector {
key: string;
Expand Down
4 changes: 2 additions & 2 deletions src/main/lens-binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import * as tar from "tar";
import { isWindows } from "../common/vars";
import type winston from "winston";

export type LensBinaryOpts = {
export interface LensBinaryOpts {
version: string;
baseDir: string;
originalBinaryName: string;
newBinaryName?: string;
requestOpts?: request.Options;
};
}

export class LensBinary {

Expand Down
4 changes: 2 additions & 2 deletions src/main/prometheus/provider-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import type { CoreV1Api } from "@kubernetes/client-node";
import { inspect } from "util";
import { Singleton } from "../../common/utils";

export type PrometheusService = {
export interface PrometheusService {
id: string;
namespace: string;
service: string;
port: number;
};
}

export abstract class PrometheusProvider {
abstract readonly id: string;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/+catalog/catalog-add-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { EventEmitter } from "events";
import { navigate } from "../../navigation";
import { catalogCategoryRegistry } from "../../api/catalog-category-registry";

export type CatalogAddButtonProps = {
export interface CatalogAddButtonProps {
category: CatalogCategory
};
}

type CategoryId = string;

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/+catalog/catalog-entity-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { cssNames } from "../../utils";
import { Avatar } from "../avatar";
import { getLabelBadges } from "./helpers";

interface Props<T extends CatalogEntity> {
export interface CatalogEntityDetailsProps<T extends CatalogEntity> {
entity: T;
hideDetails(): void;
onRun: () => void;
}

@observer
export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Props<T>> {
export class CatalogEntityDetails<T extends CatalogEntity> extends Component<CatalogEntityDetailsProps<T>> {
categoryIcon(category: CatalogCategory) {
if (category.metadata.icon.includes("<svg")) {
return <Icon svg={category.metadata.icon} smallest />;
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/+catalog/catalog-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { cssNames } from "../../utils";
import type { CatalogCategory } from "../../api/catalog-entity";
import { observer } from "mobx-react";

type Props = {
export interface CatalogMenuProps {
activeItem: string;
onItemClick: (id: string) => void;
};
}

function getCategories() {
return catalogCategoryRegistry.filteredItems;
Expand All @@ -42,7 +42,7 @@ function Item(props: TreeItemProps) {
);
}

export const CatalogMenu = observer((props: Props) => {
export const CatalogMenu = observer((props: CatalogMenuProps) => {
return (
// Overwrite Material UI styles with injectFirst https://material-ui.com/guides/interoperability/#controlling-priority-4
<StylesProvider injectFirst>
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/+catalog/catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { RegisteredCustomCategoryViewDecl } from "./custom-views.injectable
import customCategoryViewsInjectable from "./custom-views.injectable";
import type { CustomCategoryViewComponents } from "./custom-views";

interface Props extends RouteComponentProps<CatalogViewRouteParam> {}
export interface CatalogProps extends RouteComponentProps<CatalogViewRouteParam> {}

interface Dependencies {
catalogPreviousActiveTabStorage: { set: (value: string ) => void };
Expand All @@ -47,11 +47,11 @@ interface Dependencies {
}

@observer
class NonInjectedCatalog extends React.Component<Props & Dependencies> {
class NonInjectedCatalog extends React.Component<CatalogProps & Dependencies> {
@observable private contextMenu: CatalogEntityContextMenuContext;
@observable activeTab?: string;

constructor(props: Props & Dependencies) {
constructor(props: CatalogProps & Dependencies) {
super(props);
makeObservable(this);
}
Expand Down Expand Up @@ -304,7 +304,7 @@ class NonInjectedCatalog extends React.Component<Props & Dependencies> {
}
}

export const Catalog = withInjectables<Dependencies, Props>( NonInjectedCatalog, {
export const Catalog = withInjectables<Dependencies, CatalogProps>( NonInjectedCatalog, {
getProps: (di, props) => ({
catalogEntityStore: di.inject(catalogEntityStoreInjectable),
catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable),
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/+cluster/cluster-issues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ThemeStore } from "../../theme.store";
import { kubeSelectedUrlParam, toggleDetails } from "../kube-detail-params";
import { apiManager } from "../../../common/k8s-api/api-manager";

interface Props {
export interface ClusterIssuesProps {
className?: string;
}

Expand All @@ -39,14 +39,14 @@ enum sortBy {
}

@observer
export class ClusterIssues extends React.Component<Props> {
export class ClusterIssues extends React.Component<ClusterIssuesProps> {
private sortCallbacks = {
[sortBy.type]: (warning: IWarning) => warning.kind,
[sortBy.object]: (warning: IWarning) => warning.getName(),
[sortBy.age]: (warning: IWarning) => warning.timeDiffFromNow,
};

constructor(props: Props) {
constructor(props: ClusterIssuesProps) {
super(props);
makeObservable(this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/+cluster/cluster-no-metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import React from "react";
import { Icon } from "../icon";
import { cssNames } from "../../utils";

interface Props {
export interface ClusterNoMetricsProps {
className: string;
}

export function ClusterNoMetrics({ className }: Props) {
export function ClusterNoMetrics({ className }: ClusterNoMetricsProps) {
return (
<div className={cssNames("ClusterNoMetrics flex column box grow justify-center align-center", className)}>
<Icon material="info"/>
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/+config-autoscalers/hpa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ enum columnId {
status = "status",
}

interface Props extends RouteComponentProps<HpaRouteParams> {
export interface HorizontalPodAutoscalersProps extends RouteComponentProps<HpaRouteParams> {
}

@observer
export class HorizontalPodAutoscalers extends React.Component<Props> {
export class HorizontalPodAutoscalers extends React.Component<HorizontalPodAutoscalersProps> {
getTargets(hpa: HorizontalPodAutoscaler) {
const metrics = hpa.getMetrics();

Expand Down
Loading

0 comments on commit a96005b

Please sign in to comment.