From d7f30fdf73d3015f3f9cdb205d415ee4b3ddc890 Mon Sep 17 00:00:00 2001 From: Sarah Fortune Date: Fri, 30 May 2025 20:31:14 -0700 Subject: [PATCH] Make the no-grpc-client-object-literals linter rule an error for the webview-ui (#3947) * Fix linter warnings in the webview (part 2) Replace protobus calls using object literals to use Message.create({...}) Fix incorrect property name detected after this change in webview-ui/src/components/settings/SettingsView.tsx Optimised imports in vscode. * formatting * feat(lint): Add custom ESLint rules for protobuf type checking Add two custom ESLint rules to enforce proper usage patterns when creating protobuf objects. Using .create() to build protobufs ensures that the protobuf is type checked when it is created. Protobufs created using object literals are not type checked, which can lead to subtle bugs and type mismatches. The linter rules detect when protobufs are created without using .create() or .fromPartial(). - no-protobuf-object-literals: Enforces the use of `.create()` or `.fromPartial()` methods instead of object literals when creating protobuf types. ``` /Users/sjf/cline/src/shared/proto-conversions/state/chat-settings-conversion.ts 9:9 warning Use ChatSettings.create() or ChatSettings.fromPartial() instead of object literal for protobuf type Found: return { mode: chatSettings.mode === "plan" ? PlanActMode.PLAN : PlanActMode.ACT, preferredLanguage: chatSettings.preferredLanguage, openAiReasoningEffort: chatSettings.openAIReasoningEffort, } Suggestion: ChatSettings.create({ mode: chatSettings.mode === "plan" ? PlanActMode.PLAN : PlanActMode.ACT, preferredLanguage: chatSettings.preferredLanguage, openAiReasoningEffort: chatSettings.openAIReasoningEffort, }) ``` - no-grpc-client-object-literals: Enforces proper protobuf creation for gRPC service client parameters. This needs a separate rule because the type signatures of the ServiceClients methods are too generic to be detected by the previous rule. ``` /Users/sjf/cline/webview-ui/src/components/mcp/configuration/tabs/add-server/AddRemoteServerForm.tsx 41:62 warning Use the appropriate protobuf .create() or .fromPartial() method instead of object literal for gRPC client parameters. Found: McpServiceClient.addRemoteMcpServer({ serverName: serverName.trim(), serverUrl: serverUrl.trim(), }) ``` These rules help maintain code quality by enforcing consistent patterns for working with protocol buffers throughout the codebase, reducing potential runtime errors from improper message construction. * Update test * Add custom eslint rules to new webview-ui config * Only include webview grpc ServiceClient check * Fix lint errors * formatting * Update package.json * Make the no-grpc-client-object-literals linter rule an error for the webview-ui Fix the last occurrence of this issue. * formatting --- webview-ui/.eslintrc.json | 2 +- webview-ui/src/components/chat/ChatView.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/webview-ui/.eslintrc.json b/webview-ui/.eslintrc.json index fb31ca21..bf375fe6 100644 --- a/webview-ui/.eslintrc.json +++ b/webview-ui/.eslintrc.json @@ -26,7 +26,7 @@ "react-hooks/exhaustive-deps": "off", "prefer-const": "off", "no-extra-semi": "off", - "eslint-rules/no-grpc-client-object-literals": "warn" + "eslint-rules/no-grpc-client-object-literals": "error" }, "ignorePatterns": ["build"] } diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 8dfea2a1..fde690c8 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -35,7 +35,7 @@ import rehypeParse from "rehype-parse" import HomeHeader from "../welcome/HomeHeader" import AutoApproveBar from "./auto-approve-menu/AutoApproveBar" import { SuggestedTasks } from "../welcome/SuggestedTasks" -import { EmptyRequest, StringRequest } from "@shared/proto/common" +import { BooleanRequest, EmptyRequest, StringRequest } from "@shared/proto/common" import { AskResponseRequest, NewTaskRequest } from "@shared/proto/task" interface ChatViewProps { @@ -653,9 +653,11 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie const selectFilesAndImages = useCallback(async () => { try { - const response = await FileServiceClient.selectFiles({ - value: selectedModelInfo.supportsImages, - }) + const response = await FileServiceClient.selectFiles( + BooleanRequest.create({ + value: selectedModelInfo.supportsImages, + }), + ) if ( response && response.values1 &&