From nobody Fri Nov 14 17:03:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1761911834; cv=none; d=zohomail.com; s=zohoarc; b=PDcpCHJT7fJXrrrZZw++/YYeVwY5rxarnbA+NgbXwc0nBPctIVtkxRe/rkf3+n9/uBhvnIGMBP2gZ0Gw6S3VA2Ls0GrwCQtMlZKToCCxblQwkeaQ7qsdmUINdwIQdAwDt6nx1SKek6RPqcJeTlbA2HtSzSA+r8VpznjCgNXtI2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761911834; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SwHuwFnOy0I3k3Cs0w00DYpDUa/PBuK5DTTs/Tdc+88=; b=NOzFc454NYKcFL855xlvix2UR57qSOaCCbEK5rjj0/R+6l5SKfCSGHAcTnobpn5I3+H0GK1KoMa0FogWIjfJsI1Jo2wft4Oqqu8I76ORufsS5qn9fl4thZ0bASd8MMUu5LumLVrCsOnEpVBy+l6NOJM0/VEnQZSUCHV1GrH4tuY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761911834092492.1768377979687; Fri, 31 Oct 2025 04:57:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEnjn-0000EU-BA; Fri, 31 Oct 2025 07:56:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEnjQ-0008FN-VO for qemu-devel@nongnu.org; Fri, 31 Oct 2025 07:55:51 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEnj9-0006HI-8m for qemu-devel@nongnu.org; Fri, 31 Oct 2025 07:55:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c21:2d8b:0:640:7d49:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id BF4FF80949; Fri, 31 Oct 2025 14:55:20 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:546::1:17]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id JteCMd0FtqM0-ajlbdRpA; Fri, 31 Oct 2025 14:55:20 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761911720; bh=SwHuwFnOy0I3k3Cs0w00DYpDUa/PBuK5DTTs/Tdc+88=; h=Message-ID:Date:Cc:Subject:To:From; b=M0rS+/W7gJswzTG9P6OzEJjs7Af04XVQ4ZhRkA6TF+uIt3ycV8IfLRCu0Dswf9Lc8 7gaUAT6EWCMm9zhm/795ovPlFQHyac+aUEB4h9cL9TFkUuc7tJnSYrdUG/VPObcvOO oSaiDuqN66hHGlF222tgU6WHyiURd27deMWwQFfw= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: armbru@redhat.com Cc: michael.roth@amd.com, qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH v4] qapi: Add documentation format validation Date: Fri, 31 Oct 2025 14:55:17 +0300 Message-ID: <20251031115517.79032-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1761911840964158500 Content-Type: text/plain; charset="utf-8" Add explicit validation for QAPI documentation formatting rules: 1. Lines must not exceed 70 columns in width (including '# ' prefix) 2. Sentences must be separated by two spaces Example sections and literal :: blocks (seldom case) are excluded, we don't require them to be <=3D 70, that would be too restrictive. Anyway, they share common 80-columns recommendations (not requirements). Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! v4: apply suggestions by Markus: - smart regexps - simpler error messages - hack to move cursor at the place of error - support :: blocks This is based on [PATCH 0/8] A QAPI schema doc markup fix, and style cleanup Based-on: <20251031094751.2817932-1-armbru@redhat.com> scripts/qapi/parser.py | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 9fbf80a541..2c244a3608 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -108,6 +108,10 @@ def __init__(self, self.exprs: List[QAPIExpression] =3D [] self.docs: List[QAPIDoc] =3D [] =20 + # State for tracking qmp-example blocks and simple + # :: literal blocks. + self._literal_mode =3D False + # Showtime! self._parse() =20 @@ -423,12 +427,50 @@ def get_doc_line(self) -> Optional[str]: if self.val !=3D '##': raise QAPIParseError( self, "junk after '##' at end of documentation comment= ") + self._literal_mode =3D False return None if self.val =3D=3D '#': return '' if self.val[1] !=3D ' ': raise QAPIParseError(self, "missing space after #") - return self.val[2:].rstrip() + + line =3D self.val[2:].rstrip() + + if re.match(r'(\.\. +qmp-example)? *::$', line): + self._literal_mode =3D True + elif self._literal_mode and line and not line.startswith(' '): + # ReST directives stop at first non-blank non-indented line + self._literal_mode =3D False + + if not self._literal_mode: + self._validate_doc_line_format(line) + + return line + + def _validate_doc_line_format(self, line: str) -> None: + """ + Validate documentation format rules for a single line: + 1. Lines should not exceed 70 columns + 2. Sentences should be separated by two spaces + """ + full_line_length =3D len(line) + 2 # "# " =3D 2 characters + if full_line_length > 70: + # Skip URL lines - they can't be broken + if re.match(r' *(https?|ftp)://[^ ]*$', line): + pass + else: + raise QAPIParseError( + self, "documentation line exceeds 70 columns" + ) + + single_space_pattern =3D r'(\be\.g\.|^ *\d\.|([.!?])) [A-Z0-9(]' + for m in list(re.finditer(single_space_pattern, line)): + if not m.group(2): + continue + # HACK so the error message points to the offending spot + self.pos =3D self.line_pos + 2 + m.start(2) + 1 + raise QAPIParseError( + self, "Use two spaces between sentences") =20 @staticmethod def _match_at_name_colon(string: str) -> Optional[Match[str]]: --=20 2.48.1