Module: Cecil::Indentation::Ambiguity

Defined in:
lib/cecil/indentation.rb

Overview

rubocop:disable Style/Documentation

Class Method Summary collapse

Class Method Details

.adjust_by(adjustment) ⇒ Object

When given an ambiguously indented string, it assumes that first line is adjustment characters less than the least indented of the other lines.

Useful for this situation. Setting to adjust_by(4) will behave according to what's intended.

`def python_fn():
    pass`


25
# File 'lib/cecil/indentation.rb', line 25

def adjust_by(adjustment) = ->(min_level:, **) { min_level - adjustment }

.ignoreObject

When given an ambiguously indented string, assume that first line is the same as the least indented of the other lines.

Useful for this situation:

`def ruby_method
 end`


34
# File 'lib/cecil/indentation.rb', line 34

def ignore = adjust_by(0)

.raise_errorObject

When given an ambiguously indented string, raise an exception



37
38
39
40
41
42
43
44
45
46
# File 'lib/cecil/indentation.rb', line 37

def raise_error
  lambda do |src:, **|
    raise <<~MSG
      Indentation is ambiguous, cannot reindent. Try adding a blank
      line at the beginning or end of this fragment. Fragment:

      #{src}
    MSG
  end
end