Rejects a single file that declares the same component `kind` more than once.
(path: &Path, document: &Json)
| 1135 | |
| 1136 | /// Rejects a single file that declares the same component `kind` more than once. |
| 1137 | fn validate_unique_component_kinds(path: &Path, document: &Json) -> Result<()> { |
| 1138 | let Some(components) = document.get("components").and_then(Json::as_array) else { |
| 1139 | return Ok(()); |
| 1140 | }; |
| 1141 | let mut seen = HashSet::new(); |
| 1142 | let mut duplicates = Vec::new(); |
| 1143 | for component in components { |
| 1144 | if let Some(kind) = component_kind(component) |
| 1145 | && !seen.insert(kind) |
| 1146 | { |
| 1147 | duplicates.push(kind.to_string()); |
| 1148 | } |
| 1149 | } |
| 1150 | if duplicates.is_empty() { |
| 1151 | return Ok(()); |
| 1152 | } |
| 1153 | duplicates.sort(); |
| 1154 | duplicates.dedup(); |
| 1155 | Err(PluginError::InvalidConfig(format!( |
| 1156 | "duplicate plugin component kind in {}: {}; declare each kind once per plugins.toml", |
| 1157 | path.display(), |
| 1158 | duplicates.join(", ") |
| 1159 | ))) |
| 1160 | } |
| 1161 | |
| 1162 | /// Default `plugins.toml` search path (lowest precedence first): system, nearest |
| 1163 | /// project file, then user file — mirroring the gateway's discovery. `pub` only |
no test coverage detected