Scripts: Exempt a bibliography from the comment-length check libeigen/eigen!2993 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
diff --git a/scripts/check_style.py b/scripts/check_style.py index e7fe425..e354e97 100644 --- a/scripts/check_style.py +++ b/scripts/check_style.py
@@ -62,6 +62,10 @@ DOXYGEN = re.compile(r"^\s*(/\*\*|/\*!|///|//!)") LICENSE = re.compile(r"SPDX|Copyright|License|Mozilla Public", re.I) +# A bibliography is provenance, which AGENTS.md keeps, and it is long by nature: one entry per +# work cited already exceeds the block threshold. Matched on the block's own header line so that +# ordinary prose mentioning a reference is still counted. +REFERENCES = re.compile(r"^\s*(?://|/\*)?\s*References:\s*$", re.M) STD_MATH = ( r"abs|arg|conj|real|imag|sqrt|cbrt|isnan|isinf|isfinite|signbit|exp|exp2|expm1|log|log1p|log2|pow|" r"sin|cos|tan|asin|acos|atan|atan2|asinh|acosh|atanh|sinh|cosh|tanh|hypot|fma|copysign|ldexp|floor|" @@ -245,14 +249,16 @@ """Flag comment blocks that gain six or more added narration lines. Blocks are formed over the full file, so an addition inside an existing - Doxygen or license block inherits that block's exemption, and only the - ADDED lines count toward the threshold — extending a pre-existing block - by a line or two is not reported. + Doxygen, license or bibliography block inherits that block's exemption, and + only the ADDED lines count toward the threshold — extending a pre-existing + block by a line or two is not reported. """ def finish_block(block_start, block_end, is_doxygen): block = comment_only[block_start:block_end] added_in_block = [line_no for line_no in range(block_start + 1, block_end + 1) if line_no in added] - if added_in_block and len(added_in_block) >= 6 and not (is_doxygen or LICENSE.search("\n".join(block))): + text = "\n".join(block) + exempt = is_doxygen or LICENSE.search(text) or REFERENCES.search(text) + if added_in_block and len(added_in_block) >= 6 and not exempt: findings.append((added_in_block[0], "%d added lines of non-Doxygen comment: AGENTS.md keeps only " "mathematics, invariants, compatibility constraints, provenance, " "or the reason a deliberate construct must not be simplified"
diff --git a/scripts/test_check_style.py b/scripts/test_check_style.py index d092dd8..cd8cdb2 100644 --- a/scripts/test_check_style.py +++ b/scripts/test_check_style.py
@@ -142,6 +142,12 @@ license_header = "\n".join("// SPDX-License-Identifier: MPL-2.0" if i == 0 else "// Copyright notice %d" % i for i in range(8)) + "\nint x = 1;\n" assert_clean("Eigen/src/Core/Foo.h", license_header) + # A bibliography under its own header is provenance, exempt however long it runs. + refs = "// References:\n" + "\n".join("// [%d] Author, \"Title\", 20%02d." % (i, i) for i in range(8)) + assert_clean("Eigen/src/Core/Foo.h", refs + "\nint x = 1;\n") + # Prose that merely mentions references is still narration. + prose = "\n".join("// see the References: section for line %d" % i for i in range(6)) + "\nint x = 1;\n" + assert_flags("Eigen/src/Core/Foo.h", prose, "non-Doxygen comment") # Five added lines stay under the threshold. assert_clean("Eigen/src/Core/Foo.h", "\n".join("// l%d" % i for i in range(5)) + "\nint x = 1;\n") # Extending an existing narration block by two lines is not reported: only