Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit 48efead

Browse files
committed
update formatter to report each missing string as a separate error
1 parent a1e2c50 commit 48efead

1 file changed

Lines changed: 43 additions & 31 deletions

File tree

core/src/validate/formatter.rs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,23 @@ fn format_errors_from_one_file(
9292
}
9393

9494
if let Some(missing_strings) = invalid_strings_file.missing_strings_error {
95-
if !missing_strings.extra_in_default_locale.is_empty() {
95+
for extra in missing_strings.extra_in_default_locale {
9696
issues_count_in_file += 1;
9797
writeln!(
9898
&mut file_output,
99-
"Error {} (unlocalized string(s)): {}",
99+
"Error {} (unlocalized string): {}",
100100
issues_count_in_file,
101-
missing_strings
102-
.extra_in_default_locale
103-
.iter()
104-
.map(|s| s.value())
105-
.collect::<Vec<&str>>()
106-
.join(", ")
101+
extra.value()
107102
)?;
108103
}
109104

110-
if !missing_strings.extra_in_foreign_locale.is_empty() {
105+
for extra in missing_strings.extra_in_foreign_locale {
111106
issues_count_in_file += 1;
112107
writeln!(
113108
&mut file_output,
114-
"Error {} (string(s) not in defaut locale): {}",
109+
"Error {} (string not in defaut locale): {}",
115110
issues_count_in_file,
116-
missing_strings
117-
.extra_in_foreign_locale
118-
.iter()
119-
.map(|s| s.value())
120-
.collect::<Vec<&str>>()
121-
.join(", ")
111+
extra.value()
122112
)?;
123113
}
124114
}
@@ -149,6 +139,8 @@ mod tests {
149139

150140
#[test]
151141
fn formats() {
142+
// These strings needn't be invalid. We can include them in the
143+
// error & the formatter will happily report it
152144
let default_s1 = AndroidString::localizable("s1", "default_value1");
153145
let default_s2 = AndroidString::localizable("s2", "default_value2");
154146
let french_s1 = AndroidString::localizable("s1", "french_value1");
@@ -184,19 +176,34 @@ mod tests {
184176
InvalidStringsFile {
185177
file_path: String::from("spanish"),
186178
apostrophe_error: Some(apostrophe::InvalidStrings {
187-
invalid_strings: vec![spanish_s1.clone()],
179+
invalid_strings: vec![spanish_s1.clone(), spanish_s2.clone()],
188180
}),
189181
format_string_error: Some(format_string::Mismatches {
190-
mismatches: vec![format_string::Mismatch {
191-
default_parsed_data: format_string::ParsedData {
192-
android_string: default_s1.clone(),
193-
sorted_format_strings: vec![String::from("%1$s"), String::from("%1$d")],
182+
mismatches: vec![
183+
format_string::Mismatch {
184+
default_parsed_data: format_string::ParsedData {
185+
android_string: default_s1.clone(),
186+
sorted_format_strings: vec![
187+
String::from("%1$s"),
188+
String::from("%1$d"),
189+
],
190+
},
191+
foreign_parsed_data: format_string::ParsedData {
192+
android_string: spanish_s1.clone(),
193+
sorted_format_strings: vec![String::from("%1$d")],
194+
},
194195
},
195-
foreign_parsed_data: format_string::ParsedData {
196-
android_string: spanish_s1.clone(),
197-
sorted_format_strings: vec![String::from("%1$d")],
196+
format_string::Mismatch {
197+
default_parsed_data: format_string::ParsedData {
198+
android_string: default_s2.clone(),
199+
sorted_format_strings: vec![],
200+
},
201+
foreign_parsed_data: format_string::ParsedData {
202+
android_string: spanish_s2.clone(),
203+
sorted_format_strings: vec![String::from("%1$s")],
204+
},
198205
},
199-
}],
206+
],
200207
}),
201208
missing_strings_error: Some(missing_strings::MissingStrings {
202209
extra_in_default_locale: vec![default_s1, default_s2],
@@ -215,14 +222,19 @@ Path: french (1 issue)
215222
Error 1 (mismatched format string(s)): Found [asdf, qwer] in french_value1
216223
Found [] in default_value1
217224
218-
Path: spanish (4 issues)
225+
Path: spanish (8 issues)
219226
Error 1 (unescaped apostrophe): spanish_value1
220-
Error 2 (mismatched format string(s)): Found [%1$d] in spanish_value1
227+
Error 2 (unescaped apostrophe): spanish_value2
228+
Error 3 (mismatched format string(s)): Found [%1$d] in spanish_value1
221229
Found [%1$s, %1$d] in default_value1
222-
Error 3 (unlocalized string(s)): default_value1, default_value2
223-
Error 4 (string(s) not in defaut locale): spanish_value1, spanish_value2
224-
225-
Found 6 issues across 3 files!"#
230+
Error 4 (mismatched format string(s)): Found [%1$s] in spanish_value2
231+
Found [] in default_value2
232+
Error 5 (unlocalized string): default_value1
233+
Error 6 (unlocalized string): default_value2
234+
Error 7 (string not in defaut locale): spanish_value1
235+
Error 8 (string not in defaut locale): spanish_value2
236+
237+
Found 10 issues across 3 files!"#
226238
)
227239
);
228240
}

0 commit comments

Comments
 (0)