From nobody Sun Nov 16 02:26:44 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762262587; cv=none; d=zohomail.com; s=zohoarc; b=Y4L1pkwR2d/1Dy1t1LdXCVJYZXnMO9dxbZACf7NriP5mmlt+9tLA0Gxv8DfmyCRy0goEkYQ31LnznB1aRgGWiShmrAHR21wDip2JL8j1uUjmHxSRwecuXKgIcNSYS7WgRz6XsmajtwVVDBiOq+ZkCns7gSILnMt73Fl5ZiiRIzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762262587; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nB9bHUOCLBvQ5g3WUO0uBsAxrycGoa4Rljt33VyM9xs=; b=CS+CGx286s4cIHgIL7DuPv3ped7lNA1gVrtSZW7O2pYWD2QHUSl8icdPlYx8ZQKoOYGDkWjHF+0AM/DNKKVOD+R+/EZ2NtLethhCqkIRyVGpLgwNzvlP2SZhYjnrOROQOKp4eg4nlehSJOO/RLEC7jBXv9q4nU+QEQZj3RmE0ss= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176226258743677.50673988641597; Tue, 4 Nov 2025 05:23:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGH00-0001Fw-Ft; Tue, 04 Nov 2025 08:23:00 -0500 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 1vGGyj-0000En-HQ for qemu-devel@nongnu.org; Tue, 04 Nov 2025 08:21:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGGyh-0001cz-LK for qemu-devel@nongnu.org; Tue, 04 Nov 2025 08:21:41 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-Jk7V5KHnMg-KQg-prgrCZA-1; Tue, 04 Nov 2025 08:21:33 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 14D961956070; Tue, 4 Nov 2025 13:21:32 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.18]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7C64219540DB; Tue, 4 Nov 2025 13:21:31 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8DFDB21E66E4; Tue, 04 Nov 2025 14:21:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762262497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nB9bHUOCLBvQ5g3WUO0uBsAxrycGoa4Rljt33VyM9xs=; b=QKRLqjc53oyGMz0YkFTNau2/3XLf9GNLZehYXP9yjEcrq/h+HGmaCA158kT4RZsqnDtnYh 3yN+VMltqzutI6fX0sMRw9WctMKs4cYQn2KTEV93daTM+mpQdc9k9csPqrLlZhL6AC3eW/ he7RBMO/mcVa4Dje8dhCIwsMm9SuBeQ= X-MC-Unique: Jk7V5KHnMg-KQg-prgrCZA-1 X-Mimecast-MFC-AGG-ID: Jk7V5KHnMg-KQg-prgrCZA_1762262492 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Vladimir Sementsov-Ogievskiy Subject: [PULL 12/12] qapi: Add documentation format validation Date: Tue, 4 Nov 2025 14:21:25 +0100 Message-ID: <20251104132125.4134730-13-armbru@redhat.com> In-Reply-To: <20251104132125.4134730-1-armbru@redhat.com> References: <20251104132125.4134730-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.788, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762262607105154100 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy 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 Message-ID: <20251031183129.246814-1-vsementsov@yandex-team.ru> The detection of example and literal blocks isn't quite correct, but it works well enough, and we can improve on top. Reviewed-by: Markus Armbruster [Comments, error messages, and test file names tweaked] Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 50 ++++++++++++++++++- .../doc-bad-space-between-sentences.err | 2 + .../doc-bad-space-between-sentences.json | 6 +++ .../doc-bad-space-between-sentences.out | 0 tests/qapi-schema/doc-long-line.err | 1 + tests/qapi-schema/doc-long-line.json | 6 +++ tests/qapi-schema/doc-long-line.out | 0 tests/qapi-schema/meson.build | 2 + 8 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/doc-bad-space-between-sentences.err create mode 100644 tests/qapi-schema/doc-bad-space-between-sentences.json create mode 100644 tests/qapi-schema/doc-bad-space-between-sentences.out create mode 100644 tests/qapi-schema/doc-long-line.err create mode 100644 tests/qapi-schema/doc-long-line.json create mode 100644 tests/qapi-schema/doc-long-line.out diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 9fbf80a541..1bb1af7051 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,55 @@ 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 characters + 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 longer than 70 characters") + + 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 a bug.") =20 @staticmethod def _match_at_name_colon(string: str) -> Optional[Match[str]]: diff --git a/tests/qapi-schema/doc-bad-space-between-sentences.err b/tests/= qapi-schema/doc-bad-space-between-sentences.err new file mode 100644 index 0000000000..479982ce22 --- /dev/null +++ b/tests/qapi-schema/doc-bad-space-between-sentences.err @@ -0,0 +1,2 @@ +doc-bad-space-between-sentences.json:4:47: Use two spaces between sentences +If this not the end of a sentence, please report a bug. diff --git a/tests/qapi-schema/doc-bad-space-between-sentences.json b/tests= /qapi-schema/doc-bad-space-between-sentences.json new file mode 100644 index 0000000000..87b6f6eb4e --- /dev/null +++ b/tests/qapi-schema/doc-bad-space-between-sentences.json @@ -0,0 +1,6 @@ +## +# @foo: +# +# Sentences should be separated by two spaces. But here is only one. +## +{ 'command': 'foo' } diff --git a/tests/qapi-schema/doc-bad-space-between-sentences.out b/tests/= qapi-schema/doc-bad-space-between-sentences.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/doc-long-line.err b/tests/qapi-schema/doc-lo= ng-line.err new file mode 100644 index 0000000000..7baa5297cf --- /dev/null +++ b/tests/qapi-schema/doc-long-line.err @@ -0,0 +1 @@ +doc-long-line.json:4:1: documentation line longer than 70 characters diff --git a/tests/qapi-schema/doc-long-line.json b/tests/qapi-schema/doc-l= ong-line.json new file mode 100644 index 0000000000..c10153b0d5 --- /dev/null +++ b/tests/qapi-schema/doc-long-line.json @@ -0,0 +1,6 @@ +## +# @foo: +# +# This line has exactly 71 chars, including the leading hash and space. +## +{ 'command': 'foo' } diff --git a/tests/qapi-schema/doc-long-line.out b/tests/qapi-schema/doc-lo= ng-line.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index c47025d16d..debff633ac 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -61,6 +61,7 @@ schemas =3D [ 'doc-bad-event-arg.json', 'doc-bad-feature.json', 'doc-bad-indent.json', + 'doc-bad-space-between-sentences.json', 'doc-bad-symbol.json', 'doc-bad-union-member.json', 'doc-before-include.json', @@ -81,6 +82,7 @@ schemas =3D [ 'doc-invalid-return2.json', 'doc-invalid-section.json', 'doc-invalid-start.json', + 'doc-long-line.json', 'doc-missing-colon.json', 'doc-missing-expr.json', 'doc-missing-space.json', --=20 2.49.0