Writing readable rule decks¶
Keep rule IDs, messages, thresholds, and geometry steps easy to find. For operation behavior and options, use the DRC reference.
Name layers and geometry clearly¶
Use names that describe the material or purpose, with explicit GDS mappings:
metal_drawn = deck.layer(10, 0, name="METAL_DRAWN")
metal_slots = deck.layer(10, 20, name="METAL_SLOTS")
Do not use the same name for drawn, slotted, and combined material. Put geometry reused by several rules near the layer declarations. Keep calculations used by one rule beside that rule.
Keep rule declarations explicit¶
Write deck.rule("ID", "Explanation", violations=...): the message follows the
ID; violations= and optional metadata use keywords.
deck.rule("METAL.WIDTH", "Metal must be at least 0.20 um wide", violations=metal.min_width(0.20))
Use literal rule IDs, messages, and thresholds. Do not generate registrations
with loops, tables, or conditions. Use a runtime when= predicate for
layout-dependent conditions; see rule options.
Keep short expressions on one line¶
Keep readable method chains together:
Do not put each method on a separate line. When an expression becomes complex or exceeds 120 characters, split it into named geometry stages:
from fabcheck import Region
def metal_width_violations() -> Region:
ordinary_metal = metal.outside(pads)
narrow_pairs = ordinary_metal.min_width(0.20)
return narrow_pairs.polygons().merged()
deck.rule("METAL.WIDTH", "Metal must be at least 0.20 um wide", violations=metal_width_violations())
Name the resulting geometry: ordinary_metal, wide_core, narrow_pairs.
Avoid tmp1 or repeatedly overwriting region. Use the exact return type,
such as Region, Edges, EdgePairs, or Check.
Long argument lists and rule metadata can span lines. Fluent chains should stay on one line or become named stages, including after a multiline call.
Preserve rule behavior¶
Formatting and renaming must preserve:
- Operation order, thresholds, and strict/inclusive comparisons.
- Marker types, duplicate findings, and topology.
- Exemptions and the reasons for unusual calculations.
Use .polygons().merged() only when polygon output and merging are intended.
Do not add or remove transformations to shorten an expression. Comment and track
any compatibility with a known source defect.
For behavior that is easy to confuse, see raw and merged geometry, range endpoints, and exemptions.
Check formatting¶
Use the 120-character Ruff configuration in examples/ruff.toml for deck files.
Run these checks on the public examples:
.venv/bin/ruff format examples
.venv/bin/ruff check examples
.venv/bin/python -m fabcheck.style examples
| Code | Fix | What it does and why |
|---|---|---|
FCS000 |
Correct unreadable or invalid Python source | The checker could not read or parse the file. Fix the source first so the remaining style checks can run. |
FCS001 |
Keep the chain on one line or name its stages | A fluent chain is spread across lines. Keep a short chain together or name its stages so the geometry order stays easy to follow. |
FCS002 |
Use a literal rule ID | The rule ID is not a literal string. Write it directly at registration so each rule can be found by its visible ID. |
FCS003 |
Put a literal message second | The rule explanation is not a literal second argument. Put it beside the ID so readers can see what the rule means. |
FCS004 |
Move registration outside loops, conditions, comprehensions, or lambdas | A registration sits inside generated or conditional Python structure. Keep registrations explicit so the maintained rule list is visible in the source. |
The style checker parses source without executing or rewriting it. It cannot judge naming, trace indirect registration helpers, or verify geometry. Review those separately. Adjacent string literals can wrap long messages; explicit rule factory functions remain valid.