From bf1ee55629576b88fc8ec3036bf998ba29225c5d Mon Sep 17 00:00:00 2001 From: Florent BENOIT Date: Fri, 19 Jan 2024 16:17:28 +0100 Subject: [PATCH] chore: add missing linting rules from Podman Desktop (#98) * chore: add missing linting rules from Podman Desktop fixes issues reported by using the same rules it also fixes https://github.com/projectatomic/studio-extension/issues/97 --- .eslintrc.json | 15 ++++++++------- package.json | 2 +- packages/backend/package.json | 4 +++- .../backend/src/managers/applicationManager.ts | 2 +- packages/backend/src/managers/catalogManager.ts | 2 +- packages/backend/src/managers/playground.ts | 2 +- packages/backend/src/models/AIConfig.ts | 2 +- packages/frontend/package.json | 3 ++- packages/shared/src/messages/MessageProxy.ts | 12 ++---------- yarn.lock | 5 +++++ 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index d48a31a1f..56a15a0a3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -36,13 +36,14 @@ } } }, - "plugins": ["@typescript-eslint", "sonarjs", "etc", "redundant-undefined"], "ignorePatterns": [ "node_modules/**", "**/dist/**" ], + "plugins": ["@typescript-eslint", "sonarjs", "etc", "redundant-undefined", "no-null"], "rules": { - "@typescript-eslint/no-unused-vars": "error", + "eqeqeq": "error", + "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], "@typescript-eslint/no-var-requires": "off", "@typescript-eslint/consistent-type-imports": "error", "@typescript-eslint/no-explicit-any": "error", @@ -51,6 +52,7 @@ "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-misused-promises": "error", "@typescript-eslint/prefer-optional-chain": "error", + "no-null/no-null": "error", /** * Having a semicolon helps the optimizer interpret your code correctly. @@ -71,10 +73,8 @@ /** * Just for beauty */ - "quotes": [ - "warn", "single" - ], - "import/no-duplicates" : "error", + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "import/no-duplicates": "error", "import/no-unresolved": "off", "import/default": "off", "import/no-named-as-default-member": "off", @@ -85,6 +85,7 @@ "sonarjs/no-small-switch": "off", "etc/no-commented-out-code": "error", "etc/no-deprecated": "off", - "redundant-undefined/redundant-undefined": "error" + "redundant-undefined/redundant-undefined": "error", + "import/no-extraneous-dependencies": "error" } } diff --git a/package.json b/package.json index 09d7c53c1..e648818e6 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "typecheck": "npm run typecheck:shared && npm run typecheck:frontend && npm run typecheck:backend" }, "devDependencies": { - "@podman-desktop/api": "0.0.202401191125-9c1aea6", "@typescript-eslint/eslint-plugin": "^6.16.0", "@typescript-eslint/parser": "^6.16.0", "@vitest/coverage-v8": "^1.1.0", @@ -37,6 +36,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-etc": "^2.0.3", "eslint-plugin-import": "^2.29.1", + "eslint-plugin-no-null": "^1.0.2", "eslint-plugin-redundant-undefined": "^1.0.0", "eslint-plugin-sonarjs": "^0.23.0", "prettier": "^3.1.1", diff --git a/packages/backend/package.json b/packages/backend/package.json index 44ad79310..f9580ddf8 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -26,7 +26,9 @@ "simple-git": "^3.22.0" }, "devDependencies": { + "@podman-desktop/api": "0.0.202401191125-9c1aea6", "@types/js-yaml": "^4.0.9", - "@types/node": "^18" + "@types/node": "^18", + "vitest": "^1.1.0" } } diff --git a/packages/backend/src/managers/applicationManager.ts b/packages/backend/src/managers/applicationManager.ts index 4bf23d8e1..08a72253a 100644 --- a/packages/backend/src/managers/applicationManager.ts +++ b/packages/backend/src/managers/applicationManager.ts @@ -291,7 +291,7 @@ export class ApplicationManager { const dirs = entries.filter(dir => dir.isDirectory()); for (const d of dirs) { const modelEntries = fs.readdirSync(path.resolve(d.path, d.name)); - if (modelEntries.length != 1) { + if (modelEntries.length !== 1) { // we support models with one file only for now continue; } diff --git a/packages/backend/src/managers/catalogManager.ts b/packages/backend/src/managers/catalogManager.ts index 776bf27da..565b3df1a 100644 --- a/packages/backend/src/managers/catalogManager.ts +++ b/packages/backend/src/managers/catalogManager.ts @@ -66,7 +66,7 @@ export class CatalogManager { try { this.watchCatalogFile(catalogPath); // do not await, we want to do this async } catch (err: unknown) { - console.error("unable to watch catalog file, changes to the catalog file won't be reflected to the UI", err); + console.error(`unable to watch catalog file, changes to the catalog file won't be reflected to the UI`, err); } try { diff --git a/packages/backend/src/managers/playground.ts b/packages/backend/src/managers/playground.ts index 22645f962..af1016929 100644 --- a/packages/backend/src/managers/playground.ts +++ b/packages/backend/src/managers/playground.ts @@ -40,7 +40,7 @@ function findFirstProvider(): ProviderContainerConnection | undefined { const engines = provider .getContainerConnections() .filter(connection => connection.connection.type === 'podman') - .filter(connection => connection.connection.status() == 'started'); + .filter(connection => connection.connection.status() === 'started'); return engines.length > 0 ? engines[0] : undefined; } diff --git a/packages/backend/src/models/AIConfig.ts b/packages/backend/src/models/AIConfig.ts index 849a549ce..bbca2d10e 100644 --- a/packages/backend/src/models/AIConfig.ts +++ b/packages/backend/src/models/AIConfig.ts @@ -32,7 +32,7 @@ export interface AIConfig { } export function isString(value: unknown): value is string { - return (value !== undefined && value !== null && typeof value === 'string') || value instanceof String; + return (!!value && typeof value === 'string') || value instanceof String; } export function assertString(value: unknown): string { diff --git a/packages/frontend/package.json b/packages/frontend/package.json index 251c320e1..e3b105746 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -35,6 +35,7 @@ "svelte-fa": "^3.0.4", "svelte-markdown": "^0.4.1", "svelte-preprocess": "^5.1.3", - "tailwindcss": "^3.4.0" + "tailwindcss": "^3.4.0", + "vitest": "^1.1.0" } } diff --git a/packages/shared/src/messages/MessageProxy.ts b/packages/shared/src/messages/MessageProxy.ts index e98e83c56..c844df415 100644 --- a/packages/shared/src/messages/MessageProxy.ts +++ b/packages/shared/src/messages/MessageProxy.ts @@ -42,9 +42,7 @@ export interface ISubscribedMessage { type UnaryRPC = (...args: unknown[]) => Promise; export function isMessageRequest(content: unknown): content is IMessageRequest { - return ( - content !== undefined && content !== null && typeof content === 'object' && 'id' in content && 'channel' in content - ); + return !!content && typeof content === 'object' && 'id' in content && 'channel' in content; } export function isMessageResponse(content: unknown): content is IMessageResponse { @@ -208,12 +206,6 @@ export class RpcBrowser { } isSubscribedMessage(content: any): content is ISubscribedMessage { - return ( - content !== undefined && - content !== null && - 'id' in content && - 'body' in content && - this.subscribers.has(content.id) - ); + return !!content && 'id' in content && 'body' in content && this.subscribers.has(content.id); } } diff --git a/yarn.lock b/yarn.lock index 32cd7680d..ef695ab7a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1788,6 +1788,11 @@ eslint-plugin-import@^2.29.1: semver "^6.3.1" tsconfig-paths "^3.15.0" +eslint-plugin-no-null@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-no-null/-/eslint-plugin-no-null-1.0.2.tgz#1236a812391390a1877ad4007c26e745341c951f" + integrity sha512-uRDiz88zCO/2rzGfgG15DBjNsgwWtWiSo4Ezy7zzajUgpnFIqd1TjepKeRmJZHEfBGu58o2a8S0D7vglvvhkVA== + eslint-plugin-redundant-undefined@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/eslint-plugin-redundant-undefined/-/eslint-plugin-redundant-undefined-1.0.0.tgz"