Skip to content

Commit

Permalink
add elixir support
Browse files Browse the repository at this point in the history
  • Loading branch information
juli1 committed Jan 7, 2025
1 parent 3416ce2 commit b81b895
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/cli/src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use kernel::model::violation::Violation;
static FILE_EXTENSIONS_PER_LANGUAGE_LIST: &[(Language, &[&str])] = &[
(Language::Csharp, &["cs"]),
(Language::Dockerfile, &["docker", "dockerfile"]),
(Language::Elixir, &["ex"]),
(Language::Go, &["go"]),
(Language::Java, &["java"]),
(Language::JavaScript, &["js", "jsx", "mjs", "cjs"]),
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 @@ -69,6 +69,15 @@ fn main() {
files: vec!["parser.c".to_string()],
cpp: false,
},
TreeSitterProject {
name: "tree-sitter-elixir".to_string(),
compilation_unit: "tree-sitter-elixir".to_string(),
repository: "https://github.com/elixir-lang/tree-sitter-elixir.git".to_string(),
commit_hash: "02a6f7fd4be28dd94ee4dd2ca19cb777053ea74e".to_string(),
build_dir: "src".into(),
files: vec!["parser.c".to_string(), "scanner.c".to_string()],
cpp: false,
},
TreeSitterProject {
name: "tree-sitter-go".to_string(),
compilation_unit: "tree-sitter-go".to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/static-analysis-kernel/src/analysis/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn get_lines_to_ignore(code: &str, language: &Language) -> LinesToIgnore {
Language::Python
| Language::Starlark
| Language::Dockerfile
| Language::Elixir
| Language::Ruby
| Language::Terraform
| Language::Yaml
Expand Down
18 changes: 18 additions & 0 deletions crates/static-analysis-kernel/src/analysis/tree_sitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn get_tree_sitter_language(language: &Language) -> tree_sitter::Language {
extern "C" {
fn tree_sitter_c_sharp() -> tree_sitter::Language;
fn tree_sitter_dockerfile() -> tree_sitter::Language;
fn tree_sitter_elixir() -> tree_sitter::Language;
fn tree_sitter_go() -> tree_sitter::Language;
fn tree_sitter_java() -> tree_sitter::Language;
fn tree_sitter_javascript() -> tree_sitter::Language;
Expand All @@ -37,6 +38,7 @@ pub fn get_tree_sitter_language(language: &Language) -> tree_sitter::Language {
Language::Csharp => unsafe { tree_sitter_c_sharp() },
Language::Dockerfile => unsafe { tree_sitter_dockerfile() },
Language::Go => unsafe { tree_sitter_go() },
Language::Elixir => unsafe { tree_sitter_elixir() },
Language::Java => unsafe { tree_sitter_java() },
Language::JavaScript => unsafe { tree_sitter_javascript() },
Language::Kotlin => unsafe { tree_sitter_kotlin() },
Expand Down Expand Up @@ -646,6 +648,22 @@ print("Hello, World!")
assert_eq!("program", t.root_node().kind());
}

#[test]
fn test_elixir_get_tree() {
let source_code = r#"
defmodule Sum do
def add(a, b) do
a + b
end
end
"#;
let t = get_tree(source_code, &Language::Elixir);
assert!(t.is_some());
let t = t.unwrap();
assert!(!t.root_node().has_error());
assert_eq!("source", t.root_node().kind());
}

#[test]
fn test_sql_get_tree() {
let source_code = r#"
Expand Down
3 changes: 3 additions & 0 deletions crates/static-analysis-kernel/src/model/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum Language {
Csharp,
#[serde(rename = "DOCKERFILE")]
Dockerfile,
#[serde(rename = "ELIXIR")]
Elixir,
#[serde(rename = "GO")]
Go,
#[serde(rename = "JAVA")]
Expand Down Expand Up @@ -93,6 +95,7 @@ impl fmt::Display for Language {
Self::Csharp => "c#",
Self::Dockerfile => "dockerfile",
Self::Go => "go",
Self::Elixir => "elixir",
Self::Java => "java",
Self::JavaScript => "javascript",
Self::Json => "json",
Expand Down

0 comments on commit b81b895

Please sign in to comment.