cline/eslint-rules
Sarah Fortune 0c6a4f9452
feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946)
* 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-lock.json

* Update package.json
2025-05-30 20:19:04 -07:00
..
__tests__ feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946) 2025-05-30 20:19:04 -07:00
index.js feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946) 2025-05-30 20:19:04 -07:00
no-grpc-client-object-literals.js feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946) 2025-05-30 20:19:04 -07:00
package-lock.json feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946) 2025-05-30 20:19:04 -07:00
package.json feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946) 2025-05-30 20:19:04 -07:00
tsconfig.json feat(lint): Add custom ESLint rules for protobuf type checking for protobus ServiceClients (#3946) 2025-05-30 20:19:04 -07:00