Sha256: 33a0b1927e364c147618fe03a7134d0a8b1f26ff65d1c4911d0383e3355459e1

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

require 'json'

module CoffeeLint
  class Config
    # Looks for existing config files and returns the first match.
    def self.locate
      locations = default_locations

      # handle environment variables
      locations.push(ENV['COFFEELINT_CONFIG']) if ENV['COFFEELINT_CONFIG']
      locations.concat(config_files_in_path(ENV['HOME'])) if ENV['HOME']

      locations.compact.detect { |file| File.exists?(file) }
    end

    # Parses a given JSON file to a Hash.
    def self.parse(file_name)
      JSON.parse(File.read(file_name))
    end

    # Config files CoffeeLint will look for.
    def self.default_locations
      config_files + config_files_in_path('config')
    end
    private_class_method :default_locations

    # Maps config file names in given path/directory.
    def self.config_files_in_path(path)
      config_files.map { |file| File.join([*path, file].compact.reject(&:empty?)) }
    end
    private_class_method :config_files_in_path

    # Config file names CoffeeLint will look for.
    def self.config_files
      %w(
        coffeelint.json
        .coffeelint.json
      )
    end
    private_class_method :config_files
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coffeelint-1.16.1 lib/coffeelint/config.rb
coffeelint-1.16.0 lib/coffeelint/config.rb
coffeelint-1.14.0 lib/coffeelint/config.rb
coffeelint-1.11.0 lib/coffeelint/config.rb
coffeelint-1.10.0.pre.patch.1 lib/coffeelint/config.rb
coffeelint-1.10.0 lib/coffeelint/config.rb
coffeelint-1.9.1 lib/coffeelint/config.rb