Class: Yamlint::Linter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Linter

Returns a new instance of Linter.



10
11
12
# File 'lib/yamlint/linter.rb', line 10

def initialize(config = nil)
  @config = config || Config.load_default
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/yamlint/linter.rb', line 8

def config
  @config
end

Instance Method Details

#lint(content, filepath: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yamlint/linter.rb', line 14

def lint(content, filepath: nil)
  context = build_context(content, filepath)

  syntax_problems = check_syntax(content, filepath)
  return syntax_problems unless syntax_problems.empty?

  parse_content(context)

  rules = build_rules
  rules.each do |rule|
    problems = rule.check(context)
    context.problems.concat(Array(problems))
  end

  filter_disabled_problems(context)
end

#lint_file(filepath) ⇒ Object



31
32
33
34
# File 'lib/yamlint/linter.rb', line 31

def lint_file(filepath)
  content = File.read(filepath)
  lint(content, filepath:)
end