diff options
Diffstat (limited to 'xtask/src/tidy.rs')
-rw-r--r-- | xtask/src/tidy.rs | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index 9447d463d..f2ba8efef 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | use std::path::{Path, PathBuf}; | 1 | use std::{ |
2 | collections::HashSet, | ||
3 | path::{Path, PathBuf}, | ||
4 | }; | ||
2 | 5 | ||
3 | use xshell::{cmd, pushd, pushenv, read_file}; | 6 | use xshell::{cmd, pushd, pushenv, read_file}; |
4 | 7 | ||
@@ -81,6 +84,7 @@ Please adjust docs/dev/lsp-extensions.md. | |||
81 | #[test] | 84 | #[test] |
82 | fn rust_files_are_tidy() { | 85 | fn rust_files_are_tidy() { |
83 | let mut tidy_docs = TidyDocs::default(); | 86 | let mut tidy_docs = TidyDocs::default(); |
87 | let mut tidy_marks = TidyMarks::default(); | ||
84 | for path in rust_files() { | 88 | for path in rust_files() { |
85 | let text = read_file(&path).unwrap(); | 89 | let text = read_file(&path).unwrap(); |
86 | check_todo(&path, &text); | 90 | check_todo(&path, &text); |
@@ -88,8 +92,10 @@ fn rust_files_are_tidy() { | |||
88 | check_trailing_ws(&path, &text); | 92 | check_trailing_ws(&path, &text); |
89 | deny_clippy(&path, &text); | 93 | deny_clippy(&path, &text); |
90 | tidy_docs.visit(&path, &text); | 94 | tidy_docs.visit(&path, &text); |
95 | tidy_marks.visit(&path, &text); | ||
91 | } | 96 | } |
92 | tidy_docs.finish(); | 97 | tidy_docs.finish(); |
98 | tidy_marks.finish(); | ||
93 | } | 99 | } |
94 | 100 | ||
95 | #[test] | 101 | #[test] |
@@ -366,7 +372,10 @@ impl TidyDocs { | |||
366 | self.contains_fixme.push(path.to_path_buf()); | 372 | self.contains_fixme.push(path.to_path_buf()); |
367 | } | 373 | } |
368 | } else { | 374 | } else { |
369 | if text.contains("// Feature:") || text.contains("// Assist:") { | 375 | if text.contains("// Feature:") |
376 | || text.contains("// Assist:") | ||
377 | || text.contains("// Diagnostic:") | ||
378 | { | ||
370 | return; | 379 | return; |
371 | } | 380 | } |
372 | self.missing_docs.push(path.display().to_string()); | 381 | self.missing_docs.push(path.display().to_string()); |
@@ -408,6 +417,39 @@ fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool { | |||
408 | .any(|it| dirs_to_exclude.contains(&it)) | 417 | .any(|it| dirs_to_exclude.contains(&it)) |
409 | } | 418 | } |
410 | 419 | ||
420 | #[derive(Default)] | ||
421 | struct TidyMarks { | ||
422 | hits: HashSet<String>, | ||
423 | checks: HashSet<String>, | ||
424 | } | ||
425 | |||
426 | impl TidyMarks { | ||
427 | fn visit(&mut self, _path: &Path, text: &str) { | ||
428 | for line in text.lines() { | ||
429 | if let Some(mark) = find_mark(line, "hit") { | ||
430 | self.hits.insert(mark.to_string()); | ||
431 | } | ||
432 | if let Some(mark) = find_mark(line, "check") { | ||
433 | self.checks.insert(mark.to_string()); | ||
434 | } | ||
435 | if let Some(mark) = find_mark(line, "check_count") { | ||
436 | self.checks.insert(mark.to_string()); | ||
437 | } | ||
438 | } | ||
439 | } | ||
440 | |||
441 | fn finish(self) { | ||
442 | assert!(!self.hits.is_empty()); | ||
443 | |||
444 | let diff: Vec<_> = | ||
445 | self.hits.symmetric_difference(&self.checks).map(|it| it.as_str()).collect(); | ||
446 | |||
447 | if !diff.is_empty() { | ||
448 | panic!("unpaired marks: {:?}", diff) | ||
449 | } | ||
450 | } | ||
451 | } | ||
452 | |||
411 | #[allow(deprecated)] | 453 | #[allow(deprecated)] |
412 | fn stable_hash(text: &str) -> u64 { | 454 | fn stable_hash(text: &str) -> u64 { |
413 | use std::hash::{Hash, Hasher, SipHasher}; | 455 | use std::hash::{Hash, Hasher, SipHasher}; |
@@ -417,3 +459,11 @@ fn stable_hash(text: &str) -> u64 { | |||
417 | text.hash(&mut hasher); | 459 | text.hash(&mut hasher); |
418 | hasher.finish() | 460 | hasher.finish() |
419 | } | 461 | } |
462 | |||
463 | fn find_mark<'a>(text: &'a str, mark: &'static str) -> Option<&'a str> { | ||
464 | let idx = text.find(mark)?; | ||
465 | let text = text[idx + mark.len()..].strip_prefix("!(")?; | ||
466 | let idx = text.find(|c: char| !(c.is_alphanumeric() || c == '_'))?; | ||
467 | let text = &text[..idx]; | ||
468 | Some(text) | ||
469 | } | ||