Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STAL-2707] feat: add Apex support #492

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/cli/src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static FILE_EXTENSIONS_PER_LANGUAGE_LIST: &[(Language, &[&str])] = &[
(Language::Bash, &["sh", "bash"]),
(Language::PHP, &["php"]),
(Language::Markdown, &["md"]),
(Language::Apex, &["cls"]),
];

static FILE_EXACT_MATCH_PER_LANGUAGE_LIST: &[(Language, &[&str])] = &[
Expand Down Expand Up @@ -700,6 +701,7 @@ mod tests {
extensions_per_languages.insert(Language::Bash, 2);
extensions_per_languages.insert(Language::PHP, 1);
extensions_per_languages.insert(Language::Markdown, 1);
extensions_per_languages.insert(Language::Apex, 1);

for (l, e) in extensions_per_languages {
assert_eq!(
Expand Down
9 changes: 9 additions & 0 deletions crates/static-analysis-kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ fn main() {
files: vec!["parser.c".to_string(), "scanner.c".to_string()],
cpp: false,
},
TreeSitterProject {
name: "tree-sitter-apex".to_string(),
compilation_unit: "tree-sitter-apex".to_string(),
repository: "https://github.com/aheber/tree-sitter-sfapex".to_string(),
build_dir: "apex/src".into(),
commit_hash: "9fe5d1fbfd75c11ba48a32db27ac0ed5da57ec78".to_string(),
files: vec!["parser.c".to_string()],
cpp: false,
},
];

// For each project:
Expand Down
2 changes: 1 addition & 1 deletion crates/static-analysis-kernel/src/analysis/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn get_lines_to_ignore(code: &str, language: &Language) -> LinesToIgnore {
| Language::Bash => {
vec!["#no-dd-sa", "#datadog-disable"]
}
Language::JavaScript | Language::TypeScript => {
Language::JavaScript | Language::TypeScript | Language::Apex => {
vec![
"//no-dd-sa",
"/*no-dd-sa",
Expand Down
17 changes: 17 additions & 0 deletions crates/static-analysis-kernel/src/analysis/tree_sitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn get_tree_sitter_language(language: &Language) -> tree_sitter::Language {
fn tree_sitter_bash() -> tree_sitter::Language;
fn tree_sitter_php() -> tree_sitter::Language;
fn tree_sitter_markdown() -> tree_sitter::Language;
fn tree_sitter_apex() -> tree_sitter::Language;
}

match language {
Expand All @@ -48,6 +49,7 @@ pub fn get_tree_sitter_language(language: &Language) -> tree_sitter::Language {
Language::Bash => unsafe { tree_sitter_bash() },
Language::PHP => unsafe { tree_sitter_php() },
Language::Markdown => unsafe { tree_sitter_markdown() },
Language::Apex => unsafe { tree_sitter_apex() },
}
}

Expand Down Expand Up @@ -606,6 +608,21 @@ This is some text
assert_eq!("document", t.root_node().kind());
}

#[test]
fn test_apex_get_tree() {
let source_code = r#"
public class HelloWorld {
public static void main() {
System.out.println('Hello, World');
}
}"#;
let t = get_tree(source_code, &Language::Apex);
assert!(t.is_some());
let t = t.unwrap();
assert!(!t.root_node().has_error());
assert_eq!("parser_output", t.root_node().kind());
}

// test the number of node we should retrieve when executing a rule
#[test]
fn test_get_query_nodes() {
Expand Down
4 changes: 4 additions & 0 deletions crates/static-analysis-kernel/src/model/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub enum Language {
PHP,
#[serde(rename = "MARKDOWN")]
Markdown,
#[serde(rename = "APEX")]
Apex,
}

#[allow(dead_code)]
Expand All @@ -78,6 +80,7 @@ pub static ALL_LANGUAGES: &[Language] = &[
Language::Bash,
Language::PHP,
Language::Markdown,
Language::Apex,
];

impl fmt::Display for Language {
Expand All @@ -101,6 +104,7 @@ impl fmt::Display for Language {
Self::Bash => "bash",
Self::PHP => "php",
Self::Markdown => "markdown",
Self::Apex => "apex",
};
write!(f, "{s}")
}
Expand Down
Loading