Skip to content

Commit 2f321e9

Browse files
committed
fix: address PR #5491 review feedback
- Standardized terminology from 'whitelisted/blacklisted' to 'allowed/denied' across all i18n files - Removed unused _isExpanded and terminalShellIntegrationDisabled variables in CommandExecution.tsx - Added comprehensive JSDoc documentation to complex algorithms in commandPatterns.ts - Consolidated redundant command parsing logic into unified commandUtils module - Updated all imports to use the new centralized utilities - Maintained backward compatibility with re-exports where needed All tests passing after refactoring.
1 parent 51d010e commit 2f321e9

27 files changed

+405
-297
lines changed

src/core/webview/__tests__/webviewMessageHandler.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ vi.mock("vscode", () => ({
2222
// Mock i18n
2323
vi.mock("../../../i18n", () => ({
2424
t: vi.fn((key: string, params?: any) => {
25-
if (key === "common:info.command_whitelisted" && params?.pattern) {
26-
return `Command pattern "${params.pattern}" has been whitelisted`
25+
if (key === "common:info.command_allowed" && params?.pattern) {
26+
return `Command pattern "${params.pattern}" has been allowed`
2727
}
2828
return key
2929
}),
@@ -36,7 +36,7 @@ vi.mock("../../../shared/package", () => ({
3636
},
3737
}))
3838

39-
describe("webviewMessageHandler - whitelistCommand", () => {
39+
describe("webviewMessageHandler - allowCommand", () => {
4040
let mockProvider: any
4141
let mockContextProxy: any
4242
let mockConfigUpdate: any
@@ -74,7 +74,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
7474

7575
// Create message
7676
const message = {
77-
type: "whitelistCommand",
77+
type: "allowCommand",
7878
pattern: "npm run build",
7979
}
8080

@@ -90,7 +90,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
9090

9191
// Verify user was notified
9292
expect(vscode.window.showInformationMessage).toHaveBeenCalledWith(
93-
'Command pattern "npm run build" has been whitelisted',
93+
'Command pattern "npm run build" has been allowed',
9494
)
9595

9696
// Verify state was posted to webview
@@ -103,7 +103,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
103103

104104
// Create message with duplicate pattern
105105
const message = {
106-
type: "whitelistCommand",
106+
type: "allowCommand",
107107
pattern: "npm run build",
108108
}
109109

@@ -126,7 +126,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
126126

127127
// Create message
128128
const message = {
129-
type: "whitelistCommand",
129+
type: "allowCommand",
130130
pattern: "echo 'Hello, World!'",
131131
}
132132

@@ -138,7 +138,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
138138

139139
// Verify user was notified
140140
expect(vscode.window.showInformationMessage).toHaveBeenCalledWith(
141-
`Command pattern "echo 'Hello, World!'" has been whitelisted`,
141+
`Command pattern "echo 'Hello, World!'" has been allowed`,
142142
)
143143
})
144144

@@ -148,7 +148,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
148148

149149
// Create message
150150
const message = {
151-
type: "whitelistCommand",
151+
type: "allowCommand",
152152
pattern: "npm run dev",
153153
}
154154

@@ -166,7 +166,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
166166
it("should handle missing pattern gracefully", async () => {
167167
// Create message without pattern
168168
const message = {
169-
type: "whitelistCommand",
169+
type: "allowCommand",
170170
}
171171

172172
// Call handler
@@ -181,7 +181,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
181181
it("should handle non-string pattern gracefully", async () => {
182182
// Create message with non-string pattern
183183
const message = {
184-
type: "whitelistCommand",
184+
type: "allowCommand",
185185
pattern: 123, // Invalid type
186186
}
187187

@@ -200,7 +200,7 @@ describe("webviewMessageHandler - whitelistCommand", () => {
200200

201201
// Create message with complex pattern
202202
const message = {
203-
type: "whitelistCommand",
203+
type: "allowCommand",
204204
pattern: 'echo "Hello, World!" && echo $HOME',
205205
}
206206

src/core/webview/webviewMessageHandler.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ export const webviewMessageHandler = async (
771771

772772
break
773773
}
774-
case "whitelistCommand": {
774+
case "allowCommand": {
775775
// Add a command pattern to the allowed commands list
776776
if (message.pattern && typeof message.pattern === "string") {
777777
const currentCommands = getGlobalState("allowedCommands") ?? []
@@ -786,9 +786,7 @@ export const webviewMessageHandler = async (
786786
await updateGlobalState("allowedCommands", validCommands)
787787

788788
// Show confirmation to the user
789-
vscode.window.showInformationMessage(
790-
t("common:info.command_whitelisted", { pattern: message.pattern }),
791-
)
789+
vscode.window.showInformationMessage(t("common:info.command_allowed", { pattern: message.pattern }))
792790

793791
// Update the webview state
794792
await provider.postStateToWebview()

src/i18n/locales/ca/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"public_share_link_copied": "Enllaç de compartició pública copiat al porta-retalls!",
108108
"mode_exported": "Mode '{{mode}}' exportat correctament",
109109
"mode_imported": "Mode importat correctament",
110-
"command_whitelisted": "El patró d'ordres '{{pattern}}' s'ha afegit a la llista d'ordres permeses",
110+
"command_allowed": "El patró d'ordres '{{pattern}}' s'ha afegit a la llista d'ordres permeses",
111111
"command_denied": "El patró de comanda '{{pattern}}' s'ha afegit a la llista de comandes denegades"
112112
},
113113
"answers": {

src/i18n/locales/de/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"public_share_link_copied": "Öffentlicher Freigabelink in die Zwischenablage kopiert!",
104104
"mode_exported": "Modus '{{mode}}' erfolgreich exportiert",
105105
"mode_imported": "Modus erfolgreich importiert",
106-
"command_whitelisted": "Befehlsmuster '{{pattern}}' wurde zur Liste der erlaubten Befehle hinzugefügt",
106+
"command_allowed": "Befehlsmuster '{{pattern}}' wurde zur Liste der erlaubten Befehle hinzugefügt",
107107
"command_denied": "Das Befehlsmuster '{{pattern}}' wurde zur Liste der verweigerten Befehle hinzugefügt"
108108
},
109109
"answers": {

src/i18n/locales/en/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"image_saved": "Image saved to {{path}}",
104104
"mode_exported": "Mode '{{mode}}' exported successfully",
105105
"mode_imported": "Mode imported successfully",
106-
"command_whitelisted": "Command pattern '{{pattern}}' has been added to the allowed commands list",
106+
"command_allowed": "Command pattern '{{pattern}}' has been added to the allowed commands list",
107107
"command_denied": "Command pattern '{{pattern}}' has been added to the denied commands list"
108108
},
109109
"answers": {

src/i18n/locales/es/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"public_share_link_copied": "¡Enlace de compartición pública copiado al portapapeles!",
104104
"mode_exported": "Modo '{{mode}}' exportado correctamente",
105105
"mode_imported": "Modo importado correctamente",
106-
"command_whitelisted": "El patrón de comando '{{pattern}}' se ha añadido a la lista de comandos permitidos",
106+
"command_allowed": "El patrón de comando '{{pattern}}' se ha añadido a la lista de comandos permitidos",
107107
"command_denied": "El patrón de comando '{{pattern}}' se ha añadido a la lista de comandos denegados"
108108
},
109109
"answers": {

src/i18n/locales/fr/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"public_share_link_copied": "Lien de partage public copié dans le presse-papiers !",
104104
"mode_exported": "Mode '{{mode}}' exporté avec succès",
105105
"mode_imported": "Mode importé avec succès",
106-
"command_whitelisted": "Le modèle de commande '{{pattern}}' a été ajouté à la liste des commandes autorisées",
106+
"command_allowed": "Le modèle de commande '{{pattern}}' a été ajouté à la liste des commandes autorisées",
107107
"command_denied": "Le modèle de commande '{{pattern}}' a été ajouté à la liste des commandes refusées"
108108
},
109109
"answers": {

src/i18n/locales/hi/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"public_share_link_copied": "सार्वजनिक साझाकरण लिंक क्लिपबोर्ड में कॉपी किया गया!",
104104
"mode_exported": "मोड '{{mode}}' सफलतापूर्वक निर्यात किया गया",
105105
"mode_imported": "मोड सफलतापूर्वक आयात किया गया",
106-
"command_whitelisted": "कमांड पैटर्न '{{pattern}}' को अनुमत कमांड सूची में जोड़ा गया है",
106+
"command_allowed": "कमांड पैटर्न '{{pattern}}' को अनुमत कमांड सूची में जोड़ा गया है",
107107
"command_denied": "कमांड पैटर्न '{{pattern}}' को अस्वीकृत कमांड सूची में जोड़ा गया है"
108108
},
109109
"answers": {

src/i18n/locales/id/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"public_share_link_copied": "Tautan berbagi publik disalin ke clipboard!",
104104
"mode_exported": "Mode '{{mode}}' berhasil diekspor",
105105
"mode_imported": "Mode berhasil diimpor",
106-
"command_whitelisted": "Pola perintah '{{pattern}}' telah ditambahkan ke daftar perintah yang diizinkan",
106+
"command_allowed": "Pola perintah '{{pattern}}' telah ditambahkan ke daftar perintah yang diizinkan",
107107
"command_denied": "Pola perintah '{{pattern}}' telah ditambahkan ke daftar perintah yang ditolak"
108108
},
109109
"answers": {

src/i18n/locales/it/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"public_share_link_copied": "Link di condivisione pubblica copiato negli appunti!",
104104
"mode_exported": "Modalità '{{mode}}' esportata con successo",
105105
"mode_imported": "Modalità importata con successo",
106-
"command_whitelisted": "Il modello di comando '{{pattern}}' è stato aggiunto all'elenco dei comandi consentiti",
106+
"command_allowed": "Il modello di comando '{{pattern}}' è stato aggiunto all'elenco dei comandi consentiti",
107107
"command_denied": "Il pattern di comando '{{pattern}}' è stato aggiunto all'elenco dei comandi negati"
108108
},
109109
"answers": {

0 commit comments

Comments
 (0)