Sha256: 9a154aee6b071e9f9e790ffa85fd69eeff3f8f5eb9c1347ccd94c0dedafdf255

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true
module ThemeCheck
  # Reports missing include/render/section liquid file
  class MissingTemplate < LiquidCheck
    severity :suggestion
    category :liquid
    doc docs_url(__FILE__)
    single_file false

    def initialize(ignore_missing: [])
      @ignore_missing = ignore_missing
    end

    def on_include(node)
      snippet = node.value.template_name_expr
      if snippet.is_a?(String)
        add_missing_offense("snippets/#{snippet}", node: node)
      end
    end

    alias_method :on_render, :on_include

    def on_section(node)
      section = node.value.section_name
      add_missing_offense("sections/#{section}", node: node)
    end

    private

    def ignore?(path)
      @ignore_missing.any? { |pattern| File.fnmatch?(pattern, path) }
    end

    def add_missing_offense(name, node:)
      path = "#{name}.liquid"
      unless ignore?(path) || theme[name]
        add_offense("'#{path}' is not found", node: node) do |corrector|
          corrector.create_file(@theme.storage, "#{name}.liquid", "")
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
theme-check-1.10.3 lib/theme_check/checks/missing_template.rb
theme-check-1.10.2 lib/theme_check/checks/missing_template.rb
theme-check-1.10.1 lib/theme_check/checks/missing_template.rb
theme-check-1.10.0 lib/theme_check/checks/missing_template.rb
theme-check-1.9.2 lib/theme_check/checks/missing_template.rb
theme-check-1.9.1 lib/theme_check/checks/missing_template.rb
theme-check-1.9.0 lib/theme_check/checks/missing_template.rb