Sha256: 9ad8b7896966a05a643255a033267605dec000173d37d3a11c2072a7eb0b6d2a
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module ThemeCheck class Analyzer def initialize(theme, checks = Check.all.map(&:new), auto_correct = false) @theme = theme @auto_correct = auto_correct @liquid_checks = Checks.new @json_checks = Checks.new checks.each do |check| check.theme = @theme case check when LiquidCheck @liquid_checks << check when JsonCheck @json_checks << check end end @visitor = Visitor.new(@liquid_checks) end def offenses @liquid_checks.flat_map(&:offenses) + @json_checks.flat_map(&:offenses) end def offenses_clear! @liquid_checks.each do |check| check.offenses.clear end @json_checks.each do |check| check.offenses.clear end end def analyze_theme offenses_clear! @theme.liquid.each { |template| @visitor.visit_template(template) } @theme.json.each { |json_file| @json_checks.call(:on_file, json_file) } @liquid_checks.call(:on_end) @json_checks.call(:on_end) offenses end def uncorrectable_offenses unless @auto_correct return offenses end offenses.select { |offense| !offense.correctable? } end def correct_offenses if @auto_correct offenses.each(&:correct) @theme.liquid.each(&:write) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
theme-check-0.8.3 | lib/theme_check/analyzer.rb |
theme-check-0.8.2 | lib/theme_check/analyzer.rb |
theme-check-0.8.1 | lib/theme_check/analyzer.rb |