Module: ERBLint::LinterRegistry

Overview

Stores all linters available to the application.

Constant Summary collapse

DEPRECATED_CUSTOM_LINTERS_DIR =
".erb-linters"
CUSTOM_LINTERS_DIR =
".erb_linters"

Class Method Summary collapse

Class Method Details

.clearObject



11
12
13
# File 'lib/erb_lint/linter_registry.rb', line 11

def clear
  @linters = nil
end

.find_by_name(name) ⇒ Object



19
20
21
# File 'lib/erb_lint/linter_registry.rb', line 19

def find_by_name(name)
  linters.detect { |linter| linter.simple_name == name }
end

.included(linter_class) ⇒ Object



15
16
17
# File 'lib/erb_lint/linter_registry.rb', line 15

def included(linter_class)
  @loaded_linters << linter_class
end

.lintersObject



23
24
25
26
27
28
# File 'lib/erb_lint/linter_registry.rb', line 23

def linters
  @linters ||= begin
    load_custom_linters
    @loaded_linters
  end
end

.load_custom_linters(directory = CUSTOM_LINTERS_DIR) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/erb_lint/linter_registry.rb', line 30

def load_custom_linters(directory = CUSTOM_LINTERS_DIR)
  ruby_files = Dir.glob(File.expand_path(File.join(directory, "**", "*.rb")))

  deprecated_ruby_files = Dir.glob(File.expand_path(File.join(DEPRECATED_CUSTOM_LINTERS_DIR, "**", "*.rb")))
  if deprecated_ruby_files.any?
    deprecation_message = "The '#{DEPRECATED_CUSTOM_LINTERS_DIR}' directory for custom linters is deprecated. " \
      "Please rename it to '#{CUSTOM_LINTERS_DIR}'"
    warn(Rainbow(deprecation_message).yellow)
    ruby_files.concat(deprecated_ruby_files)
  end

  ruby_files.each { |file| require file }
end