Sha256: 80698d6f83ff9c58d669c00142f68b5eb6198d04d0e2773d65cf191c24f11fd2

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true
require_relative "json_helpers"

module ThemeCheck
  class Check
    include JsonHelpers

    attr_accessor :theme
    attr_accessor :offenses
    attr_accessor :options

    SEVERITIES = [
      :error,
      :suggestion,
      :style,
    ]

    CATEGORIES = [
      :liquid,
      :translation,
      :json,
    ]

    class << self
      def all
        @all ||= []
      end

      def severity(severity = nil)
        if severity
          unless SEVERITIES.include?(severity)
            raise ArgumentError, "unknown severity. Use: #{SEVERITIES.join(', ')}"
          end
          @severity = severity
        end
        @severity if defined?(@severity)
      end

      def category(category = nil)
        if category
          unless CATEGORIES.include?(category)
            raise ArgumentError, "unknown category. Use: #{CATEGORIES.join(', ')}"
          end
          @category = category
        end
        @category if defined?(@category)
      end

      def doc(doc = nil)
        @doc = doc if doc
        @doc if defined?(@doc)
      end
    end

    def severity
      self.class.severity
    end

    def category
      self.class.category
    end

    def doc
      self.class.doc
    end

    def code_name
      self.class.name.demodulize
    end

    def ignore!
      @ignored = true
    end

    def unignore!
      @ignored = false
    end

    def ignored?
      defined?(@ignored) && @ignored
    end

    def to_s
      s = +"#{code_name}:\n"
      properties = { severity: severity, category: category, doc: doc }.merge(options)
      properties.each_pair do |name, value|
        s << "  #{name}: #{value}\n" if value
      end
      s
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
theme-check-0.2.2 lib/theme_check/check.rb
theme-check-0.2.0 lib/theme_check/check.rb
theme-check-0.1.2 lib/theme_check/check.rb
theme-check-0.1.1 lib/theme_check/check.rb
theme-check-0.1.0 lib/theme_check/check.rb