diff --git a/crates/prek-identify/gen.py b/crates/prek-identify/gen.py index ad70dc440..041cbcbe3 100644 --- a/crates/prek-identify/gen.py +++ b/crates/prek-identify/gen.py @@ -37,6 +37,14 @@ ("TAG_SET_YAML", ["yaml"]), ] +# This override is intentionally undesirable: it may diverge from upstream +# identify, but upstream is unlikely to accept this mapping. We reluctantly +# carry it here because there is no practical upstream path for now. +EXTENSION_OVERRIDES = { + "cts": {"text", "ts"}, + "mts": {"text", "ts"}, +} + SELF_DIR = Path(__file__).parent TAGS_FILE = SELF_DIR / "src/tags.rs" @@ -77,6 +85,7 @@ def tagset_expr(tag_set): f.write("};\n\n") EXTENSIONS.update(EXTENSIONS_NEED_BINARY_CHECK) + EXTENSIONS.update(EXTENSION_OVERRIDES) f.write("pub const EXTENSIONS: phf::Map<&str, TagSet> = phf::phf_map! {\n") for ext in sorted(EXTENSIONS): tag_names = sorted(EXTENSIONS[ext]) diff --git a/crates/prek-identify/src/lib.rs b/crates/prek-identify/src/lib.rs index 73ab76750..e7b45385f 100644 --- a/crates/prek-identify/src/lib.rs +++ b/crates/prek-identify/src/lib.rs @@ -573,6 +573,12 @@ mod tests { let tags = super::tags_from_filename(Path::new("data.json")); assert_tagset(&tags, &["json", "text"]); + let tags = super::tags_from_filename(Path::new("index.cts")); + assert_tagset(&tags, &["text", "ts"]); + + let tags = super::tags_from_filename(Path::new("index.mts")); + assert_tagset(&tags, &["text", "ts"]); + let tags = super::tags_from_filename(Path::new("build.props")); assert_tagset(&tags, &["msbuild", "text", "xml"]); diff --git a/crates/prek-identify/src/tags.rs b/crates/prek-identify/src/tags.rs index f7dab13ba..c649446de 100644 --- a/crates/prek-identify/src/tags.rs +++ b/crates/prek-identify/src/tags.rs @@ -488,6 +488,8 @@ pub const EXTENSIONS: phf::Map<&str, TagSet> = phf::phf_map! { "csv" => TagSet::new(&[48, 255]), // ["c#", "c#script", "text"] "csx" => TagSet::new(&[29, 30, 255]), + // ["text", "ts"] + "cts" => TagSet::new(&[255, 261]), // ["cuda", "text"] "cu" => TagSet::new(&[49, 255]), // ["cue", "text"] @@ -756,6 +758,8 @@ pub const EXTENSIONS: phf::Map<&str, TagSet> = phf::phf_map! { "mscx" => TagSet::new(&[169, 255, 297]), // ["binary", "musescore", "zip"] "mscz" => TagSet::new(&[21, 169, 308]), + // ["text", "ts"] + "mts" => TagSet::new(&[255, 261]), // ["mustache", "text"] "mustache" => TagSet::new(&[170, 255]), // ["myst", "text"]