MCPcopy Index your code
hub / github.com/codeaashu/claude-code / validateBlock

Function validateBlock

src/keybindings/validate.ts:130–247  ·  view source on GitHub ↗

* Validate a keybinding block from user config.

(
  block: unknown,
  blockIndex: number,
)

Source from the content-addressed store, hash-verified

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

Callers 1

validateUserConfigFunction · 0.85

Calls 5

isValidContextFunction · 0.85
validateKeystrokeFunction · 0.85
parseChordFunction · 0.85
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected