Method: Fastlane::Actions::EnsureNoDebugCodeAction.run

Defined in:
fastlane/lib/fastlane/actions/ensure_no_debug_code.rb

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
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
# File 'fastlane/lib/fastlane/actions/ensure_no_debug_code.rb', line 4

def self.run(params)
  command = "grep -RE '#{params[:text]}' '#{File.absolute_path(params[:path])}'"

  extensions = []
  extensions << params[:extension] unless params[:extension].nil?

  if params[:extensions]
    params[:extensions].each do |extension|
      extension.delete!('.') if extension.include?(".")
      extensions << extension
    end
  end

  if extensions.count > 1
    command << " --include=\\*.{#{extensions.join(',')}}"
  elsif extensions.count > 0
    command << " --include=\\*.#{extensions.join(',')}"
  end

  command << " --exclude #{params[:exclude]}" if params[:exclude]

  if params[:exclude_dirs]
    params[:exclude_dirs].each do |dir|
      command << " --exclude-dir #{dir.shellescape}"
    end
  end

  return command if Helper.test?

  UI.important(command)
  results = `#{command}` # we don't use `sh` as the return code of grep is wrong for some reason

  # Example Output
  #   ./fastlane.gemspec:  spec.add_development_dependency 'my_word'
  #   ./Gemfile.lock:    my_word (0.10.1)

  found = []
  results.split("\n").each do |current_raw|
    found << current_raw.strip
  end

  UI.user_error!("Found debug code '#{params[:text]}': \n\n#{found.join("\n")}") if found.count > 0
  UI.message("No debug code found in code base 🐛")
end