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

Function validateSettingsFileContent

src/utils/settings/validation.ts:179–217  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

177 * This is used during file edits to ensure the resulting file is valid.
178 */
179export function validateSettingsFileContent(content: string):
180 | {
181 isValid: true
182 }
183 | {
184 isValid: false
185 error: string
186 fullSchema: string
187 } {
188 try {
189 // Parse the JSON first
190 const jsonData = jsonParse(content)
191
192 // Validate against SettingsSchema in strict mode
193 const result = SettingsSchema().strict().safeParse(jsonData)
194
195 if (result.success) {
196 return { isValid: true }
197 }
198
199 // Format the validation error in a helpful way
200 const errors = formatZodError(result.error, 'settings')
201 const errorMessage =
202 'Settings validation failed:\n' +
203 errors.map(err => `- ${err.path}: ${err.message}`).join('\n')
204
205 return {
206 isValid: false,
207 error: errorMessage,
208 fullSchema: generateSettingsJSONSchema(),
209 }
210 } catch (parseError) {
211 return {
212 isValid: false,
213 error: `Invalid JSON: ${parseError instanceof Error ? parseError.message : 'Unknown parsing error'}`,
214 fullSchema: generateSettingsJSONSchema(),
215 }
216 }
217}
218
219/**
220 * Filters invalid permission rules from raw parsed JSON data before schema validation.

Callers 1

Calls 3

jsonParseFunction · 0.85
formatZodErrorFunction · 0.85

Tested by

no test coverage detected