Linter reference
The AsciiChem linter is a separate opt-in pass that walks the model and reports chemistry errors. It does not modify the model.
Running
Section titled “Running”formula = AsciiChem.parse("H_2 + O_2 -> H_2O")diagnostics = AsciiChem::Linter.run(formula)diagnostics.each { |d| puts d }Or via CLI:
asciichem lint -i "H_2 + O_2 -> H_2O"asciichem lint -i "..." -f jsonBuilt-in checks
Section titled “Built-in checks”The thirteen checks self-register at load time; Linter.run walks the
model once and collects their diagnostics, sorted by severity.
| Check | Severity | What it validates |
|---|---|---|
BalanceCheck | error | Stoichiometric atom conservation in reactions |
ChargeBalanceCheck | error | Charge conservation in reactions (v0.7+) |
BracketBalanceCheck | error | Group bracket consistency |
CrystalSanityCheck | error/warning | Cell lengths positive, angles in (0, 180]; fractional coords in [0, 1) |
ZMatrixReferenceCheck | error | References point to earlier rows; distances positive |
SpectrumPeakCheck | warning | Peak positions and intensities are numeric |
ElementValidationCheck | warning | Element symbols in the periodic table |
IsotopeSanityCheck | error | Isotope mass ≥ atomic number (info when the element is unknown to the table) |
UnclosedRingCheck | error | Ring closure digits have matching pairs |
ValenceCheck | error | Bond order + charge ≤ max valence (info when no max valence is known) |
IdentifierFormatCheck | error | @cas/@inchi/@inchikey/@smiles values parse offline (check digits, layer structure) |
IdentifierConsistencyCheck | error/warning | Identifier values agree with the molecule they annotate (InChI formula layer, SMILES element set) |
IdentityCrossCheck | error/warning | Derives the structure’s InChI via the configured engine and compares against @inchi/@inchikey annotations; mismatch = error, absent engine = one guidance warning |
IdentityCrossCheck scales with the engine: without one it emits a
single guidance warning; with one configured it derives every
annotated molecule’s identifier and asserts agreement — see
Local identity for engine setup.
Diagnostic object
Section titled “Diagnostic object”diagnostic.severity # => :error, :warning, or :infodiagnostic.message # => "Reaction is not balanced: H: 2 vs 4"diagnostic.node # => the Model::Node that triggered itAdding a custom check
Section titled “Adding a custom check”class MyCheck < AsciiChem::Linter::Base register :my_check
def run(formula) diagnostics = [] walk(formula) do |node| # check each node... end diagnostics endendSelf-registers at file-load time via Linter::Base.register.