Class: Ace::Lint::Molecules::YamlLinter

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/lint/molecules/yaml_linter.rb

Overview

Validates YAML syntax via Psych

Class Method Summary collapse

Class Method Details

.lint(file_path) ⇒ Models::LintResult

Validate YAML file

Parameters:

  • file_path (String)

    Path to YAML file

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ace/lint/molecules/yaml_linter.rb', line 15

def self.lint(file_path)
  content = File.read(file_path)
  lint_content(file_path, content)
rescue Errno::ENOENT
  Models::LintResult.new(
    file_path: file_path,
    success: false,
    errors: [Models::ValidationError.new(message: "File not found: #{file_path}")]
  )
rescue => e
  Models::LintResult.new(
    file_path: file_path,
    success: false,
    errors: [Models::ValidationError.new(message: "Error reading file: #{e.message}")]
  )
end

.lint_content(file_path, content) ⇒ Models::LintResult

Validate YAML content

Parameters:

  • file_path (String)

    Path for reference

  • content (String)

    YAML content

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ace/lint/molecules/yaml_linter.rb', line 36

def self.lint_content(file_path, content)
  result = Atoms::YamlValidator.validate(content)

  errors = result[:errors].map do |msg|
    Models::ValidationError.new(message: msg, severity: :error)
  end

  Models::LintResult.new(
    file_path: file_path,
    success: result[:valid],
    errors: errors,
    warnings: []
  )
end