Class: ERBLint::RunnerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/erb_lint/runner_config.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, file_loader = nil) ⇒ RunnerConfig

Returns a new instance of RunnerConfig.


9
10
11
12
13
14
15
# File 'lib/erb_lint/runner_config.rb', line 9

def initialize(config = nil, file_loader = nil)
  @config = (config || {}).dup.deep_stringify_keys

  resolver.resolve_inheritance_from_gems(@config, @config.delete('inherit_gem'))
  resolver.resolve_inheritance(@config, file_loader) if file_loader
  @config.delete("inherit_from")
end

Class Method Details

.default(default_enabled: nil) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/erb_lint/runner_config.rb', line 48

def default(default_enabled: nil)
  default_enabled = default_enabled.nil? ? true : default_enabled
  new(
    linters: {
      AllowedScriptType: { enabled: default_enabled },
      ClosingErbTagIndent: { enabled: default_enabled },
      ExtraNewline: { enabled: default_enabled },
      FinalNewline: { enabled: default_enabled },
      NoJavascriptTagHelper: { enabled: default_enabled },
      ParserErrors: { enabled: default_enabled },
      RightTrim: { enabled: default_enabled },
      SelfClosingTag: { enabled: default_enabled },
      SpaceAroundErbTag: { enabled: default_enabled },
      SpaceIndentation: { enabled: default_enabled },
      SpaceInHtmlTag: { enabled: default_enabled },
      TrailingWhitespace: { enabled: default_enabled },
      RequireInputAutocomplete: { enabled: default_enabled },
    },
  )
end

.default_for(config) ⇒ Object


69
70
71
72
# File 'lib/erb_lint/runner_config.rb', line 69

def default_for(config)
  default_linters_enabled = config.to_hash.dig("EnableDefaultLinters")
  default(default_enabled: default_linters_enabled).merge(config)
end

Instance Method Details

#for_linter(klass) ⇒ Object

Raises:


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/erb_lint/runner_config.rb', line 21

def for_linter(klass)
  klass_name = if klass.is_a?(String)
    klass.to_s
  elsif klass.is_a?(Class) && klass <= ERBLint::Linter
    klass.simple_name
  else
    raise ArgumentError, 'expected String or linter class'
  end
  linter_klass = LinterRegistry.find_by_name(klass_name)
  raise Error, "#{klass_name}: linter not found (is it loaded?)" unless linter_klass
  linter_klass.config_schema.new(config_hash_for_linter(klass_name))
end

#global_excludeObject


34
35
36
# File 'lib/erb_lint/runner_config.rb', line 34

def global_exclude
  @config['exclude'] || []
end

#merge(other_config) ⇒ Object


38
39
40
# File 'lib/erb_lint/runner_config.rb', line 38

def merge(other_config)
  self.class.new(@config.deep_merge(other_config.to_hash))
end

#merge!(other_config) ⇒ Object


42
43
44
45
# File 'lib/erb_lint/runner_config.rb', line 42

def merge!(other_config)
  @config.deep_merge!(other_config.to_hash)
  self
end

#to_hashObject


17
18
19
# File 'lib/erb_lint/runner_config.rb', line 17

def to_hash
  @config.dup
end