diff --git a/eslint.config.js b/eslint.config.js index 5cb8b7fcfa..d305f75f87 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -25,6 +25,18 @@ const __dirname = path.dirname(__filename); const projectRoot = __dirname; const currentYear = new Date().getFullYear(); +const commonRestrictedSyntaxRules = [ + { + selector: 'CallExpression[callee.name="require"]', + message: 'Avoid using require(). Use ES6 imports instead.', + }, + { + selector: 'ThrowStatement > Literal:not([value=/^\\w+Error:/])', + message: + 'Do not throw string literals or non-Error objects. Throw new Error("...") instead.', + }, +]; + export default tseslint.config( { // Global ignores @@ -120,18 +132,7 @@ export default tseslint.config( 'no-cond-assign': 'error', 'no-debugger': 'error', 'no-duplicate-case': 'error', - 'no-restricted-syntax': [ - 'error', - { - selector: 'CallExpression[callee.name="require"]', - message: 'Avoid using require(). Use ES6 imports instead.', - }, - { - selector: 'ThrowStatement > Literal:not([value=/^\\w+Error:/])', - message: - 'Do not throw string literals or non-Error objects. Throw new Error("...") instead.', - }, - ], + 'no-restricted-syntax': ['error', ...commonRestrictedSyntaxRules], 'no-unsafe-finally': 'error', 'no-unused-expressions': 'off', // Disable base rule '@typescript-eslint/no-unused-expressions': [ @@ -171,6 +172,28 @@ export default tseslint.config( ], }, }, + { + // API Response Optionality enforcement for Code Assist + files: ['packages/core/src/code_assist/**/*.{ts,tsx}'], + rules: { + 'no-restricted-syntax': [ + 'error', + ...commonRestrictedSyntaxRules, + { + selector: + 'TSInterfaceDeclaration[id.name=/.+Response$/] TSPropertySignature:not([optional=true])', + message: + 'All fields in API response interfaces (*Response) must be marked as optional (?) to prevent developers from accidentally assuming a field will always be present based on current backend behavior.', + }, + { + selector: + 'TSTypeAliasDeclaration[id.name=/.+Response$/] TSPropertySignature:not([optional=true])', + message: + 'All fields in API response types (*Response) must be marked as optional (?) to prevent developers from accidentally assuming a field will always be present based on current backend behavior.', + }, + ], + }, + }, { // Rules that only apply to product code files: ['packages/*/src/**/*.{ts,tsx}'], diff --git a/packages/core/src/code_assist/server.ts b/packages/core/src/code_assist/server.ts index dbb749e45d..536bf0c31a 100644 --- a/packages/core/src/code_assist/server.ts +++ b/packages/core/src/code_assist/server.ts @@ -508,6 +508,16 @@ export class CodeAssistServer implements ContentGenerator { } interface VpcScErrorResponse { + response?: { + data?: { + error?: { + details?: unknown[]; + }; + }; + }; +} + +function isVpcScErrorResponse(error: unknown): error is VpcScErrorResponse & { response: { data: { error: { @@ -515,9 +525,7 @@ interface VpcScErrorResponse { }; }; }; -} - -function isVpcScErrorResponse(error: unknown): error is VpcScErrorResponse { +} { return ( !!error && typeof error === 'object' &&