Module: AsciiChem::Linter

Defined in:
lib/asciichem/linter.rb,
lib/asciichem/linter/base.rb,
lib/asciichem/linter/registry.rb,
lib/asciichem/linter/diagnostic.rb,
lib/asciichem/linter/balance_check.rb,
lib/asciichem/linter/valence_check.rb,
lib/asciichem/linter/unclosed_ring_check.rb,
lib/asciichem/linter/isotope_sanity_check.rb,
lib/asciichem/linter/bracket_balance_check.rb,
lib/asciichem/linter/element_validation_check.rb

Overview

Linter framework. The parser is total — it accepts any syntactically valid input without judging chemistry correctness. The linter is a separate opt-in pass that walks the model and reports chemistry errors (unbalanced reactions, valence violations, etc.).

Checks register themselves via Linter.register(:name, Klass). The registry is open for extension; adding a new check is a single new file plus one autoload entry.

Defined Under Namespace

Modules: Registry Classes: BalanceCheck, Base, BracketBalanceCheck, Diagnostic, ElementValidationCheck, IsotopeSanityCheck, UnclosedRingCheck, ValenceCheck

Constant Summary collapse

SEVERITIES =
%i[error warning info].freeze

Class Method Summary collapse

Class Method Details

.errors?(formula) ⇒ Boolean

Convenience: returns true if any check produced an error.

Returns:

  • (Boolean)


32
33
34
# File 'lib/asciichem/linter.rb', line 32

def self.errors?(formula)
  run(formula).any? { |d| d.severity == :error }
end

.run(formula) ⇒ Object

Run all registered checks against the model. Returns an array of Diagnostic objects (empty if no issues).



27
28
29
# File 'lib/asciichem/linter.rb', line 27

def self.run(formula)
  Registry.all.flat_map { |check| check.new.run(formula) }
end