Class: A11y::Lint::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/a11y/lint/configuration.rb

Overview

Loads and stores rule configuration from a YAML file.

Constant Summary collapse

DEFAULT_FILE =
".a11y-lint.yml"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash = {}) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
# File 'lib/a11y/lint/configuration.rb', line 11

def initialize(config_hash = {})
  @config = config_hash
end

Class Method Details

.load(path = nil, search_path: Dir.pwd) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/a11y/lint/configuration.rb', line 15

def self.load(path = nil, search_path: Dir.pwd)
  path ||= find_config_file(search_path)
  return new unless path && File.exist?(path)

  config_hash = YAML.safe_load_file(path) || {}
  new(config_hash)
end

Instance Method Details

#enabled?(rule_name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/a11y/lint/configuration.rb', line 39

def enabled?(rule_name)
  return true unless @config.key?(rule_name)

  @config.dig(rule_name, "Enabled") != false
end

#enabled_rulesObject



50
51
52
53
54
55
56
57
# File 'lib/a11y/lint/configuration.rb', line 50

def enabled_rules
  Rules.constants.filter_map do |name|
    klass = Rules.const_get(name)
    next unless klass.is_a?(Class) && klass < NodeRule

    klass if enabled?(klass.rule_name)
  end
end

#hidden_wrapper_classesObject



45
46
47
48
# File 'lib/a11y/lint/configuration.rb', line 45

def hidden_wrapper_classes
  @hidden_wrapper_classes ||=
    Array(@config["hidden_wrapper_classes"]).map(&:to_s).freeze
end