diff --git a/Cargo.lock b/Cargo.lock index c36a42c..786f802 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -887,6 +887,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-typescript" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecf1585ae2a9dddc2b1d4c0e2140b2ec9876e2a25fd79de47fcf7dae0384685" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "trycmd" version = "0.15.5" @@ -991,6 +1001,7 @@ dependencies = [ "tree-sitter-python", "tree-sitter-rust", "tree-sitter-swift", + "tree-sitter-typescript", "trycmd", "unic-ucd-name", "walkdir", diff --git a/Cargo.toml b/Cargo.toml index bcf856f..f19c973 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/example-files/example.ts b/example-files/example.ts new file mode 100644 index 0000000..760a465 --- /dev/null +++ b/example-files/example.ts @@ -0,0 +1,14 @@ +// Comments +// 🛫 +/* 📸 */ + +// String literals +"🐹" +'🐖' +`👃` + +// Homoglyph +if (environmentǃ=ENV_PROD) {} + +// Invisible +const { timeout,ᅠ} = req.query; diff --git a/src/config.rs b/src/config.rs index 5f11986..56947b5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -80,6 +80,7 @@ pub enum Language { Python, Rust, Swift, + Typescript, } static GO_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! { @@ -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 { match self { @@ -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(), } } @@ -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(), } } } diff --git a/src/main.rs b/src/main.rs index 89bf231..8b59426 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(), + }, + ), ]), } }