Always allow rustdoc-json tests to contain long lines · rust-lang/rust@dfed028 (original) (raw)
`@@ -72,12 +72,14 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
`
72
72
`"//@ normalize-stderr",
`
73
73
`];
`
74
74
``
``
75
`+
const LINELENGTH_CHECK: &str = "linelength";
`
``
76
+
75
77
`` // If you edit this, also edit where it gets used in check (calling contains_ignore_directives)
``
76
78
`const CONFIGURABLE_CHECKS: [&str; 11] = [
`
77
79
`"cr",
`
78
80
`"undocumented-unsafe",
`
79
81
`"tab",
`
80
``
`-
"linelength",
`
``
82
`+
LINELENGTH_CHECK,
`
81
83
`"filelength",
`
82
84
`"end-whitespace",
`
83
85
`"trailing-newlines",
`
`@@ -250,14 +252,24 @@ enum Directive {
`
250
252
`` // Use a fixed size array in the return type to catch mistakes with changing CONFIGURABLE_CHECKS
``
251
253
`` // without changing the code in check easier.
``
252
254
`fn contains_ignore_directives(
`
``
255
`+
path_str: &str,
`
253
256
`can_contain: bool,
`
254
257
`contents: &str,
`
255
258
`checks: [&str; N],
`
256
259
`) -> [Directive; N] {
`
257
``
`-
if !can_contain {
`
``
260
`+
// The rustdoc-json test syntax often requires very long lines, so the checks
`
``
261
`+
// for long lines aren't really useful.
`
``
262
`+
let always_ignore_linelength = path_str.contains("rustdoc-json");
`
``
263
+
``
264
`+
if !can_contain && !always_ignore_linelength {
`
258
265
`return [Directive::Deny; N];
`
259
266
`}
`
``
267
+
260
268
` checks.map(|check| {
`
``
269
`+
if check == LINELENGTH_CHECK && always_ignore_linelength {
`
``
270
`+
return Directive::Ignore(false);
`
``
271
`+
}
`
``
272
+
261
273
`` // Update can_contain when changing this
``
262
274
`if contents.contains(&format!("// ignore-tidy-{check}"))
`
263
275
` || contents.contains(&format!("# ignore-tidy-{check}"))
`
`@@ -367,6 +379,7 @@ pub fn check(path: &Path, bad: &mut bool) {
`
367
379
``
368
380
`walk(path, skip, &mut |entry, contents| {
`
369
381
`let file = entry.path();
`
``
382
`+
let path_str = file.to_string_lossy();
`
370
383
`let filename = file.file_name().unwrap().to_string_lossy();
`
371
384
``
372
385
`let is_css_file = filename.ends_with(".css");
`
`@@ -422,7 +435,7 @@ pub fn check(path: &Path, bad: &mut bool) {
`
422
435
`mut skip_copyright,
`
423
436
`mut skip_dbg,
`
424
437
`mut skip_odd_backticks,
`
425
``
`-
] = contains_ignore_directives(can_contain, &contents, CONFIGURABLE_CHECKS);
`
``
438
`+
] = contains_ignore_directives(&path_str, can_contain, &contents, CONFIGURABLE_CHECKS);
`
426
439
`let mut leading_new_lines = false;
`
427
440
`let mut trailing_new_lines = 0;
`
428
441
`let mut lines = 0;
`
`@@ -502,7 +515,7 @@ pub fn check(path: &Path, bad: &mut bool) {
`
502
515
`let contains_potential_directive =
`
503
516
` possible_line_start && (line.contains("-tidy") || line.contains("tidy-"));
`
504
517
`let has_recognized_ignore_directive =
`
505
``
`-
contains_ignore_directives(can_contain, line, CONFIGURABLE_CHECKS)
`
``
518
`+
contains_ignore_directives(&path_str, can_contain, line, CONFIGURABLE_CHECKS)
`
506
519
`.into_iter()
`
507
520
`.any(|directive| matches!(directive, Directive::Ignore(_)));
`
508
521
`let has_alphabetical_directive = line.contains("tidy-alphabetical-start")
`