Class: Yamlint::Rules::FloatValues

Inherits:
LineRule show all
Defined in:
lib/yamlint/rules/float_values.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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/yamlint/rules/float_values.rb', line 15

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

  problems = []

  if @config[:'forbid-scientific-notation'] && line.match?(/:\s*[\d.]+[eE][+-]?\d+/)
    problems << problem(
      line: line_number,
      column: line.index(':') + 1,
      message: 'scientific notation forbidden',
      fixable: false
    )
  end

  if @config[:'forbid-nan'] && line.match?(/:\s*\.nan\s*(?:#.*)?$/i)
    problems << problem(
      line: line_number,
      column: line.index(':') + 1,
      message: '.nan value forbidden',
      fixable: false
    )
  end

  if @config[:'forbid-inf'] && line.match?(/:\s*[+-]?\.inf\s*(?:#.*)?$/i)
    problems << problem(
      line: line_number,
      column: line.index(':') + 1,
      message: '.inf value forbidden',
      fixable: false
    )
  end

  if @config[:'require-numeral-before-decimal'] && line.match?(/:\s*\.\d+/)
    problems << problem(
      line: line_number,
      column: line.index(':') + 1,
      message: 'numeral required before decimal point',
      fixable: true
    )
  end

  problems
end

#fixable?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/yamlint/rules/float_values.rb', line 60

def fixable?
  @config[:'require-numeral-before-decimal']
end