Class: Rubydex::Linter::RuleLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rubydex/linter/rule_loader.rb

Overview

Loads project and bundled-gem rules using the Rubydex linter path convention.

Constant Summary collapse

BUILT_IN_RULE_GLOB =

: String

File.expand_path("../../{rubydex_linter,rubydex}/rules/**/*.rb", __dir__)
RULE_GLOB =

: String

"rubydex_linter/rules/**/*.rb"

Class Method Summary collapse

Class Method Details

.load(workspace_path) ⇒ Object

: (String workspace_path) -> void



24
25
26
27
28
29
30
# File 'lib/rubydex/linter/rule_loader.rb', line 24

def load(workspace_path)
  paths(workspace_path).each do |rule_file|
    require rule_file
  rescue LoadError, SyntaxError => error
    raise RuleLoadError, "Unable to load linter rules from #{rule_file}: #{error.message}", cause: error
  end
end

.paths(workspace_path) ⇒ Object

: (String workspace_path) -> Array



12
13
14
15
16
17
18
19
20
21
# File 'lib/rubydex/linter/rule_loader.rb', line 12

def paths(workspace_path)
  rule_files = Dir.glob(BUILT_IN_RULE_GLOB)
  rule_files.concat(Dir.glob(RULE_GLOB, base: workspace_path).map do |rule_file|
    File.expand_path(rule_file, workspace_path)
  end)
  rule_files.concat(Gem.find_latest_files(RULE_GLOB)) if ENV["BUNDLE_GEMFILE"]

  # Bundler can return Rubydex's built-in rules through the gem search as well.

  rule_files.uniq
end