Class: Danger::DangerRegexp

Inherits:
Plugin
  • Object
show all
Defined in:
lib/danger_plugin.rb

Defined Under Namespace

Classes: ChangedLine

Constant Summary collapse

MAX_COMMENT_COUNT =
5

Instance Method Summary collapse

Instance Method Details

#lint(&block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/danger_plugin.rb', line 9

def lint(&block)
  @map = {}

  instance_eval(&block)

  @map.each do |regexp, message|
    count = 0

    target_lines = changed_lines.select do |line|
      line.content.match?(regexp)
    end

    target_lines.first(MAX_COMMENT_COUNT).each do |line|
      markdown(message, file: line.file, line: line.number)
    end

    if target_lines.size > MAX_COMMENT_COUNT
      warn "        Regexp \#{regexp.inspect} matched too many lines (\#{target_lines.size} lines). Only first \#{MAX_COMMENT_COUNT} comments are posted.\n      MSG\n    end\n  end\nend\n"