Class: Danger::DangerWCC

Inherits:
Plugin
  • Object
show all
Includes:
Github, Utils
Defined in:
lib/wcc/rubocop_exceptions.rb,
lib/wcc/commit_lint.rb,
lib/wcc/plugin.rb,
lib/wcc/jshint.rb,
lib/wcc/todos.rb,
lib/wcc/reek.rb

Defined Under Namespace

Classes: CommitLint, Jshint, Reek, RubocopExceptions, Todos

Constant Summary collapse

CHECKS =
%i[
  rubocop_exceptions
  todos
  commit_lint
  reek
  flay
  brakeman
  jshint
].freeze

Instance Method Summary collapse

Methods included from Github

#add_labels, #labels, #pr_number, #repo_name

Methods included from Utils

#diff_strings, #each_addition_in_diff, #each_file_in_diff, #find_in_diff, #format_links_as_markdown, #issue, #logger, #parsed_diffs, #plugin, #run, #run_and_diff, #with_revision

Instance Method Details

#all(options = {}) ⇒ Object

Runs all the included checks in the plugin

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/wcc/plugin.rb', line 26

def all(options = {})
  to_run = CHECKS.reject { |check_name| options[check_name] == false }
  raise ArgumentError, 'No Enabled Checks' if to_run.empty?

  to_run.each do |check_name|
    public_send(check_name, options.fetch(check_name, {}))
  end
end

#brakeman(options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/wcc/plugin.rb', line 58

def brakeman(options = {})
  logger.info "brakeman: #{options}"
  diff = run_and_diff('bundle exec brakeman -f tabs 2>/dev/null '\
    '| sed s@`pwd`/@@ | sed -E "s/([0-9]+)//g"')
  diff = GitDiff.from_string(diff)

  brakeman_lines = run 'bundle exec brakeman -f tabs 2>/dev/null '\
    '| sed s@`pwd`/@@'
  brakeman_lines = brakeman_lines.lines

  each_addition_in_diff(diff) do |line|
    fields = brakeman_lines[line.line_number.right - 1].split("\t")

    add_brakeman_error(fields, fields[0])
  end
end

#commit_lint(options = {}) ⇒ Object

Lints the commit messages



48
49
50
51
# File 'lib/wcc/plugin.rb', line 48

def commit_lint(options = {})
  logger.info "commit_lint: #{options}"
  CommitLint.new(self, DEFAULT_COMMIT_LINT_OPTIONS.merge(options)).perform
end

#flay(options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/wcc/plugin.rb', line 75

def flay(options = {})
  logger.info "flay: #{options}"
  flay_results = parse_flay_results

  each_addition_in_diff do |add, _h, file|
    search = "#{file.b_path}:#{add.line_number.right}"
    flay_results.each do |warning, lines|
      other = lines.reject { |l| l == search }
      next unless other.length < lines.length

      add_flay_warning(warning, other, file, add)
    end
  end
end

#jshint(options = {}) ⇒ Object



90
91
92
93
# File 'lib/wcc/plugin.rb', line 90

def jshint(options = {})
  logger.info "jshint: #{options}"
  Jshint.new(self, options).perform
end

#reek(options = {}) ⇒ Object



53
54
55
56
# File 'lib/wcc/plugin.rb', line 53

def reek(options = {})
  logger.info "reek: #{options}"
  Reek.new(self, options).perform
end

#rubocop_exceptions(options = {}) ⇒ Object

Checks for if Rubocop was disabled in the source



42
43
44
45
# File 'lib/wcc/plugin.rb', line 42

def rubocop_exceptions(options = {})
  logger.info "rubocop_exceptions: #{options}"
  RubocopExceptions.new(self, options).perform
end

#todos(options = {}) ⇒ Object

Checks for added TODOs



36
37
38
39
# File 'lib/wcc/plugin.rb', line 36

def todos(options = {})
  logger.info "TODOs: #{options}"
  Todos.new(self, options).perform
end