address review comment

https://github.com/rust-lang/rustc-dev-guide/pull/1394#discussion_r934018268

This led to a more robust regex, though making the tool more picky.
It also found a wrong date format that was missed.
This commit is contained in:
Tshepang Mbambo 2022-07-31 22:00:27 +02:00
parent df6b80508d
commit 3faf82c00e
3 changed files with 20 additions and 5 deletions

View File

@ -38,8 +38,8 @@ impl fmt::Display for Date {
fn make_date_regex() -> Vec<Regex> {
let patterns = [
r"<!--\s+date-check:\s+(\w+)\s+(\d+{4})\s+-->",
r"<!--\s+date-check\s+-->\s+(\w+)\s+(\d+{4})",
r"<!--\s+date-check:\s+(\D+)\s+(\d{4})\s+-->",
r"<!--\s+date-check\s+-->\s+(\D+)\s+(\d{4})\b",
];
let set = RegexSet::new(&patterns).unwrap();
set.patterns()
@ -198,6 +198,20 @@ mod tests {
assert!(regexes[1].is_match("<!-- date-check --> january 2021"));
assert!(regexes[1].is_match("<!-- date-check --> Jan 2021"));
assert!(regexes[1].is_match("<!-- date-check --> January 2021"));
assert!(regexes[1].is_match("<!-- date-check --> jan 2021 "));
assert!(regexes[1].is_match("<!-- date-check --> jan 2021."));
}
#[test]
fn test_date_regex_fail() {
let regexes = &make_date_regex();
assert!(!regexes[0].is_match("<!-- date-check: jan 221 -->"));
assert!(!regexes[0].is_match("<!-- date-check: jan 20221 -->"));
assert!(!regexes[0].is_match("<!-- date-check: 01 2021 -->"));
assert!(!regexes[1].is_match("<!-- date-check --> jan 221"));
assert!(!regexes[1].is_match("<!-- date-check --> jan 20222"));
assert!(!regexes[1].is_match("<!-- date-check --> 01 2021"));
}
#[test]

View File

@ -22,7 +22,7 @@ You can also install the hook as a step of running `./x.py setup`!
a file. By default, `rust-analyzer` runs the `cargo check` and `rustfmt`
commands, but you can override these commands to use more adapted versions
of these tools when hacking on `rustc`. For example, for Visual Studio Code,
you can write: <!-- date: 2022-04 --><!-- the date comment is for the edition below -->
you can write: <!-- date-check: apr 2022 --><!-- the date comment is for the edition below -->
```JSON
{

View File

@ -447,9 +447,10 @@ Just a few things to keep in mind:
There is a CI action (in "~/.github/workflows/date-check.yml")
that generates a monthly issue with any of these that are over 6 months old.
For the action to pick the date, add this annotation:
For the action to pick the date,
add a special annotation before specifying the date:
<!-- date-check -->
<!-- date-check --> Jul 2022
Example: