From b95e22437bf50e226831425f5e50af20e27ffd54 Mon Sep 17 00:00:00 2001 From: miaoda Date: Thu, 12 Feb 2026 14:43:34 +0800 Subject: [PATCH] fix: Add JSX and TSX file support to ast-grep scanner - Add tsx and jsx language mapping in detectLangFromRuleID function - Improve TypeScript rules to use kind: import_statement for better accuracy - Add arrow_function support to function detection - Create dedicated rule files for JSX and TSX languages This fix enables codemap to properly scan React/TypeScript projects that use .jsx and .tsx file extensions. Co-Authored-By: Claude Sonnet 4.5 --- scanner/astgrep.go | 4 ++++ scanner/sg-rules/jsx.yml | 12 ++++++++++++ scanner/sg-rules/tsx.yml | 12 ++++++++++++ scanner/sg-rules/typescript.yml | 6 ++---- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 scanner/sg-rules/jsx.yml create mode 100644 scanner/sg-rules/tsx.yml diff --git a/scanner/astgrep.go b/scanner/astgrep.go index 13c29cf..8d994ee 100644 --- a/scanner/astgrep.go +++ b/scanner/astgrep.go @@ -195,8 +195,12 @@ func detectLangFromRuleID(ruleID string) string { return "go" case "ts": return "typescript" + case "tsx": + return "typescript" case "js": return "javascript" + case "jsx": + return "javascript" case "py": return "python" case "rust": diff --git a/scanner/sg-rules/jsx.yml b/scanner/sg-rules/jsx.yml new file mode 100644 index 0000000..b09fc2d --- /dev/null +++ b/scanner/sg-rules/jsx.yml @@ -0,0 +1,12 @@ +id: jsx-imports +language: jsx +rule: + kind: import_statement +--- +id: jsx-functions +language: jsx +rule: + any: + - kind: function_declaration + - kind: method_definition + - kind: arrow_function diff --git a/scanner/sg-rules/tsx.yml b/scanner/sg-rules/tsx.yml new file mode 100644 index 0000000..3d13096 --- /dev/null +++ b/scanner/sg-rules/tsx.yml @@ -0,0 +1,12 @@ +id: tsx-imports +language: tsx +rule: + kind: import_statement +--- +id: tsx-functions +language: tsx +rule: + any: + - kind: function_declaration + - kind: method_definition + - kind: arrow_function diff --git a/scanner/sg-rules/typescript.yml b/scanner/sg-rules/typescript.yml index c12dffd..597cd54 100644 --- a/scanner/sg-rules/typescript.yml +++ b/scanner/sg-rules/typescript.yml @@ -1,10 +1,7 @@ id: ts-imports language: typescript rule: - any: - - pattern: import $$$_ from "$PATH" - - pattern: import "$PATH" - - pattern: require("$PATH") + kind: import_statement --- id: ts-functions language: typescript @@ -12,3 +9,4 @@ rule: any: - kind: function_declaration - kind: method_definition + - kind: arrow_function