Regula rule reference

This page documents Regula 0.8.0. The latest release is Regula 0.11.1: this page in Regula 0.11.1.

RG5001: Claimed modules need a leading module docstring and no repeated import๐Ÿ”—

  • Category Documentation
  • Scope module
  • Subreason module-documentation

A module in a claimed surface has no module docstring (/-! โ€ฆ -/ or Verso module documentation), has one that is not the first command after its imports, or repeats an import with the same modifiers.

What to do. Add a module docstring that identifies the module's material declarations and assumptions, directly after the imports and before any public section, and delete repeated imports.

Requirement
Every claimed module has a module docstring (/-! โ€ฆ -/) as its first command after the imports, and its header repeats no import with the same modifiers.
Reported in
EditorProject
Enforcement
Strict, like every rule: see how rules are enforced.

Checked example๐Ÿ”—

Violating input

โœ— RejectedExample.leansource examples/rules/RG5001/Violation.lean
theorem reflexive (n : Nat) : n = n := rfl

Findings of the violating run

RG5001 error violation fresh project, claim kernel-only

Subject Example at module `Example`

module-documentation: add a module doc comment describing this module

Correction

Change to Example.lean
+ /-! # Reflexivity
+ 
+ Reflexivity for every natural number; no additional assumptions. -/
  theorem reflexive (n : Nat) : n = n := rfl
โœ“ PassesExample.leansource examples/rules/RG5001/Fixed.lean
/-! # Reflexivity

Reflexivity for every natural number; no additional assumptions. -/
theorem reflexive (n : Nat) : n = n := rfl

The correction adds module documentation to the unchanged reflexivity evidence.

Checked by a fresh whole-project audit of <example> (axiomGate): violating run rejected, corrected run completed.

How to fix it๐Ÿ”—

  1. Add /-! # Title โ€ฆ -/ as the first command after the imports.

  2. In a module file, move the module docstring above @[expose] public section or public section.

  3. Delete the second copy of a repeated import; public import A and import all A are different imports.

  4. Follow the template in standard ยง5.3: a # title and summary, main declarations with their results and hypotheses, assumptions and dependencies, design notes. Keep only sections that help.

Why it matters๐Ÿ”—

Module documentation tells a reader which declarations carry the module's claims and under which assumptions, so the claims can be reviewed without reading every proof. The Lean community puts it first, where readers and tools look. A repeated import adds nothing and obscures which dependencies a module declares.

What triggers it๐Ÿ”—

When a claimed module finishes elaborating, the checker asks Lean for its module documentation and parses the module's header and first command from its source with Lean's own parser. The proved decision RegulaPolicy.ModuleHeader.failures then rejects, with applicability module-documentation, a module without module documentation; a module whose first command after the imports is not a module docstring (for example @[expose] public section or a declaration; a set_option โ€ฆ in prefix, the community's form for a Verso module docstring, is read through); and each import that occurs twice with the same public, meta and all modifiers. Empty modules are included.

What a passing result establishes๐Ÿ”—

Every claimed module has module documentation, its first command after the imports is a module docstring, and its header repeats no import.

It does not establish:

  • That the documentation identifies all material declarations and assumptions, or describes them faithfully (R-DOC). Presence and position say nothing about content; no section layout is imposed.

  • Import minimality: an unused or transitively redundant import that is not repeated is not reported.

It leaves these review obligations open: R-DOC.

Limitations and unsupported cases๐Ÿ”—

The editor reports this rule only when the module has finished elaborating without errors; a module with elaboration errors gets RG2005 (incomplete) instead.

Sources๐Ÿ”—

Normative clauses
standard ยง5.3 Module Documentation, standard ยง6.4 Import Discipline
Checklist rows
DOC-01, DECL-01
Detector, policy and proof sources
lean/RegulaPolicy/ModuleHeader.lean, lean/Regula/Linter/Documentation.lean, lean/Regula/Checker/AxiomGate.lean, website/RegulaStandard/DocumentationStandards.lean
Proved linkage
RegulaPolicy.ModuleHeader.failures_eq_nil_iff and mem_repeated_iff, and Regula.Checker.Acceptance.modulePresence_iff and documentationPresence_modes. Parsing the module header is operational.