class CoffeeLint::Config

Public Class Methods

locate() click to toggle source

Looks for existing config files and returns the first match.

# File lib/coffeelint/config.rb, line 6
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
parse(file_name) click to toggle source

Parses a given JSON file to a Hash.

# File lib/coffeelint/config.rb, line 17
def self.parse(file_name)
  JSON.parse(File.read(file_name))
end

Private Class Methods

config_files() click to toggle source

Config file names CoffeeLint will look for.

# File lib/coffeelint/config.rb, line 34
def self.config_files
  %w(
    coffeelint.json
    .coffeelint.json
  )
end
config_files_in_path(path) click to toggle source

Maps config file names in given path/directory.

# File lib/coffeelint/config.rb, line 28
def self.config_files_in_path(path)
  config_files.map { |file| File.join([*path, file].compact.reject(&:empty?)) }
end
default_locations() click to toggle source

Config files CoffeeLint will look for.

# File lib/coffeelint/config.rb, line 22
def self.default_locations
  config_files + config_files_in_path('config')
end