Class: Ace::Lint::Atoms::CommentValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/lint/atoms/comment_validator.rb

Overview

Validates presence of required YAML comments in frontmatter Used for SKILL.md files that require documentation comments

Class Method Summary collapse

Class Method Details

.frontmatter_start_lineInteger

Find the line number where a comment should be added

Parameters:

  • content (String)

    Raw file content

Returns:

  • (Integer)

    Line number for error reporting (typically line 1-2)



38
39
40
# File 'lib/ace/lint/atoms/comment_validator.rb', line 38

def frontmatter_start_line
  1
end

.validate(content, required_comments:) ⇒ Array<String>

Validate that required comments are present in the raw content

Parameters:

  • content (String)

    Raw file content (with frontmatter)

  • required_comments (Array<String>)

    Comment prefixes to check for

Returns:

  • (Array<String>)

    List of missing comment patterns



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ace/lint/atoms/comment_validator.rb', line 14

def validate(content, required_comments:)
  return [] if required_comments.nil? || required_comments.empty?
  return required_comments if content.nil? || content.empty?

  # Extract frontmatter section (between --- markers)
  frontmatter = extract_frontmatter_raw(content)
  return required_comments if frontmatter.nil?

  missing = []

  required_comments.each do |comment_pattern|
    # Check if the comment pattern exists in frontmatter
    # The pattern is like "# context:" - we check if it appears in the YAML section
    unless frontmatter.include?(comment_pattern)
      missing << comment_pattern
    end
  end

  missing
end