Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion generate_guideline_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def guideline_rst_template(
scope: str,
tags: str,
amplification: str,
exceptions: str,
rationale: str,
non_compliant_ex_prose: str,
non_compliant_ex: str,
Expand All @@ -67,6 +68,16 @@ def norm(value: str) -> str:

indented_compliant_ex = indent(compliant_example.strip(), " " * 13)
indented_non_compliant_ex = indent(non_compliant_ex.strip(), " " * 13)

# Build the exception section only if exceptions content is provided
exception_section = ""
if exceptions and exceptions.strip():
exception_section = f"""
**Exception**

{exceptions.strip()}
"""

guideline_text = dedent(f"""
.. guideline:: {guideline_title.strip()}
:id: {guideline_id}
Expand All @@ -79,7 +90,7 @@ def norm(value: str) -> str:
:tags: {tags}

{amplification.strip()}

{exception_section}
.. rationale::
:id: {rationale_id}
:status: {norm(status)}
Expand Down Expand Up @@ -130,6 +141,7 @@ def generate_guideline_template():
scope="",
tags="",
amplification="Description of the guideline goes here.",
exceptions="",
rationale="Explanation of why this guideline is important.",
non_compliant_ex_prose="Explanation of code example.",
non_compliant_ex=""" fn example_function() {\n // Non-compliant implementation\n } """,
Expand Down
7 changes: 7 additions & 0 deletions scripts/guideline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def get(key):
md_to_rst(get("compliant_example_prose")), " " * 16
)

# Process exceptions field - convert to RST and indent appropriately
exceptions_raw = get("exceptions")
exceptions_text = ""
if exceptions_raw:
exceptions_text = indent(md_to_rst(exceptions_raw), " " * 12)

guideline_text = guideline_rst_template(
guideline_title=get("guideline_title"),
category=get("category"),
Expand All @@ -195,6 +201,7 @@ def get(key):
scope=get("scope"),
tags=get("tags"),
amplification=amplification_text,
exceptions=exceptions_text,
rationale=rationale_text,
non_compliant_ex_prose=non_compliant_ex_prose_text,
non_compliant_ex=format_code_block(get("non_compliant_ex")),
Expand Down