<commit_before>module LiveEditor
  module Cli
    module Validators
      class ConfigValidator
        # Attributes
        attr_reader :errors

        # Constructor.
        def initialize
          @errors = []
        end

        # Returns an array of errors if any were found with `/theme.json`.
        def valid?
          # Grab location of /config.json.
          config_loc = LiveEditor::Cli::theme_root_dir + '/config.json'

          # Validate existence of config.json.
          if File.exist?(config_loc)
            # Validate format of config.json.
            begin
              config = JSON.parse(File.read(config_loc))
            rescue Exception => e
              @errors << {
                type: :error,
                message: 'The file at `/config.json` does not contain valid JSON markup.'
              }

              return false
            end

            # Validate presence of `api_key`, `secret_key`, and `admin_domain` attributes.
            ['api_key', 'secret_key', 'admin_domain'].each do |key|
              unless config[key]
                a_an = key.start_with?('a') ? 'an' : 'a'

                @errors << {
                  type: :error,
                  message: "The file at `/config.json` must contain #{a_an} `#{key}` attribute."
                }
              end
            end
          # No config.json.
          else
            @errors << {
              type: :notice,
              messag: '`/config.json` has not yet been created.'
            }
          end

          @errors.select { |error| error[:type] == :error }.size == 0
        end
      end
    end<commit_msg>Cleanup logic in config validator<commit_after>module LiveEditor
  module Cli
    module Validators
      class ConfigValidator
        # Attributes
        attr_reader :errors

        # Constructor.
        def initialize
          @errors = []
        end

        # Returns an array of errors if any were found with `/theme.json`.
        def valid?
          # Grab location of /config.json.
          config_loc = LiveEditor::Cli::theme_root_dir + '/config.json'

          # Validate existence of config.json.
          if File.exist?(config_loc)
            # Validate format of config.json.
            begin
              config = JSON.parse(File.read(config_loc))
            rescue Exception => e
              @errors << {
                type: :error,
                message: 'The file at `/config.json` does not contain valid JSON markup.'
              }

              return false
            end

            # Validate presence of `api_key`, `secret_key`, and `admin_domain` attributes.
            ['api_key', 'secret_key', 'admin_domain'].each do |key|
              if config[key].blank?
                a_an = key.start_with?('a') ? 'an' : 'a'

                @errors << {
                  type: :error,
                  message: "The file at `/config.json` must contain #{a_an} `#{key}` attribute."
                }
              end
            end
          # No config.json.
          else
            @errors << {
              type: :notice,
              messag: '`/config.json` has not yet been created.'
            }
          end

          @errors.select { |error| error[:type] == :error }.size == 0
        end
      end
    end
{'fraction_non_alphanumeric': 0.09888453421766656, 'fraction_numerical': 0.0006029544769369913, 'mean_word_length': 1.3432203389830508, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1364502', 'n_tokens_mistral': 879, 'n_tokens_neox': 856, 'n_words': 255}