Skip to content

Commit d7f30fd

Browse files
authored
Make the no-grpc-client-object-literals linter rule an error for the webview-ui (RooCodeInc#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
1 parent 0c6a4f9 commit d7f30fd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

webview-ui/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"react-hooks/exhaustive-deps": "off",
2727
"prefer-const": "off",
2828
"no-extra-semi": "off",
29-
"eslint-rules/no-grpc-client-object-literals": "warn"
29+
"eslint-rules/no-grpc-client-object-literals": "error"
3030
},
3131
"ignorePatterns": ["build"]
3232
}

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import rehypeParse from "rehype-parse"
3535
import HomeHeader from "../welcome/HomeHeader"
3636
import AutoApproveBar from "./auto-approve-menu/AutoApproveBar"
3737
import { SuggestedTasks } from "../welcome/SuggestedTasks"
38-
import { EmptyRequest, StringRequest } from "@shared/proto/common"
38+
import { BooleanRequest, EmptyRequest, StringRequest } from "@shared/proto/common"
3939
import { AskResponseRequest, NewTaskRequest } from "@shared/proto/task"
4040

4141
interface ChatViewProps {
@@ -653,9 +653,11 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
653653

654654
const selectFilesAndImages = useCallback(async () => {
655655
try {
656-
const response = await FileServiceClient.selectFiles({
657-
value: selectedModelInfo.supportsImages,
658-
})
656+
const response = await FileServiceClient.selectFiles(
657+
BooleanRequest.create({
658+
value: selectedModelInfo.supportsImages,
659+
}),
660+
)
659661
if (
660662
response &&
661663
response.values1 &&

0 commit comments

Comments
 (0)