normalize_languages/
sshconfig.rs1use crate::external_packages::ResolvedPackage;
4use crate::{Export, Import, Language, Symbol, Visibility, VisibilityMechanism};
5use std::path::{Path, PathBuf};
6use tree_sitter::Node;
7
8pub struct SshConfig;
10
11impl Language for SshConfig {
12 fn name(&self) -> &'static str {
13 "SSH Config"
14 }
15 fn extensions(&self) -> &'static [&'static str] {
16 &[]
17 } fn grammar_name(&self) -> &'static str {
19 "ssh-config"
20 }
21
22 fn has_symbols(&self) -> bool {
23 true
24 }
25
26 fn container_kinds(&self) -> &'static [&'static str] {
27 &[]
28 }
29 fn function_kinds(&self) -> &'static [&'static str] {
30 &[]
31 }
32 fn type_kinds(&self) -> &'static [&'static str] {
33 &[]
34 }
35 fn import_kinds(&self) -> &'static [&'static str] {
36 &[]
37 }
38 fn public_symbol_kinds(&self) -> &'static [&'static str] {
39 &[]
40 }
41
42 fn visibility_mechanism(&self) -> VisibilityMechanism {
43 VisibilityMechanism::AllPublic
44 }
45
46 fn extract_public_symbols(&self, _node: &Node, _content: &str) -> Vec<Export> {
47 Vec::new()
48 }
49
50 fn scope_creating_kinds(&self) -> &'static [&'static str] {
51 &[]
52 }
53 fn control_flow_kinds(&self) -> &'static [&'static str] {
54 &[]
55 }
56 fn complexity_nodes(&self) -> &'static [&'static str] {
57 &[]
58 }
59 fn nesting_nodes(&self) -> &'static [&'static str] {
60 &[]
61 }
62
63 fn signature_suffix(&self) -> &'static str {
64 ""
65 }
66
67 fn extract_function(
68 &self,
69 _node: &Node,
70 _content: &str,
71 _in_container: bool,
72 ) -> Option<Symbol> {
73 None
74 }
75 fn extract_container(&self, _node: &Node, _content: &str) -> Option<Symbol> {
76 None
77 }
78 fn extract_type(&self, _node: &Node, _content: &str) -> Option<Symbol> {
79 None
80 }
81 fn extract_docstring(&self, _node: &Node, _content: &str) -> Option<String> {
82 None
83 }
84
85 fn extract_attributes(&self, _node: &Node, _content: &str) -> Vec<String> {
86 Vec::new()
87 }
88 fn extract_imports(&self, _node: &Node, _content: &str) -> Vec<Import> {
89 Vec::new()
90 }
91
92 fn format_import(&self, _import: &Import, _names: Option<&[&str]>) -> String {
93 String::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
116 fn body_has_docstring(&self, _body: &Node, _content: &str) -> bool {
117 false
118 }
119
120 fn node_name<'a>(&self, node: &Node, content: &'a str) -> Option<&'a str> {
121 node.child_by_field_name("name")
122 .map(|n| &content[n.byte_range()])
123 }
124
125 fn file_path_to_module_name(&self, path: &Path) -> Option<String> {
126 let name = path.file_name()?.to_str()?;
127 if name == "config" || name == "ssh_config" || name.ends_with("_config") {
128 return Some(name.to_string());
129 }
130 None
131 }
132
133 fn module_name_to_paths(&self, _module: &str) -> Vec<String> {
134 vec!["config".to_string(), "ssh_config".to_string()]
135 }
136
137 fn lang_key(&self) -> &'static str {
138 "ssh-config"
139 }
140
141 fn is_stdlib_import(&self, _: &str, _: &Path) -> bool {
142 false
143 }
144 fn find_stdlib(&self, _: &Path) -> Option<PathBuf> {
145 None
146 }
147 fn resolve_local_import(&self, _: &str, _: &Path, _: &Path) -> Option<PathBuf> {
148 None
149 }
150 fn resolve_external_import(&self, _: &str, _: &Path) -> Option<ResolvedPackage> {
151 None
152 }
153 fn get_version(&self, _: &Path) -> Option<String> {
154 None
155 }
156 fn find_package_cache(&self, _: &Path) -> Option<PathBuf> {
157 None
158 }
159 fn indexable_extensions(&self) -> &'static [&'static str] {
160 &[]
161 }
162 fn package_sources(&self, _: &Path) -> Vec<crate::PackageSource> {
163 Vec::new()
164 }
165
166 fn should_skip_package_entry(&self, name: &str, _is_dir: bool) -> bool {
167 use crate::traits::skip_dotfiles;
168 skip_dotfiles(name)
169 }
170
171 fn discover_packages(&self, _: &crate::PackageSource) -> Vec<(String, PathBuf)> {
172 Vec::new()
173 }
174
175 fn package_module_name(&self, entry_name: &str) -> String {
176 entry_name.to_string()
177 }
178
179 fn find_package_entry(&self, path: &Path) -> Option<PathBuf> {
180 if path.is_file() {
181 Some(path.to_path_buf())
182 } else {
183 None
184 }
185 }
186}
187
188#[cfg(test)]
189mod tests {
190 use super::*;
191 use crate::validate_unused_kinds_audit;
192
193 #[test]
194 fn unused_node_kinds_audit() {
195 #[rustfmt::skip]
196 let documented_unused: &[&str] = &[
197 "host_declaration", "match_declaration",
198 ];
199 validate_unused_kinds_audit(&SshConfig, documented_unused)
200 .expect("SSH Config unused node kinds audit failed");
201 }
202}