require 'twiddler/config' module Twiddler module Lint def self.check(config) report = [] Rule::registered.each do |rule| report << rule.new(config).check end report end class Rule class << self def register @@registered ||= [] @@registered << self end def registered @@registered || [] end end def initialize(config) @config = config end def check() return "" end end class MissingStrokes < Rule register def check() all_strokes = [] @config.keytable.each do |key| all_strokes << [key.code, ""] all_strokes << [key.code, "shift"] if key.has_mod?("shift") end @config.keyboard.each do |chord| next unless chord.single? all_strokes.delete(@config.keytable.normalized(chord[0])) end if all_strokes.empty? return "Missing: all normal keystrokes accounted for" else return "Config lacks strokes: #{all_strokes.map{|str| @config.keytable[*str]}.inspect}" end end end end end