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

Function extractDangerousPatterns

src/utils/bash/treeSitterAnalysis.ts:448–489  ·  view source on GitHub ↗
(rootNode: unknown)

Source from the content-addressed store, hash-verified

446 * Extract dangerous pattern information from the AST.
447 */
448export function extractDangerousPatterns(rootNode: unknown): DangerousPatterns {
449 const n = rootNode as TreeSitterNode
450 let hasCommandSubstitution = false
451 let hasProcessSubstitution = false
452 let hasParameterExpansion = false
453 let hasHeredoc = false
454 let hasComment = false
455
456 function walk(node: TreeSitterNode): void {
457 switch (node.type) {
458 case 'command_substitution':
459 hasCommandSubstitution = true
460 break
461 case 'process_substitution':
462 hasProcessSubstitution = true
463 break
464 case 'expansion':
465 hasParameterExpansion = true
466 break
467 case 'heredoc_redirect':
468 hasHeredoc = true
469 break
470 case 'comment':
471 hasComment = true
472 break
473 }
474
475 for (const child of node.children) {
476 if (child) walk(child)
477 }
478 }
479
480 walk(n)
481
482 return {
483 hasCommandSubstitution,
484 hasProcessSubstitution,
485 hasParameterExpansion,
486 hasHeredoc,
487 hasComment,
488 }
489}
490
491/**
492 * Perform complete tree-sitter analysis of a command.

Callers 1

analyzeCommandFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected