From 40797eef5ea3f8d50c98fbb81b0c005f7a358539 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 23 Oct 2023 08:53:16 +1100 Subject: [PATCH] tidy: skip lines starting with `#` in alphabetical check. These are comment lines in `Cargo.toml` files. But exclude lines starting with `#!` from the skipping, because we want to check them. (Rust `#![feature(...)]` lines.) Also allow empty lines, which are occasionally useful. --- src/tools/tidy/src/alphabetical.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/alphabetical.rs b/src/tools/tidy/src/alphabetical.rs index dde5bef5a5f..98a8f4a9980 100644 --- a/src/tools/tidy/src/alphabetical.rs +++ b/src/tools/tidy/src/alphabetical.rs @@ -10,9 +10,10 @@ //! ``` //! //! The following lines are ignored: +//! - Empty lines //! - Lines that are indented with more or less spaces than the first line -//! - Lines starting with `//`, `#[`, `)`, `]`, `}` if the comment has the same indentation as -//! the first line +//! - Lines starting with `//`, `#` (except those starting with `#!`), `)`, `]`, `}` if the comment +//! has the same indentation as the first line //! //! If a line ends with an opening bracket, the line is ignored and the next line will have //! its extra indentation ignored. @@ -43,6 +44,10 @@ fn check_section<'a>( let mut in_split_line = None; for (line_idx, line) in lines { + if line.is_empty() { + continue; + } + if line.contains(START_MARKER) { tidy_error!(bad, "{file}:{} found `{START_MARKER}` expecting `{END_MARKER}`", line_idx) } @@ -71,7 +76,7 @@ fn check_section<'a>( let trimmed_line = line.trim_start_matches(' '); if trimmed_line.starts_with("//") - || trimmed_line.starts_with("#[") + || (trimmed_line.starts_with("#") && !trimmed_line.starts_with("#!")) || trimmed_line.starts_with(is_close_bracket) { continue;