diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-03 20:47:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-03 20:47:17 +0100 |
| commit | e2d40b2d802d5161fcc8cc4b87303e7eb862e46b (patch) | |
| tree | 5870bb2e2af36c641dee8717ea08ab0feeead28f /src | |
| parent | 61f3ec4416f8fd1295b644fd183962d928c2e2c1 (diff) | |
| parent | dfed028e788702a313ad49754e5d7ec64ffa61cf (diff) | |
| download | rust-e2d40b2d802d5161fcc8cc4b87303e7eb862e46b.tar.gz rust-e2d40b2d802d5161fcc8cc4b87303e7eb862e46b.zip | |
Rollup merge of #137955 - Noratrieb:rustdoc-json-long-lines, r=aDotInTheVoid,jieyouxu
Always allow rustdoc-json tests to contain long lines The rustdoc-json test syntax often requires very long lines, so the checks for long lines aren't really useful. `@aDotInTheVoid` told me she'd like this and r? jieyouxu you're gonna tell me that the implementation is terrible. at least the performance seems reasonable: 2.5s after and 2.5s before.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/tidy/src/style.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 21b513629ed..205d6720718 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -72,12 +72,14 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[ "//@ normalize-stderr", ]; +const LINELENGTH_CHECK: &str = "linelength"; + // If you edit this, also edit where it gets used in `check` (calling `contains_ignore_directives`) const CONFIGURABLE_CHECKS: [&str; 11] = [ "cr", "undocumented-unsafe", "tab", - "linelength", + LINELENGTH_CHECK, "filelength", "end-whitespace", "trailing-newlines", @@ -250,14 +252,24 @@ enum Directive { // Use a fixed size array in the return type to catch mistakes with changing `CONFIGURABLE_CHECKS` // without changing the code in `check` easier. fn contains_ignore_directives<const N: usize>( + path_str: &str, can_contain: bool, contents: &str, checks: [&str; N], ) -> [Directive; N] { - if !can_contain { + // The rustdoc-json test syntax often requires very long lines, so the checks + // for long lines aren't really useful. + let always_ignore_linelength = path_str.contains("rustdoc-json"); + + if !can_contain && !always_ignore_linelength { return [Directive::Deny; N]; } + checks.map(|check| { + if check == LINELENGTH_CHECK && always_ignore_linelength { + return Directive::Ignore(false); + } + // Update `can_contain` when changing this if contents.contains(&format!("// ignore-tidy-{check}")) || contents.contains(&format!("# ignore-tidy-{check}")) @@ -367,6 +379,7 @@ pub fn check(path: &Path, bad: &mut bool) { walk(path, skip, &mut |entry, contents| { let file = entry.path(); + let path_str = file.to_string_lossy(); let filename = file.file_name().unwrap().to_string_lossy(); let is_css_file = filename.ends_with(".css"); @@ -422,7 +435,7 @@ pub fn check(path: &Path, bad: &mut bool) { mut skip_copyright, mut skip_dbg, mut skip_odd_backticks, - ] = contains_ignore_directives(can_contain, &contents, CONFIGURABLE_CHECKS); + ] = contains_ignore_directives(&path_str, can_contain, &contents, CONFIGURABLE_CHECKS); let mut leading_new_lines = false; let mut trailing_new_lines = 0; let mut lines = 0; @@ -502,7 +515,7 @@ pub fn check(path: &Path, bad: &mut bool) { let contains_potential_directive = possible_line_start && (line.contains("-tidy") || line.contains("tidy-")); let has_recognized_ignore_directive = - contains_ignore_directives(can_contain, line, CONFIGURABLE_CHECKS) + contains_ignore_directives(&path_str, can_contain, line, CONFIGURABLE_CHECKS) .into_iter() .any(|directive| matches!(directive, Directive::Ignore(_))); let has_alphabetical_directive = line.contains("tidy-alphabetical-start") |
