MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateBlock

Function validateBlock

source code/keybindings/validate.ts:132–249  ·  view source on GitHub ↗

* Validate a keybinding block from user config.

(
  block: unknown,
  blockIndex: number,
)

Source from the content-addressed store, hash-verified

130 * Validate a keybinding block from user config.
131 */
132function validateBlock(
133 block: unknown,
134 blockIndex: number,
135): KeybindingWarning[] {
136 const warnings: KeybindingWarning[] = []
137
138 if (typeof block !== 'object' || block === null) {
139 warnings.push({
140 type: 'parse_error',
141 severity: 'error',
142 message: `Keybinding block ${blockIndex + 1} is not an object`,
143 })
144 return warnings
145 }
146
147 const b = block as Record<string, unknown>
148
149 // Validate context - extract to narrowed variable for type safety
150 const rawContext = b.context
151 let contextName: string | undefined
152 if (typeof rawContext !== 'string') {
153 warnings.push({
154 type: 'parse_error',
155 severity: 'error',
156 message: `Keybinding block ${blockIndex + 1} missing "context" field`,
157 })
158 } else if (!isValidContext(rawContext)) {
159 warnings.push({
160 type: 'invalid_context',
161 severity: 'error',
162 message: `Unknown context "${rawContext}"`,
163 context: rawContext,
164 suggestion: `Valid contexts: ${VALID_CONTEXTS.join(', ')}`,
165 })
166 } else {
167 contextName = rawContext
168 }
169
170 // Validate bindings
171 if (typeof b.bindings !== 'object' || b.bindings === null) {
172 warnings.push({
173 type: 'parse_error',
174 severity: 'error',
175 message: `Keybinding block ${blockIndex + 1} missing "bindings" field`,
176 })
177 return warnings
178 }
179
180 const bindings = b.bindings as Record<string, unknown>
181 for (const [key, action] of Object.entries(bindings)) {
182 // Validate key syntax
183 const keyError = validateKeystroke(key)
184 if (keyError) {
185 keyError.context = contextName
186 warnings.push(keyError)
187 }
188
189 // Validate action

Callers 1

validateUserConfigFunction · 0.85

Calls 4

isValidContextFunction · 0.85
validateKeystrokeFunction · 0.85
parseChordFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected