Class: AsciiChem::Linter::ElementValidationCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/asciichem/linter/element_validation_check.rb

Overview

Validates that each Atom's element symbol is in the periodic table. Catches typos like Hx, Cy, Oq that would otherwise silently parse and produce nonsense output. Uses AsciiChem::PeriodicTable as the single source of truth.

Severity is warning, not error — the parser is total and might intentionally accept placeholder elements (e.g. X for "unknown halogen" in teaching contexts). The linter flags them for the user to confirm.

Instance Method Summary collapse

Methods inherited from Base

register

Instance Method Details

#run(formula) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/asciichem/linter/element_validation_check.rb', line 17

def run(formula)
  diagnostics = []
  walk(formula) do |node|
    next unless node.is_a?(AsciiChem::Model::Atom)

    check_atom(node, diagnostics)
  end
  diagnostics
end