Class: Dependabot::GithubActions::FileUpdater::WorkflowUpdater::YamlCommentFinder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/github_actions/file_updater/workflow_updater/yaml_comment_finder.rb

Instance Method Summary collapse

Instance Method Details

#find(suffix) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/yaml_comment_finder.rb', line 14

def find(suffix)
  previous_non_whitespace = T.let(nil, T.nilable(String))
  index = 0

  while index < suffix.length
    character = T.must(suffix[index])
    if quoted_scalar_start?(character, previous_non_whitespace)
      previous_non_whitespace = character
      index = quoted_scalar_end(suffix, index)
      next
    end

    return comment_with_leading_whitespace(suffix, index) if comment_start?(suffix, index)

    previous_non_whitespace = character unless character.match?(/\s/)
    index += 1
  end
  nil
end

#find_immediate(suffix) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/yaml_comment_finder.rb', line 35

def find_immediate(suffix)
  comment = find(suffix)
  return unless comment

  comment_start = T.must(suffix.b.index(comment.b))
  prefix = suffix.byteslice(0...comment_start) || ""
  comment if prefix.match?(/\A[ \t]*,?[ \t]*\z/)
end

#find_line(line) ⇒ Object



45
46
47
48
49
50
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/yaml_comment_finder.rb', line 45

def find_line(line)
  stripped = line.lstrip
  return stripped if stripped.start_with?("#")

  find(line)
end