diff --git a/packages/backend.ai-client/eslint.config.js b/packages/backend.ai-client/eslint.config.js new file mode 100644 index 0000000000..c3da47b3de --- /dev/null +++ b/packages/backend.ai-client/eslint.config.js @@ -0,0 +1,45 @@ +import { base } from 'eslint-config-bai'; + +export default [ + ...base, + + { + ignores: ['dist/**'], + }, + + { + rules: { + // Enforce `import type` for type-only imports. + '@typescript-eslint/consistent-type-imports': 'error', + // Surface real bugs from un-awaited promises. + '@typescript-eslint/no-floating-promises': 'error', + // Existing code has many `any`s; a strict-typing pass is tracked + // separately under the FR-2792 epic. Keep as warn (overrides the + // shared base which currently turns this rule off entirely) so + // the noise is visible without being a publish-blocker. + '@typescript-eslint/no-explicit-any': 'warn', + '@typescript-eslint/no-unused-vars': [ + 'warn', + { argsIgnorePattern: '^_' }, + ], + }, + languageOptions: { + parserOptions: { + // `no-floating-promises` requires type information. + projectService: true, + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + + // Tests: relax the strictest rules so test scaffolding (e.g. mock + // objects typed as `any`, intentionally fire-and-forget assertions) + // does not block `prepublishOnly`. + { + files: ['**/*.test.ts'], + rules: { + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-explicit-any': 'off', + }, + }, +]; diff --git a/packages/backend.ai-client/package.json b/packages/backend.ai-client/package.json index 342611fce0..cc70859efc 100644 --- a/packages/backend.ai-client/package.json +++ b/packages/backend.ai-client/package.json @@ -36,15 +36,18 @@ "test": "vitest run", "vitest": "vitest run", "vitest:watch": "vitest", - "lint": "eslint ./src --max-warnings=0", + "lint": "eslint ./src", "prepublishOnly": "pnpm lint && pnpm test && pnpm build" }, "dependencies": { "crypto-es": "^2.1.0" }, "devDependencies": { + "@eslint/js": "catalog:", + "eslint-config-bai": "workspace:*", "tsup": "^8.5.0", "typescript": "^5.9.3", + "typescript-eslint": "catalog:", "vitest": "^4.1.4" }, "type": "module" diff --git a/packages/backend.ai-client/src/client.ts b/packages/backend.ai-client/src/client.ts index 1123ae0d6d..f14fef29ad 100644 --- a/packages/backend.ai-client/src/client.ts +++ b/packages/backend.ai-client/src/client.ts @@ -1372,7 +1372,7 @@ export class Client { runId: string, mode: string, code: string, - opts: Object, + opts: object = {}, timeout = 0, ): Promise { let params = { @@ -1865,7 +1865,7 @@ export class Client { .replace(/\s+/g, '-') // Replace spaces with - .replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special chars .replace(/&/g, '-and-') // Replace & with 'and' - .replace(/[^\w\-]+/g, '') // Remove all non-word chars + .replace(/[^\w-]+/g, '') // Remove all non-word chars .replace(/--+/g, '-') // Replace multiple - with single - .replace(/^-+/, '') // Trim - from start of text .replace(/-+$/, ''); // Trim - from end of text diff --git a/packages/backend.ai-client/src/resources/pipeline.ts b/packages/backend.ai-client/src/resources/pipeline.ts index 79900f77cf..6fb853a268 100644 --- a/packages/backend.ai-client/src/resources/pipeline.ts +++ b/packages/backend.ai-client/src/resources/pipeline.ts @@ -41,7 +41,7 @@ export class Pipeline { }), }); // if there's no token, then user account is invalid - if (!result.hasOwnProperty('token')) { + if (!Object.prototype.hasOwnProperty.call(result, 'token')) { return Promise.resolve(false); } else { const token = result.token;