From nobody Fri Nov 14 17:03:06 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=1761935615; cv=none; d=zohomail.com; s=zohoarc; b=nUDtACtnPvtKz9uPRzqkSNvd/p1kO8yMQYzIGHrU6DJx6AcExuRAk0K8AYzU9/enswsgHrCEEcThNZiaEXJsI7CLIt+kYQnx9ger+7FJcPJIiAmNrA0g5NAgb/qpTeGUnA2ms+7s3360UU5ZtvQTCXrquirJTJd2+5YIk5+jMvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761935615; 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=UhMiifSzE8VpldrM1dkSvTWfFrj4YgW6TUkb0IkBTvA=; b=VDTwpekyYU9Jj6w3b8krlF6Lr6sX6vvKJgIzDGB9oXKEbSzOApt0UYLBQ0g/Qd8SCRj5nQduQFyGgoZHDeFr1iO0cAhI/WQlEzklW2gta2beqBwcRJU6PrhxEODfbdifuG6xjR63xh7GEJhhO8/UW5Tc1ecYsrTjltVQEi0QO6I= 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 1761935615155663.7005927313317; Fri, 31 Oct 2025 11:33:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEtuv-0003Jz-Ln; Fri, 31 Oct 2025 14:32:05 -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 1vEtut-0003JM-2d for qemu-devel@nongnu.org; Fri, 31 Oct 2025 14:32:03 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEtue-0005uT-04 for qemu-devel@nongnu.org; Fri, 31 Oct 2025 14:31:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:7888:0:640:a8fd:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id CBE12C0157; Fri, 31 Oct 2025 21:31:33 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:546::1:17]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id UVld3d0Gj4Y0-etopZuYF; Fri, 31 Oct 2025 21:31:32 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761935492; bh=UhMiifSzE8VpldrM1dkSvTWfFrj4YgW6TUkb0IkBTvA=; h=Message-ID:Date:Cc:Subject:To:From; b=VbqO0cx6JlHIYKxm9PN7fNgMCYbklOpyOkxczsYuOD0ec5lXjsMr57x3ky6iqo6/m rv0yUVo44I/XEVzqWY18vNGo8OotBiplQUZDVLBYzrX9Knyi6jJk10EIe9+64aUJ4z PDDW7ZGFWYKyYPgF39FNNZ9MhsCtZjOzAJYE1s/c= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.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 v5] qapi: Add documentation format validation Date: Fri, 31 Oct 2025 21:31:29 +0300 Message-ID: <20251031183129.246814-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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1761935627692158500 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). Add two simple tests, illustrating the change. Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! v5: - break "literal" block at any decreasing the indent, not only at no-indent - add two simple tests 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 | 52 +++++++++++++++++++++- tests/qapi-schema/doc-bad-long-line.err | 1 + tests/qapi-schema/doc-bad-long-line.json | 6 +++ tests/qapi-schema/doc-bad-long-line.out | 0 tests/qapi-schema/doc-bad-whitespaces.err | 2 + tests/qapi-schema/doc-bad-whitespaces.json | 6 +++ tests/qapi-schema/doc-bad-whitespaces.out | 0 tests/qapi-schema/meson.build | 2 + 8 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/doc-bad-long-line.err create mode 100644 tests/qapi-schema/doc-bad-long-line.json create mode 100644 tests/qapi-schema/doc-bad-long-line.out create mode 100644 tests/qapi-schema/doc-bad-whitespaces.err create mode 100644 tests/qapi-schema/doc-bad-whitespaces.json create mode 100644 tests/qapi-schema/doc-bad-whitespaces.out diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 9fbf80a541..ffb149850d 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -108,6 +108,11 @@ 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 + self._literal_mode_indent =3D 0 + # Showtime! self._parse() =20 @@ -423,12 +428,57 @@ 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 + self._literal_mode_indent =3D 0 + elif self._literal_mode and line: + indent =3D re.match(r'^ *', line).end() + if self._literal_mode_indent =3D=3D 0: + self._literal_mode_indent =3D indent + elif indent < self._literal_mode_indent: + # ReST directives stop at decreasing indentation + 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\n" + "If this not the end of a sentence, please report the bug", + ) =20 @staticmethod def _match_at_name_colon(string: str) -> Optional[Match[str]]: diff --git a/tests/qapi-schema/doc-bad-long-line.err b/tests/qapi-schema/do= c-bad-long-line.err new file mode 100644 index 0000000000..611a3b1fef --- /dev/null +++ b/tests/qapi-schema/doc-bad-long-line.err @@ -0,0 +1 @@ +doc-bad-long-line.json:4:1: documentation line exceeds 70 columns diff --git a/tests/qapi-schema/doc-bad-long-line.json b/tests/qapi-schema/d= oc-bad-long-line.json new file mode 100644 index 0000000000..d7f887694d --- /dev/null +++ b/tests/qapi-schema/doc-bad-long-line.json @@ -0,0 +1,6 @@ +## +# @foo: +# +# This line has exactly 71 characters, including spaces and punctuation! +## +{ 'command': 'foo' } diff --git a/tests/qapi-schema/doc-bad-long-line.out b/tests/qapi-schema/do= c-bad-long-line.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/doc-bad-whitespaces.err b/tests/qapi-schema/= doc-bad-whitespaces.err new file mode 100644 index 0000000000..5cca1954c0 --- /dev/null +++ b/tests/qapi-schema/doc-bad-whitespaces.err @@ -0,0 +1,2 @@ +doc-bad-whitespaces.json:4:48: Use two spaces between sentences +If this not the end of a sentence, please report the bug diff --git a/tests/qapi-schema/doc-bad-whitespaces.json b/tests/qapi-schema= /doc-bad-whitespaces.json new file mode 100644 index 0000000000..b0c318c670 --- /dev/null +++ b/tests/qapi-schema/doc-bad-whitespaces.json @@ -0,0 +1,6 @@ +## +# @foo: +# +# Sentences should be split by two whitespaces. But here is only one. +## +{ 'command': 'foo' } diff --git a/tests/qapi-schema/doc-bad-whitespaces.out b/tests/qapi-schema/= doc-bad-whitespaces.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index c47025d16d..b24b27db21 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -61,8 +61,10 @@ schemas =3D [ 'doc-bad-event-arg.json', 'doc-bad-feature.json', 'doc-bad-indent.json', + 'doc-bad-long-line.json', 'doc-bad-symbol.json', 'doc-bad-union-member.json', + 'doc-bad-whitespaces.json', 'doc-before-include.json', 'doc-before-pragma.json', 'doc-duplicate-features.json', --=20 2.48.1