Class: Yamlint::Rules::CommentsIndentation

Inherits:
Base
  • Object
show all
Defined in:
lib/yamlint/rules/comments_indentation.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #level

Instance Method Summary collapse

Methods inherited from Base

defaults, desc, inherited, #initialize, rule_id

Constructor Details

This class inherits a constructor from Yamlint::Rules::Base

Instance Method Details

#check(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yamlint/rules/comments_indentation.rb', line 10

def check(context)
  problems = []

  context.lines.each_with_index do |line, index|
    line_number = index + 1

    next unless line.strip.start_with?('#')

    current_indent = line[/\A */].length
    expected_indent = expected_indent_for_comment(context.lines, index)

    next unless expected_indent && current_indent != expected_indent

    problems << problem(
      line: line_number,
      column: 1,
      message: "comment not indented correctly (expected #{expected_indent}, found #{current_indent})",
      fixable: true
    )
  end

  problems
end

#fixable?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/yamlint/rules/comments_indentation.rb', line 34

def fixable?
  true
end