Skip to main content

normalize_languages/
css.rs

1//! CSS language support (parse only, minimal skeleton).
2
3use crate::external_packages::ResolvedPackage;
4use crate::{Export, Import, Language, Symbol, Visibility, VisibilityMechanism};
5use std::path::{Path, PathBuf};
6use tree_sitter::Node;
7
8/// CSS language support.
9pub struct Css;
10
11impl Language for Css {
12    fn name(&self) -> &'static str {
13        "CSS"
14    }
15    fn extensions(&self) -> &'static [&'static str] {
16        &["css", "scss"]
17    }
18    fn grammar_name(&self) -> &'static str {
19        "css"
20    }
21
22    fn has_symbols(&self) -> bool {
23        false
24    }
25
26    // CSS has no functions/containers/types in the traditional sense
27    fn container_kinds(&self) -> &'static [&'static str] {
28        &[]
29    }
30    fn function_kinds(&self) -> &'static [&'static str] {
31        &[]
32    }
33    fn type_kinds(&self) -> &'static [&'static str] {
34        &[]
35    }
36    fn import_kinds(&self) -> &'static [&'static str] {
37        &[]
38    }
39    fn public_symbol_kinds(&self) -> &'static [&'static str] {
40        &[]
41    }
42    fn visibility_mechanism(&self) -> VisibilityMechanism {
43        VisibilityMechanism::NotApplicable
44    }
45    fn scope_creating_kinds(&self) -> &'static [&'static str] {
46        &[]
47    }
48    fn control_flow_kinds(&self) -> &'static [&'static str] {
49        &[]
50    }
51    fn complexity_nodes(&self) -> &'static [&'static str] {
52        &[]
53    }
54    fn nesting_nodes(&self) -> &'static [&'static str] {
55        &[]
56    }
57
58    fn signature_suffix(&self) -> &'static str {
59        ""
60    }
61
62    fn extract_function(
63        &self,
64        _node: &Node,
65        _content: &str,
66        _in_container: bool,
67    ) -> Option<Symbol> {
68        None
69    }
70
71    fn extract_container(&self, _node: &Node, _content: &str) -> Option<Symbol> {
72        None
73    }
74
75    fn extract_type(&self, _node: &Node, _content: &str) -> Option<Symbol> {
76        None
77    }
78    fn extract_docstring(&self, _node: &Node, _content: &str) -> Option<String> {
79        None
80    }
81
82    fn extract_attributes(&self, _node: &Node, _content: &str) -> Vec<String> {
83        Vec::new()
84    }
85    fn extract_imports(&self, _node: &Node, _content: &str) -> Vec<Import> {
86        Vec::new()
87    }
88
89    fn format_import(&self, _import: &Import, _names: Option<&[&str]>) -> String {
90        // CSS @import not tracked
91        String::new()
92    }
93    fn extract_public_symbols(&self, _node: &Node, _content: &str) -> Vec<Export> {
94        Vec::new()
95    }
96
97    fn is_public(&self, _node: &Node, _content: &str) -> bool {
98        true
99    }
100    fn get_visibility(&self, _node: &Node, _content: &str) -> Visibility {
101        Visibility::Public
102    }
103
104    fn is_test_symbol(&self, _symbol: &crate::Symbol) -> bool {
105        false
106    }
107
108    fn embedded_content(&self, _node: &Node, _content: &str) -> Option<crate::EmbeddedBlock> {
109        None
110    }
111
112    fn container_body<'a>(&self, _node: &'a Node<'a>) -> Option<Node<'a>> {
113        None
114    }
115    fn body_has_docstring(&self, _body: &Node, _content: &str) -> bool {
116        false
117    }
118    fn node_name<'a>(&self, _node: &Node, _content: &'a str) -> Option<&'a str> {
119        None
120    }
121
122    fn file_path_to_module_name(&self, _: &Path) -> Option<String> {
123        None
124    }
125    fn module_name_to_paths(&self, _: &str) -> Vec<String> {
126        Vec::new()
127    }
128
129    fn lang_key(&self) -> &'static str {
130        ""
131    }
132    fn resolve_local_import(&self, _: &str, _: &Path, _: &Path) -> Option<PathBuf> {
133        None
134    }
135    fn resolve_external_import(&self, _: &str, _: &Path) -> Option<ResolvedPackage> {
136        None
137    }
138    fn is_stdlib_import(&self, _: &str, _: &Path) -> bool {
139        false
140    }
141    fn get_version(&self, _: &Path) -> Option<String> {
142        None
143    }
144    fn find_package_cache(&self, _: &Path) -> Option<PathBuf> {
145        None
146    }
147    fn indexable_extensions(&self) -> &'static [&'static str] {
148        &[]
149    }
150    fn find_stdlib(&self, _: &Path) -> Option<PathBuf> {
151        None
152    }
153    fn package_module_name(&self, name: &str) -> String {
154        name.to_string()
155    }
156    fn package_sources(&self, _: &Path) -> Vec<crate::PackageSource> {
157        Vec::new()
158    }
159    fn discover_packages(&self, _: &crate::PackageSource) -> Vec<(String, PathBuf)> {
160        Vec::new()
161    }
162    fn find_package_entry(&self, _: &Path) -> Option<PathBuf> {
163        None
164    }
165
166    fn should_skip_package_entry(&self, name: &str, is_dir: bool) -> bool {
167        use crate::traits::{has_extension, skip_dotfiles};
168        if skip_dotfiles(name) {
169            return true;
170        }
171        !is_dir && !has_extension(name, self.indexable_extensions())
172    }
173}
174
175#[cfg(test)]
176mod tests {
177    use super::*;
178    use crate::validate_unused_kinds_audit;
179
180    #[test]
181    fn unused_node_kinds_audit() {
182        #[rustfmt::skip]
183        let documented_unused: &[&str] = &[
184            "binary_expression", "block", "call_expression", "charset_statement",
185            "class_name", "class_selector", "declaration", "function_name",
186            "identifier", "import_statement", "important", "important_value",
187            "keyframe_block", "keyframe_block_list", "keyframes_statement",
188            "media_statement", "namespace_statement", "postcss_statement",
189            "pseudo_class_selector", "scope_statement", "supports_statement",
190        ];
191        validate_unused_kinds_audit(&Css, documented_unused)
192            .expect("CSS unused node kinds audit failed");
193    }
194}