Class: Danger::DangerRubocop

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

Overview

Run Ruby files through Rubocop. Results are passed out as a table in markdown.

Examples:

Specifying custom config file.


rubocop.lint

Lint specific files in a folder, when they change


public_files = (modified_files + added_files).select { |path| path.include?("/public/") }
rubocop.lint public_files

See Also:

  • Moya/Aeryn

Instance Method Summary collapse

Instance Method Details

#lint(config = nil) ⇒ void

This method returns an undefined value.

Runs Ruby files through Rubocop. Generates a ‘markdown` list of warnings.

Parameters:

  • files (String)

    A globbed string which should return the files that you want to run through, defaults to nil. If nil, modified and added files from the diff will be used.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/danger_plugin.rb', line 29

def lint(config = nil)
  config = config.is_a?(Hash) ? config : { files: config }
  files = config[:files]
  force_exclusion = config[:force_exclusion] || false
  config_path = config[:config]
  report_danger = config[:report_danger] || false
  only_report_new_offenses = config[:only_report_new_offenses] || false
  inline_comment = config[:inline_comment] || false
  group_inline_comments = config[:group_inline_comments] || false
  fail_on_inline_comment = config[:fail_on_inline_comment] || false
  report_severity = config[:report_severity] || false
  include_cop_names = config[:include_cop_names] || false
  rubocop_cmd = config[:rubocop_cmd] || 'rubocop'
  skip_bundle_exec = config[:skip_bundle_exec] || false

  files_to_lint = fetch_files_to_lint(files)
  files_to_report = rubocop(files_to_lint, force_exclusion, only_report_new_offenses, cmd: rubocop_cmd, config_path: config_path, skip_bundle_exec: skip_bundle_exec)

  return if files_to_report.empty?
  return report_failures(files_to_report, include_cop_names: include_cop_names) if report_danger

  if inline_comment && group_inline_comments
    add_grouped_violation_for_each_line(files_to_report, fail_on_inline_comment, report_severity, include_cop_names: include_cop_names)
  elsif inline_comment
    add_violation_for_each_line(files_to_report, fail_on_inline_comment, report_severity, include_cop_names: include_cop_names)
  else
    markdown offenses_message(files_to_report, include_cop_names: include_cop_names)
  end
end