lib/mini_yaml/linter.rb in mini_yaml-0.1.0 vs lib/mini_yaml/linter.rb in mini_yaml-0.1.1
- old
+ new
@@ -1,13 +1,14 @@
# frozen_string_literal: true
require 'yaml'
module MiniYaml
class Linter
- def initialize(yaml, paranoid: true)
+ def initialize(yaml, paranoid: true, columns: 80)
@comment_map = nil
@parsed = parse(yaml)
+ @columns = columns
if paranoid
before, before_e, after, after_e = nil
begin
@@ -86,11 +87,11 @@
index = 0
while char = line[index]
prev_char = line[index - 1]
next_char = line[index + 1]
- if col > 80 && char == " " && prev_char.match?(/\S/) && next_char.match?(/\S/)
+ if col > @columns && char == " " && prev_char.match?(/\S/) && next_char.match?(/\S/)
buf << "\n"
col = 0
else
buf << char
end
@@ -122,12 +123,12 @@
end
end
val = val.to_s
- if val.include?("\n") || val.length > 80
+ if val.include?("\n") || val.length > @columns
lines = val.split("\n")
- force_short = lines.map(&:length).max > 80
+ force_short = lines.map(&:length).max > @columns
strip_trailing_newline = val[-1] != "\n"
if force_short
result << ">"
val = to_multiline(val)