{"record":{"id":"5a959d3cdd2f60fa","repo":"pbakaus/impeccable","slug":"config-exclude-if-present-must-be-a-string-array","errorCode":null,"errorMessage":"config.exclude, if present, must be a string array","messagePattern":"config\\.exclude, if present, must be a string array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"plugin/skills/impeccable/scripts/live-inject.mjs","lineNumber":459,"sourceCode":"  }\n  return new RegExp('^' + re + '$');\n}\n\n// ---------------------------------------------------------------------------\n// Core operations\n// ---------------------------------------------------------------------------\n\nfunction validateConfig(cfg) {\n  if (!cfg || typeof cfg !== 'object') throw new Error('config.json must be an object');\n  if (!Array.isArray(cfg.files) || cfg.files.length === 0) {\n    throw new Error('config.files (non-empty string array) required');\n  }\n  if (!cfg.files.every((f) => typeof f === 'string' && f.length > 0)) {\n    throw new Error('config.files must contain only non-empty strings');\n  }\n  if (cfg.exclude !== undefined) {\n    if (!Array.isArray(cfg.exclude)) {\n      throw new Error('config.exclude, if present, must be a string array');\n    }\n    if (!cfg.exclude.every((f) => typeof f === 'string' && f.length > 0)) {\n      throw new Error('config.exclude must contain only non-empty strings');\n    }\n  }\n  if (typeof cfg.insertBefore !== 'string' && typeof cfg.insertAfter !== 'string') {\n    throw new Error('config.insertBefore or config.insertAfter (string) required');\n  }\n  if (cfg.commentSyntax !== 'html' && cfg.commentSyntax !== 'jsx') {\n    throw new Error(\"config.commentSyntax must be 'html' or 'jsx'\");\n  }\n  if (cfg.cspChecked !== undefined && typeof cfg.cspChecked !== 'boolean') {\n    throw new Error(\"config.cspChecked, if present, must be a boolean\");\n  }\n}\n\n// ---------------------------------------------------------------------------\n// Auto-execute","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/pbakaus/impeccable/blob/d14711ae3d1a1dd62dee61a358d27f107c51ccd0/plugin/skills/impeccable/scripts/live-inject.mjs#L441-L477","documentation":"Fourth validateConfig() check: cfg.exclude is optional, but if present it must be an array. Fires when exclude is set to a string, number, object, or null (null is typeof 'object' but not Array.isArray, so it triggers). The exclude list feeds globToRegex filters in resolveFiles(), which iterates with .map(), so a non-array would throw later anyway — this validates early with a clear message.","triggerScenarios":"\"exclude\": \"node_modules\" (string), \"exclude\": null, \"exclude\": {\"node_modules\": true}. A correctly absent exclude key (undefined) skips the whole block.","commonSituations":"User assumed exclude takes a single glob string like gitignore; hand-edit replaced an array with a scalar; a config migration left null where an array used to be.","solutions":["Provide exclude as an array of glob strings, e.g. [\"node_modules\\/**\", \"dist\\/**\"].","Remove the exclude key entirely if you have no exclusions (HARD_EXCLUDES already filters common build dirs).","If migrating, normalise: exclude = exclude == null ? undefined : (Array.isArray(exclude) ? exclude : [exclude]).","Validate with `node live-inject.mjs --check`."],"exampleFix":"// before\n{ \"exclude\": \"node_modules\", ... }\n\n// after\n{ \"exclude\": [\"node_modules\\/**\"], ... }","handlingStrategy":"validation","validationCode":"function isValidExclude(cfg) {\n  return cfg?.exclude === undefined || Array.isArray(cfg.exclude);\n}\nif (!isValidExclude(cfg)) {\n  // normalise a single string to an array, or drop it\n  cfg.exclude = typeof cfg.exclude === 'string' ? [cfg.exclude] : undefined;\n}","typeGuard":"/** True when exclude is absent or a string array. */\nfunction isOptionalStringArray(value) {\n  return value === undefined || Array.isArray(value);\n}","tryCatchPattern":"try {\n  validateConfig(cfg);\n} catch (err) {\n  if (/config\\.exclude, if present, must be a string array/.test(err.message)) {\n    cfg.exclude = Array.isArray(cfg.exclude) ? cfg.exclude : undefined;\n    validateConfig(cfg);\n  }\n  throw err;\n}","preventionTips":["Omit the exclude key entirely when you have no exclusions — HARD_EXCLUDES already filters build dirs.","Always write exclude as an array of globs, never a single string.","Normalise null to undefined before validation."],"tags":["live-inject","config","validation","json"],"backgroundTag":null,"analyzedSha":"d14711ae3d1a1dd62dee61a358d27f107c51ccd0","analyzedAt":"2026-08-13T00:52:25.771Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}