Skip to content

feat: Sort (markdown) output by file path #1619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mahlzahn opened this issue Jan 30, 2025 · 1 comment
Open

feat: Sort (markdown) output by file path #1619

mahlzahn opened this issue Jan 30, 2025 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mahlzahn
Copy link

mahlzahn commented Jan 30, 2025

Currently, each run of lychee sorts the files where broken links are found in another kind of random order. That makes it difficult to compare different outputs.

I suggest to let lychee by default sort the headings of the output.

(A workaround is to do it manually afterwards, but it would be nice to have it inside lychee)

@mre mre added enhancement New feature or request good first issue Good for newcomers labels Feb 3, 2025
@mre
Copy link
Member

mre commented Feb 3, 2025

Good idea.

The content is in a data structure called error_map, which is not sorted (beause it's a HashMap).
We iterate over the error_map in multiple places, dependening on the output format:

if !&map.is_empty() {
writeln!(f, "\n## {name} per input")?;
for (source, responses) in map {
writeln!(f, "\n### {name} in {source}\n")?;
for response in responses {
writeln!(f, "{}", write_stat(response)?)?;
}
}
}

for (source, responses) in &stats.error_map {
color!(f, BOLD_YELLOW, "[{}]:\n", source)?;
for response in responses {
writeln!(
f,
"{}",
response_formatter.format_detailed_response(response)
)?;
}

for (source, responses) in &stats.error_map {
// Using leading newlines over trailing ones (e.g. `writeln!`)
// lets us avoid extra newlines without any additional logic.
write!(f, "\n\nErrors in {source}")?;
for response in responses {
write!(
f,
"\n{}",
response_formatter.format_detailed_response(response)
)?;
if let Some(suggestions) = &stats.suggestion_map.get(source) {
writeln!(f, "\nSuggestions in {source}")?;
for suggestion in *suggestions {
writeln!(f, "{suggestion}")?;
}
}
}
}
Ok(())
}

The proper way to change this would be to return the error_map sorted by key. We could add a helper method, e.g. sorted_error_map to the stats and use that in the above places instead of directly iterating over error_map.

I'd be thankful for a pull request if anyone wants to tackle this. Should be pretty straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants