1
0
Fork 0
mirror of https://github.com/rust-unofficial/awesome-rust.git synced 2024-11-13 11:34:18 -05:00

Sort the README and enforce it with the checker

This commit is contained in:
Tom Parker-Shemilt 2021-07-25 20:44:10 +01:00
parent a955a09942
commit 0491e2ce2d
4 changed files with 407 additions and 321 deletions

19
Cargo.lock generated
View file

@ -24,6 +24,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -53,6 +62,7 @@ version = "0.1.0"
dependencies = [
"chrono",
"chrono-humanize",
"diffy",
"env_logger",
"failure",
"futures",
@ -189,6 +199,15 @@ dependencies = [
"syn",
]
[[package]]
name = "diffy"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c1ff48e3f358d3158f88b2c95071f28d136be31d89e5fa843095032a70bff56"
dependencies = [
"ansi_term",
]
[[package]]
name = "dtoa"
version = "0.4.8"

View file

@ -22,4 +22,5 @@ log = "0.4"
regex = "1"
scraper = "0.11"
chrono = { version = "0.4", features = ["serde"] }
chrono-humanize = "0.2"
chrono-humanize = "0.2"
diffy = "0.2"

638
README.md

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,7 @@ use chrono::{Local, DateTime, Duration};
use std::env;
use tokio::sync::Semaphore;
use tokio::sync::SemaphorePermit;
use diffy::create_patch;
#[derive(Debug, Fail, Serialize, Deserialize)]
enum CheckerError {
@ -27,7 +28,7 @@ enum CheckerError {
},
#[fail(display = "too many requests")]
TooManyRequests,
TooManyRequests,
#[fail(display = "reqwest error: {}", error)]
ReqwestError {
@ -295,13 +296,76 @@ async fn main() -> Result<(), Error> {
let mut to_check: Vec<String> = vec![];
for (event, _range) in parser.into_offset_iter() {
#[derive(Debug)]
struct ListInfo {
location: usize,
data: Vec<String>
}
let mut list_items: Vec<ListInfo> = Vec::new();
let mut in_list_item = false;
let mut list_item: String = String::new();
for (event, range) in parser.into_offset_iter() {
match event {
Event::Start(tag) => {
match tag {
Tag::Link(_link_type, url, _title) | Tag::Image(_link_type, url, _title) => {
to_check.push(url.to_string());
}
Tag::List(_) => {
if in_list_item && list_item.len() > 0 {
list_items.last_mut().unwrap().data.push(list_item.clone());
in_list_item = false;
}
list_items.push(ListInfo {location: range.start, data: Vec::new()});
}
Tag::Item => {
if in_list_item && list_item.len() > 0 {
list_items.last_mut().unwrap().data.push(list_item.clone());
}
in_list_item = true;
list_item = String::new();
}
Tag::Heading(_) => {}
Tag::Paragraph => {}
_ => {
if in_list_item {
in_list_item = false;
}
}
}
}
Event::Text(text) => {
if in_list_item {
list_item.push_str(&text);
}
}
Event::End(tag) => {
match tag {
Tag::Item => {
if list_item.len() > 0 {
list_items.last_mut().unwrap().data.push(list_item.clone());
list_item = String::new();
}
in_list_item = false
}
Tag::List(_) => {
let list_info = list_items.pop().unwrap();
if list_info.data.iter().find(|s| *s == "License").is_some() && list_info.data.iter().find(|s| *s == "Resources").is_some() {
// Ignore wrong ordering in top-level list
continue
}
let mut sorted_recent_list = list_info.data.to_vec();
sorted_recent_list.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()));
let joined_recent = list_info.data.join("\n");
let joined_sorted = sorted_recent_list.join("\n");
let patch = create_patch(&joined_recent, &joined_sorted);
if patch.hunks().len() > 0 {
println!("{}", patch);
return Err(format_err!("Sorting error"));
}
}
_ => {}
}
}