1use std::fmt;
2
3use codeint_model::{Metric, SourceSet};
4use globset::{Glob, GlobBuilder, GlobSet, GlobSetBuilder};
5use serde_json::Value;
6
7pub(crate) const CONFIGURATION_FILE_NAME: &str = "codeint.json";
8
9#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
10#[error("{message} at line {line} column {column}")]
11pub struct JsoncError {
12 pub message: String,
13 pub line: usize,
14 pub column: usize,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum ConfigSyntax {
19 Json,
20 Toml,
21 Yaml,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
25pub enum ConfigFileKind {
26 #[default]
27 Json,
28 Jsonc,
29 Toml,
30 Yaml,
31 Yml,
32 DotCodeintJson,
33 DotCodeintJsonc,
34 DotCodeintToml,
35 DotCodeintYaml,
36 DotCodeintYml,
37}
38
39impl ConfigFileKind {
40 pub const ALL: [ConfigFileKind; 10] = [
41 ConfigFileKind::Json,
42 ConfigFileKind::Jsonc,
43 ConfigFileKind::Toml,
44 ConfigFileKind::Yaml,
45 ConfigFileKind::Yml,
46 ConfigFileKind::DotCodeintJson,
47 ConfigFileKind::DotCodeintJsonc,
48 ConfigFileKind::DotCodeintToml,
49 ConfigFileKind::DotCodeintYaml,
50 ConfigFileKind::DotCodeintYml,
51 ];
52
53 pub fn file_name(self) -> &'static str {
54 match self {
55 ConfigFileKind::Json => CONFIGURATION_FILE_NAME,
56 ConfigFileKind::Jsonc => "codeint.jsonc",
57 ConfigFileKind::Toml => "codeint.toml",
58 ConfigFileKind::Yaml => "codeint.yaml",
59 ConfigFileKind::Yml => "codeint.yml",
60 ConfigFileKind::DotCodeintJson => ".codeint/config.json",
61 ConfigFileKind::DotCodeintJsonc => ".codeint/config.jsonc",
62 ConfigFileKind::DotCodeintToml => ".codeint/config.toml",
63 ConfigFileKind::DotCodeintYaml => ".codeint/config.yaml",
64 ConfigFileKind::DotCodeintYml => ".codeint/config.yml",
65 }
66 }
67
68 pub fn syntax(self) -> ConfigSyntax {
69 match self {
70 ConfigFileKind::Json
71 | ConfigFileKind::Jsonc
72 | ConfigFileKind::DotCodeintJson
73 | ConfigFileKind::DotCodeintJsonc => ConfigSyntax::Json,
74 ConfigFileKind::Toml | ConfigFileKind::DotCodeintToml => ConfigSyntax::Toml,
75 ConfigFileKind::Yaml
76 | ConfigFileKind::Yml
77 | ConfigFileKind::DotCodeintYaml
78 | ConfigFileKind::DotCodeintYml => ConfigSyntax::Yaml,
79 }
80 }
81}
82
83impl fmt::Display for ConfigFileKind {
84 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
85 formatter.write_str(self.file_name())
86 }
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq)]
90pub enum JsonType {
91 Object,
92 Array,
93 String,
94 Number,
95 Integer,
96 Boolean,
97 Null,
98}
99
100#[derive(Debug, Clone, PartialEq, Eq)]
101pub enum KeySegment {
102 Key(String),
103 Index(usize),
104}
105
106#[derive(Debug, Clone, Default, PartialEq, Eq)]
107pub struct KeyPath(Vec<KeySegment>);
108
109#[derive(Debug, thiserror::Error)]
110pub enum ConfigurationFileError {
111 #[error("{}", format_ambiguous_config_files(files))]
112 AmbiguousConfigFiles { files: Vec<ConfigFileKind> },
113 #[error("cannot read {file}")]
114 Unreadable {
115 file: ConfigFileKind,
116 #[source]
117 source: std::io::Error,
118 },
119 #[error("{file} is a broken symlink")]
120 BrokenSymlink { file: ConfigFileKind },
121 #[error("{file} is not valid JSON")]
122 NotJson {
123 file: ConfigFileKind,
124 #[source]
125 source: serde_json::Error,
126 },
127 #[error("{file} is not valid JSON")]
128 InvalidJsonc {
129 file: ConfigFileKind,
130 #[source]
131 source: JsoncError,
132 },
133 #[error("{file} is not valid TOML: {message}")]
134 InvalidToml {
135 file: ConfigFileKind,
136 message: String,
137 },
138 #[error("{file} is not valid YAML: {message}")]
139 InvalidYaml {
140 file: ConfigFileKind,
141 message: String,
142 },
143 #[error(
144 "{file}: {key} uses a TOML date-time value, which codeint configuration does not support"
145 )]
146 UnsupportedTomlDatetime { file: ConfigFileKind, key: KeyPath },
147 #[error(
148 "{file} specifies conflicting schema URLs in {first_label} ({first_url:?}) and {second_label} ({second_url:?})"
149 )]
150 ConflictingSchemaDirectives {
151 file: ConfigFileKind,
152 first_label: &'static str,
153 first_url: String,
154 second_label: &'static str,
155 second_url: String,
156 },
157 #[error(
158 "{file} has an unknown key {key}; the keys allowed there are {}",
159 allowed.join(", ")
160 )]
161 UnknownKey {
162 file: ConfigFileKind,
163 key: KeyPath,
164 allowed: Vec<String>,
165 },
166 #[error(
167 "--budget {}.{metric} names an unknown Metric {metric:?}; the Metrics allowed are {}",
168 source_set.key(),
169 allowed.join(", ")
170 )]
171 UnknownCliBudgetMetric {
172 source_set: SourceSet,
173 metric: String,
174 allowed: Vec<String>,
175 },
176 #[error(
177 "{file}: {key} must be {}, not {}",
178 any_of(expected),
179 found.with_article()
180 )]
181 WrongType {
182 file: ConfigFileKind,
183 key: KeyPath,
184 expected: Vec<JsonType>,
185 found: JsonType,
186 },
187 #[error("{file}: {key} must be between {minimum} and {maximum}, not {found}")]
188 OutOfRange {
189 file: ConfigFileKind,
190 key: KeyPath,
191 minimum: f64,
192 maximum: f64,
193 found: f64,
194 },
195 #[error(
196 "{file}: {key} must be greater than {exclusive_minimum} and at most {maximum}, not {found}"
197 )]
198 OutOfExclusiveMinRange {
199 file: ConfigFileKind,
200 key: KeyPath,
201 exclusive_minimum: f64,
202 maximum: f64,
203 found: f64,
204 },
205 #[error(
206 "{file}: {key} must be one of {}, not {found}",
207 allowed.join(", ")
208 )]
209 NotOneOf {
210 file: ConfigFileKind,
211 key: KeyPath,
212 allowed: Vec<String>,
213 found: Box<Value>,
214 },
215 #[error("{file}: {key} is not a valid glob")]
216 InvalidGlob {
217 file: ConfigFileKind,
218 key: KeyPath,
219 #[source]
220 source: globset::Error,
221 },
222 #[error("{file}: {key} needs the key {missing}")]
223 MissingKey {
224 file: ConfigFileKind,
225 key: KeyPath,
226 missing: String,
227 },
228 #[error(
229 "{file} names an unknown Language plugin {name} at {key}; the Language plugins are {}",
230 known.join(", ")
231 )]
232 UnknownLanguagePlugin {
233 file: ConfigFileKind,
234 key: KeyPath,
235 name: String,
236 known: Vec<String>,
237 },
238 #[error("--source-set {}: {glob:?} is not a valid glob", source_set.key())]
239 InvalidCliGlob {
240 source_set: SourceSet,
241 glob: String,
242 #[source]
243 source: globset::Error,
244 },
245 #[error("{file}: {key} must be a 64-character hexadecimal SHA-256 digest, not {found:?}")]
246 InvalidSha256 {
247 file: ConfigFileKind,
248 key: KeyPath,
249 found: String,
250 },
251 #[error("{file}: {key} must not be empty")]
252 EmptyPluginField { file: ConfigFileKind, key: KeyPath },
253 #[error("{file}: {key} for Plugin {name:?} must set either path or url")]
254 MissingPluginSource {
255 file: ConfigFileKind,
256 key: KeyPath,
257 name: String,
258 },
259 #[error("{file}: {key} for Plugin {name:?} must set either path or url, not both")]
260 AmbiguousPluginSource {
261 file: ConfigFileKind,
262 key: KeyPath,
263 name: String,
264 },
265 #[error("{file}: {key} for Plugin {name:?} must use an HTTPS URL (https://), not {url:?}")]
266 NonHttpsPluginUrl {
267 file: ConfigFileKind,
268 key: KeyPath,
269 name: String,
270 url: String,
271 },
272 #[error(
273 "{file} targets codeint v{config_version} via $schema, which is newer than this binary (v{binary_version})"
274 )]
275 NewerSchemaVersion {
276 file: ConfigFileKind,
277 config_version: String,
278 binary_version: String,
279 },
280 #[error("{file}: {key} has invalid boundary zone name {name:?}")]
281 InvalidBoundaryZoneName {
282 file: ConfigFileKind,
283 key: KeyPath,
284 name: String,
285 },
286 #[error("{file}: {key} for boundary zone {zone:?} must list at least one glob pattern")]
287 EmptyBoundaryZonePatterns {
288 file: ConfigFileKind,
289 key: KeyPath,
290 zone: String,
291 },
292 #[error(
293 "{file}: {key} references unknown boundary zone {zone:?}; known zones are {}",
294 known.join(", ")
295 )]
296 UnknownBoundaryZone {
297 file: ConfigFileKind,
298 key: KeyPath,
299 zone: String,
300 known: Vec<String>,
301 },
302 #[error("{file}: {key} for boundary zone {from:?} must set either allow or deny, not both")]
303 ConflictingBoundaryRule {
304 file: ConfigFileKind,
305 key: KeyPath,
306 from: String,
307 },
308 #[error(
309 "{file}: {key} for boundary zone {from:?} must set either allow_external or deny_external, not both"
310 )]
311 ConflictingExternalBoundaryRule {
312 file: ConfigFileKind,
313 key: KeyPath,
314 from: String,
315 },
316 #[error(
317 "{file}: {key} for boundary zone {from:?} must set at least one of allow, deny, allow_external, or deny_external"
318 )]
319 MissingBoundaryRuleDirective {
320 file: ConfigFileKind,
321 key: KeyPath,
322 from: String,
323 },
324 #[error("{file}: {key} mixes allow and deny directives for boundary zone {from:?}")]
325 ConflictingBoundaryDirectives {
326 file: ConfigFileKind,
327 key: KeyPath,
328 from: String,
329 },
330 #[error(
331 "{file}: {key} mixes allow_external and deny_external directives for boundary zone {from:?}"
332 )]
333 ConflictingExternalBoundaryDirectives {
334 file: ConfigFileKind,
335 key: KeyPath,
336 from: String,
337 },
338 #[error("{file}: {key} must not be empty")]
339 EmptyBoundaryExternalPattern { file: ConfigFileKind, key: KeyPath },
340 #[error("{file}: {key} must not be empty")]
341 EmptyDependencyIgnore { file: ConfigFileKind, key: KeyPath },
342 #[error("{file}: {key} must not be empty")]
343 EmptyCoverageReportPath { file: ConfigFileKind, key: KeyPath },
344 #[error(
345 "{file}: {key} must be a path relative to the repository root, not an absolute path ({path:?})"
346 )]
347 AbsoluteCoverageReportPath {
348 file: ConfigFileKind,
349 key: KeyPath,
350 path: String,
351 },
352 #[error("{file}: {key} must stay inside the repository and must not contain \"..\" ({path:?})")]
353 ParentTraversalCoverageReportPath {
354 file: ConfigFileKind,
355 key: KeyPath,
356 path: String,
357 },
358 #[error("{file}: {key} is not supported; Test gap covers only the Production Source set")]
359 TestGapBudgetOutsideProduction { file: ConfigFileKind, key: KeyPath },
360 #[error(
361 "--budget {}.test_gap is not supported; Test gap covers only the Production Source set",
362 source_set.key()
363 )]
364 CliTestGapBudgetOutsideProduction { source_set: SourceSet },
365 #[error("{file}: {key} is not supported; Test gap has no Regression check")]
366 TestGapRegressionLimit { file: ConfigFileKind, key: KeyPath },
367 #[error(
368 "{file}: {key} is not supported; {} applies to the Production Source set only",
369 metric.display_name()
370 )]
371 MetricBudgetOutsideProduction {
372 file: ConfigFileKind,
373 key: KeyPath,
374 metric: Metric,
375 },
376 #[error(
377 "--budget {}.{} is not supported; {} applies to the Production Source set only",
378 source_set.key(),
379 metric.key(),
380 metric.display_name()
381 )]
382 CliMetricBudgetOutsideProduction {
383 source_set: SourceSet,
384 metric: Metric,
385 },
386 #[error(
387 "{file}: {key} needs file_size.max_source_lines; File size measures nothing without a limit"
388 )]
389 FileSizeGateWithoutLimit { file: ConfigFileKind, key: KeyPath },
390 #[error(
391 "--budget production.file_size needs file_size.max_source_lines; File size measures nothing without a limit"
392 )]
393 CliFileSizeBudgetWithoutLimit,
394 #[error(
395 "{file}: {key} is not supported; {} applies to the Production Source set only",
396 metric.display_name()
397 )]
398 MetricRegressionLimitOutsideProduction {
399 file: ConfigFileKind,
400 key: KeyPath,
401 metric: Metric,
402 },
403 #[error("{file}: {key} must name a non-empty Language plugin")]
404 EmptyDialectLanguage { file: ConfigFileKind, key: KeyPath },
405 #[error("{file}: {key} must not be empty")]
406 EmptyDialectName { file: ConfigFileKind, key: KeyPath },
407 #[error("{file}: {key} for {language} Dialect {dialect:?} must list at least one glob pattern")]
408 EmptyDialectInclude {
409 file: ConfigFileKind,
410 key: KeyPath,
411 language: String,
412 dialect: String,
413 },
414 #[error("{file}: {key} must not be empty")]
415 EmptyDialectPattern { file: ConfigFileKind, key: KeyPath },
416 #[error(
417 "{file}: {key} names an unknown Language plugin {language:?}; the known Language plugins are {}",
418 known.join(", ")
419 )]
420 UnknownDialectLanguage {
421 file: ConfigFileKind,
422 key: KeyPath,
423 language: String,
424 known: Vec<String>,
425 },
426 #[error("{}", format_unknown_dialect(*file, key, language, dialect, known))]
427 UnknownDialect {
428 file: ConfigFileKind,
429 key: KeyPath,
430 language: String,
431 dialect: String,
432 known: Vec<String>,
433 },
434 #[error("{file}: {key} must not be empty")]
435 EmptyHazardRuleName { file: ConfigFileKind, key: KeyPath },
436 #[error("{}", format_unknown_framework_profile(*file, key, name, known))]
437 UnknownFrameworkProfile {
438 file: ConfigFileKind,
439 key: KeyPath,
440 name: String,
441 known: Vec<String>,
442 },
443 #[error("{file}: {key} must not be empty")]
444 EmptyFrameworkProfileName { file: ConfigFileKind, key: KeyPath },
445 #[error("{file}: {key} must set either exclude or only, not both")]
446 ConflictingFrameworkProfileRule { file: ConfigFileKind, key: KeyPath },
447 #[error("{file}: {key} must set either exclude or only")]
448 EmptyFrameworkProfileObject { file: ConfigFileKind, key: KeyPath },
449 #[error("{file}: {key} has invalid Workspace package path {package:?}")]
450 InvalidPackageConfigKey {
451 file: ConfigFileKind,
452 key: KeyPath,
453 package: String,
454 },
455 #[error("{file}: {key} duplicates Workspace package path {package:?}")]
456 DuplicatePackageConfigKey {
457 file: ConfigFileKind,
458 key: KeyPath,
459 package: String,
460 },
461 #[error("{file}: {key} must not be empty")]
462 EmptyRatchetPath { file: ConfigFileKind, key: KeyPath },
463 #[error(
464 "{file}: {key} must be a path relative to the repository root, not an absolute path ({path:?})"
465 )]
466 AbsoluteRatchetPath {
467 file: ConfigFileKind,
468 key: KeyPath,
469 path: String,
470 },
471 #[error("{file}: {key} must stay inside the repository and must not contain \"..\" ({path:?})")]
472 ParentTraversalRatchetPath {
473 file: ConfigFileKind,
474 key: KeyPath,
475 path: String,
476 },
477}
478
479fn format_ambiguous_config_files(files: &[ConfigFileKind]) -> String {
480 let listed = files
481 .iter()
482 .map(|file| file.file_name())
483 .collect::<Vec<_>>()
484 .join(", ");
485 format!("multiple configuration files exist ({listed}); keep only one")
486}
487
488impl ConfigurationFileError {
489 pub(crate) fn with_file_kind(mut self, file_kind: ConfigFileKind) -> Self {
490 use ConfigurationFileError::*;
491 match &mut self {
492 Unreadable { file, .. }
493 | BrokenSymlink { file }
494 | NotJson { file, .. }
495 | InvalidJsonc { file, .. }
496 | InvalidToml { file, .. }
497 | InvalidYaml { file, .. }
498 | UnsupportedTomlDatetime { file, .. }
499 | ConflictingSchemaDirectives { file, .. }
500 | UnknownKey { file, .. }
501 | WrongType { file, .. }
502 | OutOfRange { file, .. }
503 | OutOfExclusiveMinRange { file, .. }
504 | NotOneOf { file, .. }
505 | MissingKey { file, .. }
506 | UnknownLanguagePlugin { file, .. }
507 | InvalidGlob { file, .. }
508 | InvalidSha256 { file, .. }
509 | EmptyPluginField { file, .. }
510 | MissingPluginSource { file, .. }
511 | AmbiguousPluginSource { file, .. }
512 | NonHttpsPluginUrl { file, .. }
513 | NewerSchemaVersion { file, .. }
514 | InvalidBoundaryZoneName { file, .. }
515 | EmptyBoundaryZonePatterns { file, .. }
516 | UnknownBoundaryZone { file, .. }
517 | ConflictingBoundaryRule { file, .. }
518 | ConflictingExternalBoundaryRule { file, .. }
519 | MissingBoundaryRuleDirective { file, .. }
520 | ConflictingBoundaryDirectives { file, .. }
521 | ConflictingExternalBoundaryDirectives { file, .. }
522 | EmptyBoundaryExternalPattern { file, .. }
523 | EmptyDependencyIgnore { file, .. }
524 | EmptyCoverageReportPath { file, .. }
525 | AbsoluteCoverageReportPath { file, .. }
526 | ParentTraversalCoverageReportPath { file, .. }
527 | TestGapBudgetOutsideProduction { file, .. }
528 | TestGapRegressionLimit { file, .. }
529 | MetricBudgetOutsideProduction { file, .. }
530 | MetricRegressionLimitOutsideProduction { file, .. }
531 | FileSizeGateWithoutLimit { file, .. }
532 | EmptyDialectLanguage { file, .. }
533 | EmptyDialectName { file, .. }
534 | EmptyDialectInclude { file, .. }
535 | EmptyDialectPattern { file, .. }
536 | UnknownDialectLanguage { file, .. }
537 | UnknownDialect { file, .. }
538 | EmptyHazardRuleName { file, .. }
539 | UnknownFrameworkProfile { file, .. }
540 | EmptyFrameworkProfileName { file, .. }
541 | ConflictingFrameworkProfileRule { file, .. }
542 | EmptyFrameworkProfileObject { file, .. }
543 | InvalidPackageConfigKey { file, .. }
544 | DuplicatePackageConfigKey { file, .. }
545 | EmptyRatchetPath { file, .. }
546 | AbsoluteRatchetPath { file, .. }
547 | ParentTraversalRatchetPath { file, .. } => *file = file_kind,
548 AmbiguousConfigFiles { .. }
549 | UnknownCliBudgetMetric { .. }
550 | CliTestGapBudgetOutsideProduction { .. }
551 | CliMetricBudgetOutsideProduction { .. }
552 | CliFileSizeBudgetWithoutLimit
553 | InvalidCliGlob { .. } => {}
554 }
555 self
556 }
557}
558
559pub(crate) fn is_absolute_repo_path(path: &str) -> bool {
560 if std::path::Path::new(path).is_absolute() || path.starts_with('/') || path.starts_with('\\') {
561 return true;
562 }
563 let bytes = path.as_bytes();
564 bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':'
565}
566
567pub(crate) fn contains_parent_traversal(path: &str) -> bool {
568 path.split(['/', '\\']).any(|segment| segment == "..")
569}
570
571pub(crate) fn compile_glob(glob: &str) -> Result<Glob, globset::Error> {
572 GlobBuilder::new(glob)
573 .literal_separator(true)
574 .backslash_escape(true)
575 .build()
576}
577
578pub(crate) fn glob_set(key: &KeyPath, globs: &[String]) -> Result<GlobSet, ConfigurationFileError> {
579 let mut builder = GlobSetBuilder::new();
580 for (index, glob) in globs.iter().enumerate() {
581 let compiled =
582 compile_glob(glob).map_err(|source| ConfigurationFileError::InvalidGlob {
583 file: ConfigFileKind::Json,
584 key: key.child(KeySegment::Index(index)),
585 source,
586 })?;
587 builder.add(compiled);
588 }
589 builder
590 .build()
591 .map_err(|source| ConfigurationFileError::InvalidGlob {
592 file: ConfigFileKind::Json,
593 key: key.clone(),
594 source,
595 })
596}
597
598impl KeyPath {
599 pub(crate) fn nested(parent: &str, child: &str) -> KeyPath {
600 KeyPath(vec![
601 KeySegment::Key(parent.to_owned()),
602 KeySegment::Key(child.to_owned()),
603 ])
604 }
605
606 pub(crate) fn child(&self, segment: KeySegment) -> KeyPath {
607 let mut segments = self.0.clone();
608 segments.push(segment);
609 KeyPath(segments)
610 }
611
612 pub fn first_key(&self) -> Option<&str> {
613 match self.0.first() {
614 Some(KeySegment::Key(key)) => Some(key.as_str()),
615 _ => None,
616 }
617 }
618}
619
620impl fmt::Display for KeyPath {
621 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
622 for (position, segment) in self.0.iter().enumerate() {
623 match segment {
624 KeySegment::Key(key) if position == 0 => write!(formatter, "{key}")?,
625 KeySegment::Key(key) => write!(formatter, ".{key}")?,
626 KeySegment::Index(index) => write!(formatter, "[{index}]")?,
627 }
628 }
629 Ok(())
630 }
631}
632
633impl JsonType {
634 pub(crate) fn of(value: &Value) -> JsonType {
635 match value {
636 Value::Object(_) => JsonType::Object,
637 Value::Array(_) => JsonType::Array,
638 Value::String(_) => JsonType::String,
639 Value::Number(number) if number.is_i64() || number.is_u64() => JsonType::Integer,
640 Value::Number(_) => JsonType::Number,
641 Value::Bool(_) => JsonType::Boolean,
642 Value::Null => JsonType::Null,
643 }
644 }
645
646 pub(crate) fn from_schema_name(name: &str) -> Option<JsonType> {
647 match name {
648 "object" => Some(JsonType::Object),
649 "array" => Some(JsonType::Array),
650 "string" => Some(JsonType::String),
651 "number" => Some(JsonType::Number),
652 "integer" => Some(JsonType::Integer),
653 "boolean" => Some(JsonType::Boolean),
654 "null" => Some(JsonType::Null),
655 _ => None,
656 }
657 }
658
659 pub(crate) fn accepts(self, value: &Value) -> bool {
660 let found = JsonType::of(value);
661 found == self || (self == JsonType::Number && found == JsonType::Integer)
662 }
663
664 pub(crate) fn with_article(self) -> &'static str {
665 match self {
666 JsonType::Object => "an object",
667 JsonType::Array => "an array",
668 JsonType::String => "a string",
669 JsonType::Number => "a number",
670 JsonType::Integer => "an integer",
671 JsonType::Boolean => "a boolean",
672 JsonType::Null => "null",
673 }
674 }
675}
676
677fn any_of(types: &[JsonType]) -> String {
678 types
679 .iter()
680 .map(|json_type| json_type.with_article())
681 .collect::<Vec<_>>()
682 .join(" or ")
683}
684
685fn format_unknown_framework_profile(
686 file: ConfigFileKind,
687 key: &KeyPath,
688 name: &str,
689 known: &[String],
690) -> String {
691 if known.is_empty() {
692 format!(
693 "{file} names an unknown Framework profile {name:?} at {key}; no loaded Language plugin defines Framework profiles"
694 )
695 } else {
696 format!(
697 "{file} names an unknown Framework profile {name:?} at {key}; the known Framework profiles are {}",
698 known.join(", ")
699 )
700 }
701}
702
703fn format_unknown_dialect(
704 file: ConfigFileKind,
705 key: &KeyPath,
706 language: &str,
707 dialect: &str,
708 known: &[String],
709) -> String {
710 if known.is_empty() {
711 format!(
712 "{file} names an unknown Dialect {dialect:?} for {language:?} at {key}; Language plugin {language:?} defines no selectable Dialects"
713 )
714 } else {
715 format!(
716 "{file} names an unknown Dialect {dialect:?} for {language:?} at {key}; the known Dialects are {}",
717 known.join(", ")
718 )
719 }
720}