2021-06-13 04:33:08 -05:00
|
|
|
use std::{
|
|
|
|
collections::HashSet,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
2020-03-17 04:26:29 -05:00
|
|
|
|
2022-07-22 19:06:11 -05:00
|
|
|
use xshell::Shell;
|
2021-03-01 11:16:23 -06:00
|
|
|
|
2022-07-22 19:06:11 -05:00
|
|
|
#[cfg(not(feature = "in-rust-tree"))]
|
|
|
|
use xshell::cmd;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "in-rust-tree"))]
|
2020-05-06 03:25:25 -05:00
|
|
|
#[test]
|
|
|
|
fn check_code_formatting() {
|
2022-03-13 16:20:51 -05:00
|
|
|
let sh = &Shell::new().unwrap();
|
|
|
|
sh.change_dir(sourcegen::project_root());
|
2021-07-03 14:11:03 -05:00
|
|
|
|
2022-08-06 09:12:13 -05:00
|
|
|
let out = cmd!(sh, "rustup run stable rustfmt --version").read().unwrap();
|
2021-07-03 14:11:03 -05:00
|
|
|
if !out.contains("stable") {
|
|
|
|
panic!(
|
|
|
|
"Failed to run rustfmt from toolchain 'stable'. \
|
|
|
|
Please run `rustup component add rustfmt --toolchain stable` to install it.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-06 09:12:13 -05:00
|
|
|
let res = cmd!(sh, "rustup run stable cargo fmt -- --check").run();
|
2021-06-03 05:46:56 -05:00
|
|
|
if res.is_err() {
|
2022-08-06 09:12:13 -05:00
|
|
|
let _ = cmd!(sh, "rustup run stable cargo fmt").run();
|
2021-03-08 12:39:09 -06:00
|
|
|
}
|
|
|
|
res.unwrap()
|
2020-05-06 03:25:25 -05:00
|
|
|
}
|
2020-03-17 04:26:29 -05:00
|
|
|
|
2020-10-14 06:30:06 -05:00
|
|
|
#[test]
|
|
|
|
fn check_lsp_extensions_docs() {
|
2022-03-13 16:20:51 -05:00
|
|
|
let sh = &Shell::new().unwrap();
|
|
|
|
|
2020-10-14 06:30:06 -05:00
|
|
|
let expected_hash = {
|
2022-03-13 16:20:51 -05:00
|
|
|
let lsp_ext_rs = sh
|
|
|
|
.read_file(sourcegen::project_root().join("crates/rust-analyzer/src/lsp_ext.rs"))
|
|
|
|
.unwrap();
|
2020-10-14 06:30:06 -05:00
|
|
|
stable_hash(lsp_ext_rs.as_str())
|
|
|
|
};
|
|
|
|
|
|
|
|
let actual_hash = {
|
|
|
|
let lsp_extensions_md =
|
2022-03-13 16:20:51 -05:00
|
|
|
sh.read_file(sourcegen::project_root().join("docs/dev/lsp-extensions.md")).unwrap();
|
2020-10-14 06:30:06 -05:00
|
|
|
let text = lsp_extensions_md
|
|
|
|
.lines()
|
|
|
|
.find_map(|line| line.strip_prefix("lsp_ext.rs hash:"))
|
|
|
|
.unwrap()
|
|
|
|
.trim();
|
|
|
|
u64::from_str_radix(text, 16).unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
if actual_hash != expected_hash {
|
|
|
|
panic!(
|
|
|
|
"
|
|
|
|
lsp_ext.rs was changed without touching lsp-extensions.md.
|
|
|
|
|
2022-12-30 01:59:11 -06:00
|
|
|
Expected hash: {expected_hash:x}
|
|
|
|
Actual hash: {actual_hash:x}
|
2020-10-14 06:30:06 -05:00
|
|
|
|
|
|
|
Please adjust docs/dev/lsp-extensions.md.
|
2022-12-30 01:59:11 -06:00
|
|
|
"
|
2020-10-14 06:30:06 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:26:29 -05:00
|
|
|
#[test]
|
2021-07-04 04:42:35 -05:00
|
|
|
fn files_are_tidy() {
|
2022-03-13 16:20:51 -05:00
|
|
|
let sh = &Shell::new().unwrap();
|
|
|
|
|
2021-07-04 04:42:35 -05:00
|
|
|
let files = sourcegen::list_files(&sourcegen::project_root().join("crates"));
|
|
|
|
|
2020-03-17 04:26:29 -05:00
|
|
|
let mut tidy_docs = TidyDocs::default();
|
2021-06-13 04:33:08 -05:00
|
|
|
let mut tidy_marks = TidyMarks::default();
|
2021-07-04 04:42:35 -05:00
|
|
|
for path in files {
|
|
|
|
let extension = path.extension().unwrap_or_default().to_str().unwrap_or_default();
|
|
|
|
match extension {
|
|
|
|
"rs" => {
|
2022-03-13 16:20:51 -05:00
|
|
|
let text = sh.read_file(&path).unwrap();
|
2021-07-04 04:42:35 -05:00
|
|
|
check_todo(&path, &text);
|
|
|
|
check_dbg(&path, &text);
|
|
|
|
check_test_attrs(&path, &text);
|
|
|
|
check_trailing_ws(&path, &text);
|
|
|
|
deny_clippy(&path, &text);
|
|
|
|
tidy_docs.visit(&path, &text);
|
|
|
|
tidy_marks.visit(&path, &text);
|
|
|
|
}
|
|
|
|
"toml" => {
|
2022-03-13 16:20:51 -05:00
|
|
|
let text = sh.read_file(&path).unwrap();
|
2021-07-04 04:42:35 -05:00
|
|
|
check_cargo_toml(&path, text);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
2020-03-17 04:26:29 -05:00
|
|
|
}
|
2021-07-04 04:42:35 -05:00
|
|
|
|
2020-03-17 04:26:29 -05:00
|
|
|
tidy_docs.finish();
|
2021-06-13 04:33:08 -05:00
|
|
|
tidy_marks.finish();
|
2020-03-17 04:26:29 -05:00
|
|
|
}
|
|
|
|
|
2021-10-16 06:32:55 -05:00
|
|
|
fn check_cargo_toml(path: &Path, text: String) {
|
2021-07-04 04:42:35 -05:00
|
|
|
let mut section = None;
|
|
|
|
for (line_no, text) in text.lines().enumerate() {
|
|
|
|
let text = text.trim();
|
|
|
|
if text.starts_with('[') {
|
|
|
|
if !text.ends_with(']') {
|
|
|
|
panic!(
|
|
|
|
"\nplease don't add comments or trailing whitespace in section lines.\n\
|
|
|
|
{}:{}\n",
|
|
|
|
path.display(),
|
|
|
|
line_no + 1
|
|
|
|
)
|
|
|
|
}
|
|
|
|
section = Some(text);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let text: String = text.split_whitespace().collect();
|
|
|
|
if !text.contains("path=") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
match section {
|
|
|
|
Some(s) if s.contains("dev-dependencies") => {
|
|
|
|
if text.contains("version") {
|
2021-03-01 13:13:16 -06:00
|
|
|
panic!(
|
2021-07-04 04:42:35 -05:00
|
|
|
"\ncargo internal dev-dependencies should not have a version.\n\
|
|
|
|
{}:{}\n",
|
|
|
|
path.display(),
|
2021-03-01 13:13:16 -06:00
|
|
|
line_no + 1
|
2021-07-04 04:42:35 -05:00
|
|
|
);
|
2021-03-01 13:13:16 -06:00
|
|
|
}
|
2021-02-03 08:01:09 -06:00
|
|
|
}
|
2021-07-04 04:42:35 -05:00
|
|
|
Some(s) if s.contains("dependencies") => {
|
|
|
|
if !text.contains("version") {
|
|
|
|
panic!(
|
|
|
|
"\ncargo internal dependencies should have a version.\n\
|
|
|
|
{}:{}\n",
|
|
|
|
path.display(),
|
|
|
|
line_no + 1
|
|
|
|
);
|
2021-03-01 13:13:16 -06:00
|
|
|
}
|
2021-02-03 08:01:09 -06:00
|
|
|
}
|
2021-07-04 04:42:35 -05:00
|
|
|
_ => {}
|
2021-02-03 08:01:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 09:33:18 -05:00
|
|
|
fn deny_clippy(path: &Path, text: &str) {
|
2020-10-20 14:29:31 -05:00
|
|
|
let ignore = &[
|
|
|
|
// The documentation in string literals may contain anything for its own purposes
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-db/src/generated/lints.rs",
|
2021-06-04 12:18:45 -05:00
|
|
|
// The tests test clippy lint hovers
|
2021-09-23 12:54:57 -05:00
|
|
|
"ide/src/hover/tests.rs",
|
2021-10-17 05:58:37 -05:00
|
|
|
// The tests test clippy lint completions
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-completion/src/tests/attribute.rs",
|
2020-10-20 14:29:31 -05:00
|
|
|
];
|
|
|
|
if ignore.iter().any(|p| path.ends_with(p)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-31 16:58:04 -06:00
|
|
|
if text.contains("\u{61}llow(clippy") {
|
2020-08-12 05:45:38 -05:00
|
|
|
panic!(
|
|
|
|
"\n\nallowing lints is forbidden: {}.
|
|
|
|
rust-analyzer intentionally doesn't check clippy on CI.
|
|
|
|
You can allow lint globally via `xtask clippy`.
|
2020-08-12 06:03:43 -05:00
|
|
|
See https://github.com/rust-lang/rust-clippy/issues/5537 for discussion.
|
2020-08-12 05:45:38 -05:00
|
|
|
|
|
|
|
",
|
|
|
|
path.display()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 19:06:11 -05:00
|
|
|
#[cfg(not(feature = "in-rust-tree"))]
|
2020-07-14 10:14:00 -05:00
|
|
|
#[test]
|
|
|
|
fn check_licenses() {
|
2022-03-13 16:20:51 -05:00
|
|
|
let sh = &Shell::new().unwrap();
|
|
|
|
|
2020-07-14 10:14:00 -05:00
|
|
|
let expected = "
|
2022-10-15 06:07:21 -05:00
|
|
|
(MIT OR Apache-2.0) AND Unicode-DFS-2016
|
2020-07-14 10:14:00 -05:00
|
|
|
0BSD OR MIT OR Apache-2.0
|
2020-07-31 19:55:04 -05:00
|
|
|
Apache-2.0
|
2020-07-14 10:14:00 -05:00
|
|
|
Apache-2.0 OR BSL-1.0
|
|
|
|
Apache-2.0 OR MIT
|
2022-03-17 12:10:45 -05:00
|
|
|
Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT
|
2020-07-14 10:14:00 -05:00
|
|
|
Apache-2.0/MIT
|
|
|
|
BSD-3-Clause
|
2022-06-10 09:30:09 -05:00
|
|
|
BlueOak-1.0.0 OR MIT OR Apache-2.0
|
2021-04-15 11:15:23 -05:00
|
|
|
CC0-1.0 OR Artistic-2.0
|
2020-07-14 10:14:00 -05:00
|
|
|
ISC
|
|
|
|
MIT
|
|
|
|
MIT / Apache-2.0
|
|
|
|
MIT OR Apache-2.0
|
2020-11-17 08:39:25 -06:00
|
|
|
MIT OR Apache-2.0 OR Zlib
|
2020-10-08 08:43:00 -05:00
|
|
|
MIT OR Zlib OR Apache-2.0
|
2020-07-14 10:14:00 -05:00
|
|
|
MIT/Apache-2.0
|
2023-01-01 10:52:47 -06:00
|
|
|
Unlicense OR MIT
|
2020-07-14 10:14:00 -05:00
|
|
|
Unlicense/MIT
|
2020-08-18 03:49:18 -05:00
|
|
|
Zlib OR Apache-2.0 OR MIT
|
2020-07-14 10:14:00 -05:00
|
|
|
"
|
|
|
|
.lines()
|
|
|
|
.filter(|it| !it.is_empty())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
2022-03-13 16:20:51 -05:00
|
|
|
let meta = cmd!(sh, "cargo metadata --format-version 1").read().unwrap();
|
2020-07-14 10:14:00 -05:00
|
|
|
let mut licenses = meta
|
|
|
|
.split(|c| c == ',' || c == '{' || c == '}')
|
|
|
|
.filter(|it| it.contains(r#""license""#))
|
|
|
|
.map(|it| it.trim())
|
|
|
|
.map(|it| it[r#""license":"#.len()..].trim_matches('"'))
|
|
|
|
.collect::<Vec<_>>();
|
2021-06-03 05:46:56 -05:00
|
|
|
licenses.sort_unstable();
|
2020-07-14 10:14:00 -05:00
|
|
|
licenses.dedup();
|
2020-10-16 12:46:03 -05:00
|
|
|
if licenses != expected {
|
|
|
|
let mut diff = String::new();
|
|
|
|
|
2021-06-03 06:01:16 -05:00
|
|
|
diff.push_str("New Licenses:\n");
|
2020-10-16 12:46:03 -05:00
|
|
|
for &l in licenses.iter() {
|
|
|
|
if !expected.contains(&l) {
|
2022-12-23 12:42:58 -06:00
|
|
|
diff += &format!(" {l}\n")
|
2020-10-16 12:46:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 06:01:16 -05:00
|
|
|
diff.push_str("\nMissing Licenses:\n");
|
2020-10-16 12:46:03 -05:00
|
|
|
for &l in expected.iter() {
|
|
|
|
if !licenses.contains(&l) {
|
2022-12-23 12:42:58 -06:00
|
|
|
diff += &format!(" {l}\n")
|
2020-10-16 12:46:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-23 12:42:58 -06:00
|
|
|
panic!("different set of licenses!\n{diff}");
|
2020-10-16 12:46:03 -05:00
|
|
|
}
|
2020-07-31 18:52:24 -05:00
|
|
|
assert_eq!(licenses, expected);
|
2020-07-14 10:14:00 -05:00
|
|
|
}
|
|
|
|
|
2020-03-17 04:26:29 -05:00
|
|
|
fn check_todo(path: &Path, text: &str) {
|
2020-07-08 15:47:50 -05:00
|
|
|
let need_todo = &[
|
|
|
|
// This file itself obviously needs to use todo (<- like this!).
|
2020-12-27 21:27:54 -06:00
|
|
|
"tests/tidy.rs",
|
2020-07-08 15:47:50 -05:00
|
|
|
// Some of our assists generate `todo!()`.
|
2020-05-19 17:07:00 -05:00
|
|
|
"handlers/add_turbo_fish.rs",
|
2020-07-03 11:15:03 -05:00
|
|
|
"handlers/generate_function.rs",
|
2021-09-20 16:53:05 -05:00
|
|
|
"handlers/add_missing_match_arms.rs",
|
2021-08-08 11:44:54 -05:00
|
|
|
"handlers/replace_derive_with_manual_impl.rs",
|
2020-07-08 15:47:50 -05:00
|
|
|
// To support generating `todo!()` in assists, we have `expr_todo()` in
|
|
|
|
// `ast::make`.
|
2020-04-10 15:41:11 -05:00
|
|
|
"ast/make.rs",
|
2020-08-09 12:35:42 -05:00
|
|
|
// The documentation in string literals may contain anything for its own purposes
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-db/src/generated/lints.rs",
|
|
|
|
"ide-assists/src/utils/gen_trait_fn_body.rs",
|
|
|
|
"ide-assists/src/tests/generated.rs",
|
2021-09-09 10:48:51 -05:00
|
|
|
// The tests for missing fields
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-diagnostics/src/handlers/missing_fields.rs",
|
2020-04-10 15:41:11 -05:00
|
|
|
];
|
2020-07-08 15:47:50 -05:00
|
|
|
if need_todo.iter().any(|p| path.ends_with(p)) {
|
2020-03-17 04:26:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if text.contains("TODO") || text.contains("TOOD") || text.contains("todo!") {
|
2020-11-09 06:07:18 -06:00
|
|
|
// Generated by an assist
|
|
|
|
if text.contains("${0:todo!()}") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:26:29 -05:00
|
|
|
panic!(
|
2020-04-17 03:32:12 -05:00
|
|
|
"\nTODO markers or todo! macros should not be committed to the master branch,\n\
|
2020-03-17 04:26:29 -05:00
|
|
|
use FIXME instead\n\
|
|
|
|
{}\n",
|
|
|
|
path.display(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-27 21:27:54 -06:00
|
|
|
fn check_dbg(path: &Path, text: &str) {
|
|
|
|
let need_dbg = &[
|
|
|
|
// This file itself obviously needs to use dbg.
|
2021-07-04 04:42:35 -05:00
|
|
|
"slow-tests/tidy.rs",
|
2020-12-27 21:27:54 -06:00
|
|
|
// Assists to remove `dbg!()`
|
|
|
|
"handlers/remove_dbg.rs",
|
|
|
|
// We have .dbg postfix
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-completion/src/completions/postfix.rs",
|
|
|
|
"ide-completion/src/completions/keyword.rs",
|
|
|
|
"ide-completion/src/tests/proc_macros.rs",
|
2020-12-27 21:27:54 -06:00
|
|
|
// The documentation in string literals may contain anything for its own purposes
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-completion/src/lib.rs",
|
|
|
|
"ide-db/src/generated/lints.rs",
|
2020-12-27 21:27:54 -06:00
|
|
|
// test for doc test for remove_dbg
|
|
|
|
"src/tests/generated.rs",
|
|
|
|
];
|
|
|
|
if need_dbg.iter().any(|p| path.ends_with(p)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if text.contains("dbg!") {
|
|
|
|
panic!(
|
|
|
|
"\ndbg! macros should not be committed to the master branch,\n\
|
|
|
|
{}\n",
|
|
|
|
path.display(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 08:54:43 -05:00
|
|
|
fn check_test_attrs(path: &Path, text: &str) {
|
|
|
|
let ignore_rule =
|
2022-07-08 08:44:49 -05:00
|
|
|
"https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/style.md#ignore";
|
2021-06-15 08:54:43 -05:00
|
|
|
let need_ignore: &[&str] = &[
|
2021-07-04 04:42:35 -05:00
|
|
|
// This file.
|
|
|
|
"slow-tests/tidy.rs",
|
|
|
|
// Special case to run `#[ignore]` tests.
|
2021-06-15 08:54:43 -05:00
|
|
|
"ide/src/runnables.rs",
|
|
|
|
// A legit test which needs to be ignored, as it takes too long to run
|
|
|
|
// :(
|
2022-04-30 16:46:10 -05:00
|
|
|
"hir-def/src/nameres/collector.rs",
|
2021-07-03 14:11:03 -05:00
|
|
|
// Long sourcegen test to generate lint completions.
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-db/src/tests/sourcegen_lints.rs",
|
2021-06-15 08:54:43 -05:00
|
|
|
// Obviously needs ignore.
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-assists/src/handlers/toggle_ignore.rs",
|
2021-06-15 08:54:43 -05:00
|
|
|
// See above.
|
2022-04-30 16:46:10 -05:00
|
|
|
"ide-assists/src/tests/generated.rs",
|
2021-06-15 08:54:43 -05:00
|
|
|
];
|
|
|
|
if text.contains("#[ignore") && !need_ignore.iter().any(|p| path.ends_with(p)) {
|
2022-12-23 12:42:58 -06:00
|
|
|
panic!("\ndon't `#[ignore]` tests, see:\n\n {ignore_rule}\n\n {}\n", path.display(),)
|
2021-06-15 08:54:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let panic_rule =
|
2022-07-08 08:44:49 -05:00
|
|
|
"https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/style.md#should_panic";
|
2021-07-04 04:42:35 -05:00
|
|
|
let need_panic: &[&str] = &[
|
|
|
|
// This file.
|
|
|
|
"slow-tests/tidy.rs",
|
2022-04-30 16:46:10 -05:00
|
|
|
"test-utils/src/fixture.rs",
|
2021-07-04 04:42:35 -05:00
|
|
|
];
|
2021-06-15 08:54:43 -05:00
|
|
|
if text.contains("#[should_panic") && !need_panic.iter().any(|p| path.ends_with(p)) {
|
|
|
|
panic!(
|
|
|
|
"\ndon't add `#[should_panic]` tests, see:\n\n {}\n\n {}\n",
|
|
|
|
panic_rule,
|
|
|
|
path.display(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:46:46 -05:00
|
|
|
fn check_trailing_ws(path: &Path, text: &str) {
|
|
|
|
if is_exclude_dir(path, &["test_data"]) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-17 03:32:12 -05:00
|
|
|
for (line_number, line) in text.lines().enumerate() {
|
2020-03-17 04:46:46 -05:00
|
|
|
if line.chars().last().map(char::is_whitespace) == Some(true) {
|
2021-06-18 06:47:26 -05:00
|
|
|
panic!("Trailing whitespace in {} at line {}", path.display(), line_number + 1)
|
2020-03-17 04:46:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:26:29 -05:00
|
|
|
#[derive(Default)]
|
|
|
|
struct TidyDocs {
|
|
|
|
missing_docs: Vec<String>,
|
|
|
|
contains_fixme: Vec<PathBuf>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TidyDocs {
|
|
|
|
fn visit(&mut self, path: &Path, text: &str) {
|
2021-05-17 04:04:17 -05:00
|
|
|
// Tests and diagnostic fixes don't need module level comments.
|
2021-05-22 09:20:22 -05:00
|
|
|
if is_exclude_dir(path, &["tests", "test_data", "fixes", "grammar"]) {
|
2020-03-17 04:46:46 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if is_exclude_file(path) {
|
2020-03-17 04:26:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let first_line = match text.lines().next() {
|
|
|
|
Some(it) => it,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
if first_line.starts_with("//!") {
|
|
|
|
if first_line.contains("FIXME") {
|
2020-05-31 02:59:38 -05:00
|
|
|
self.contains_fixme.push(path.to_path_buf());
|
2020-03-17 04:26:29 -05:00
|
|
|
}
|
|
|
|
} else {
|
2021-06-13 06:41:19 -05:00
|
|
|
if text.contains("// Feature:")
|
|
|
|
|| text.contains("// Assist:")
|
|
|
|
|| text.contains("// Diagnostic:")
|
|
|
|
{
|
2020-05-31 02:59:38 -05:00
|
|
|
return;
|
|
|
|
}
|
2020-03-17 04:26:29 -05:00
|
|
|
self.missing_docs.push(path.display().to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_exclude_file(d: &Path) -> bool {
|
2021-01-12 13:19:13 -06:00
|
|
|
let file_names = ["tests.rs", "famous_defs_fixture.rs"];
|
2020-03-17 04:26:29 -05:00
|
|
|
|
|
|
|
d.file_name()
|
|
|
|
.unwrap_or_default()
|
|
|
|
.to_str()
|
|
|
|
.map(|f_n| file_names.iter().any(|name| *name == f_n))
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn finish(self) {
|
|
|
|
if !self.missing_docs.is_empty() {
|
|
|
|
panic!(
|
|
|
|
"\nMissing docs strings\n\n\
|
|
|
|
modules:\n{}\n\n",
|
|
|
|
self.missing_docs.join("\n")
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-05-22 09:39:19 -05:00
|
|
|
for path in self.contains_fixme {
|
2020-03-17 04:26:29 -05:00
|
|
|
panic!("FIXME doc in a fully-documented crate: {}", path.display())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 04:46:46 -05:00
|
|
|
fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
|
2021-07-04 04:42:35 -05:00
|
|
|
p.strip_prefix(sourcegen::project_root())
|
2020-06-02 15:15:23 -05:00
|
|
|
.unwrap()
|
|
|
|
.components()
|
|
|
|
.rev()
|
|
|
|
.skip(1)
|
|
|
|
.filter_map(|it| it.as_os_str().to_str())
|
|
|
|
.any(|it| dirs_to_exclude.contains(&it))
|
2020-03-17 04:46:46 -05:00
|
|
|
}
|
2020-10-14 06:30:06 -05:00
|
|
|
|
2021-06-13 04:33:08 -05:00
|
|
|
#[derive(Default)]
|
|
|
|
struct TidyMarks {
|
|
|
|
hits: HashSet<String>,
|
|
|
|
checks: HashSet<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TidyMarks {
|
|
|
|
fn visit(&mut self, _path: &Path, text: &str) {
|
2022-07-05 08:48:28 -05:00
|
|
|
find_marks(&mut self.hits, text, "hit");
|
|
|
|
find_marks(&mut self.checks, text, "check");
|
|
|
|
find_marks(&mut self.checks, text, "check_count");
|
2021-06-13 04:33:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn finish(self) {
|
|
|
|
assert!(!self.hits.is_empty());
|
|
|
|
|
|
|
|
let diff: Vec<_> =
|
|
|
|
self.hits.symmetric_difference(&self.checks).map(|it| it.as_str()).collect();
|
|
|
|
|
|
|
|
if !diff.is_empty() {
|
2022-12-23 12:42:58 -06:00
|
|
|
panic!("unpaired marks: {diff:?}")
|
2021-06-13 04:33:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 06:30:06 -05:00
|
|
|
#[allow(deprecated)]
|
|
|
|
fn stable_hash(text: &str) -> u64 {
|
|
|
|
use std::hash::{Hash, Hasher, SipHasher};
|
|
|
|
|
|
|
|
let text = text.replace('\r', "");
|
|
|
|
let mut hasher = SipHasher::default();
|
|
|
|
text.hash(&mut hasher);
|
|
|
|
hasher.finish()
|
|
|
|
}
|
2021-06-13 04:33:08 -05:00
|
|
|
|
2022-07-05 08:48:28 -05:00
|
|
|
fn find_marks(set: &mut HashSet<String>, text: &str, mark: &str) {
|
|
|
|
let mut text = text;
|
|
|
|
let mut prev_text = "";
|
|
|
|
while text != prev_text {
|
|
|
|
prev_text = text;
|
|
|
|
if let Some(idx) = text.find(mark) {
|
|
|
|
text = &text[idx + mark.len()..];
|
|
|
|
if let Some(stripped_text) = text.strip_prefix("!(") {
|
|
|
|
text = stripped_text.trim_start();
|
|
|
|
if let Some(idx2) = text.find(|c: char| !(c.is_alphanumeric() || c == '_')) {
|
|
|
|
let mark_text = &text[..idx2];
|
|
|
|
set.insert(mark_text.to_string());
|
|
|
|
text = &text[idx2..];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 04:33:08 -05:00
|
|
|
}
|