Class: Yamlint::Rules::Indentation

Inherits:
LineRule show all
Defined in:
lib/yamlint/rules/indentation.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #level

Instance Method Summary collapse

Methods inherited from LineRule

#check

Methods inherited from Base

#check, defaults, desc, inherited, #initialize, rule_id

Constructor Details

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

Instance Method Details

#check_line(line, line_number, _context) ⇒ Object



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

def check_line(line, line_number, _context)
  return if line.strip.empty?
  return if line.start_with?('#')

  expected_spaces = @config[:spaces]
  leading_spaces = line[/\A */].length

  return if leading_spaces.zero?
  return if (leading_spaces % expected_spaces).zero?

  problem(
    line: line_number,
    column: 1,
    message: "wrong indentation: expected #{expected_spaces}n spaces",
    fixable: true
  )
end

#fixable?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/yamlint/rules/indentation.rb', line 32

def fixable?
  true
end