Skip to content

Commit

Permalink
Add support for typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoire-mullvad committed Sep 27, 2024
1 parent b00c498 commit 7ce22b2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tree-sitter-javascript = "0.23.0"
tree-sitter-python = "0.23.2"
tree-sitter-rust = "0.23.0"
tree-sitter-swift = "0.6.0"
tree-sitter-typescript = "0.23.0"

[dev-dependencies]
trycmd = "0.15.5"
14 changes: 14 additions & 0 deletions example-files/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Comments
// 🛫
/* 📸 */

// String literals
"🐹"
'🐖'
`👃`

// Homoglyph
if (environmentǃ=ENV_PROD) {}

// Invisible
const { timeout,} = req.query;
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub enum Language {
Python,
Rust,
Swift,
Typescript,
}

static GO_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
Expand Down Expand Up @@ -119,6 +120,12 @@ static SWIFT_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"multi_line_str_text" => CodeType::StringLiteral,
};

static TYPESCRIPT_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"comment" => CodeType::Comment,

"string_fragment" => CodeType::StringLiteral,
};

impl Language {
pub fn lookup_code_type(&self, tree_sitter_code_type: &str) -> Option<CodeType> {
match self {
Expand All @@ -127,6 +134,7 @@ impl Language {
Language::Python => PYTHON_CODE_TYPES.get(tree_sitter_code_type).copied(),
Language::Rust => RUST_CODE_TYPES.get(tree_sitter_code_type).copied(),
Language::Swift => SWIFT_CODE_TYPES.get(tree_sitter_code_type).copied(),
Language::Typescript => TYPESCRIPT_CODE_TYPES.get(tree_sitter_code_type).copied(),
}
}

Expand All @@ -137,6 +145,7 @@ impl Language {
Language::Python => tree_sitter_python::LANGUAGE.into(),
Language::Rust => tree_sitter_rust::LANGUAGE.into(),
Language::Swift => tree_sitter_swift::LANGUAGE.into(),
Language::Typescript => tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ fn get_default_config() -> Config {
rules: Default::default(),
},
),
(
Language::Typescript,
config::LanguageRules {
paths: Some(vec![glob::Pattern::new("**/*.ts").unwrap()]),
rules: Default::default(),
},
),
]),
}
}

0 comments on commit 7ce22b2

Please sign in to comment.