Extract comments from JavaScript code
(code: &str)
| 777 | |
| 778 | /// Extract comments from JavaScript code |
| 779 | fn extract_code_comments(code: &str) -> Vec<String> { |
| 780 | let mut comments = Vec::new(); |
| 781 | |
| 782 | // Single-line comments |
| 783 | let single_line_regex = Regex::new(r"//\s*(.+)$").unwrap(); |
| 784 | for line in code.lines() { |
| 785 | if let Some(cap) = single_line_regex.captures(line) { |
| 786 | if let Some(comment) = cap.get(1) { |
| 787 | let comment_text = comment.as_str().trim(); |
| 788 | // Filter out source map references |
| 789 | if !comment_text.starts_with("# sourceMappingURL") && |
| 790 | !comment_text.starts_with("@ sourceMappingURL") && |
| 791 | comment_text.len() > 5 { |
| 792 | comments.push(comment_text.to_string()); |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | // Multi-line comments |
| 799 | let multi_line_regex = Regex::new(r"/\*\s*([\s\S]*?)\s*\*/").unwrap(); |
| 800 | for cap in multi_line_regex.captures_iter(code) { |
| 801 | if let Some(comment) = cap.get(1) { |
| 802 | let comment_text = comment.as_str().trim(); |
| 803 | if comment_text.len() > 5 { |
| 804 | comments.push(comment_text.to_string()); |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | comments |
| 810 | } |
| 811 | |
| 812 | /// Extract environment variable references from code |
| 813 | pub fn extract_env_variables(code: &str) -> Vec<String> { |
no outgoing calls
no test coverage detected