Class: Nucop::CLI
- Inherits:
-
Thor
- Object
- Thor
- Nucop::CLI
- Defined in:
- lib/nucop/cli.rb
Instance Method Summary collapse
- #diff ⇒ Object
- #diff_enforced ⇒ Object
- #modified_lines ⇒ Object
- #ready_for_promotion ⇒ Object
- #regen_backlog ⇒ Object
- #rubocop(files = nil) ⇒ Object
- #update_enforced ⇒ Object
Instance Method Details
#diff ⇒ Object
24 25 26 27 28 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 58 59 60 |
# File 'lib/nucop/cli.rb', line 24 def diff puts "Running on files changed relative to '#{options[:"commit-spec"]}' (specify using the 'commit-spec' option)" diff_filter = [:"added-only"] ? "A" : "d" diff_base = capture_std_out("git merge-base HEAD #{options[:"commit-spec"]}").chomp files, diff_status = Open3.capture2("git diff #{diff_base} --diff-filter=#{diff_filter} --name-only | grep \"\\.rb$\"") if diff_status != 0 if [:exit] puts "There are no rb files present in diff. Exiting." exit 0 else puts "There are no rb files present in diff." return true end end if [:ignore] && File.exist?([:diffignore_file]) && !File.zero?([:diffignore_file]) files, non_ignored_diff_status = Open3.capture2("grep -v -f #{options[:diffignore_file]}", stdin_data: files) if non_ignored_diff_status != 0 if [:exit] puts "There are no non-ignored rb files present in diff. Exiting." exit 0 else puts "There are no non-ignored rb files present in diff." return true end end end no_violations_detected = invoke :rubocop, [multi_line_to_single_line(files)], exit 1 unless no_violations_detected return true unless [:exit] exit 0 end |
#diff_enforced ⇒ Object
13 14 15 |
# File 'lib/nucop/cli.rb', line 13 def diff_enforced invoke :diff, nil, .merge(only: cops_to_enforce.join(",")) end |
#modified_lines ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/nucop/cli.rb', line 95 def modified_lines diff_files, diff_status = Open3.capture2("git diff #{options[:'commit-spec']} --diff-filter=d --name-only | grep \"\\.rb$\"") exit 1 unless diff_status.exitstatus.zero? command = [ "bundle exec rubocop", "--parallel", "--format Nucop::Formatters::GitDiffFormatter", "--config #{options[:rubocop_todo_config_file]}", multi_line_to_single_line(diff_files).to_s ].join(" ") # HACK: use ENVVAR to parameterize GitDiffFormatter system({ "RUBOCOP_COMMIT_SPEC" => [:"commit-spec"] }, command) end |
#ready_for_promotion ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/nucop/cli.rb', line 114 def ready_for_promotion finder = Helpers::NextCopForPromotion.new([:rubocop_todo_file]) todo_config = YAML.load_file([:rubocop_todo_file]) puts "The following cop(s) are ready to be promoted to enforced. Good luck!" puts "Remember to run `nucop:regen_backlog` to capture your hard work." puts finder.find(["n"].to_i).each do |todo| puts "#{todo.name} with #{todo.offenses} offenses:" puts files = todo_config.fetch(todo.name, {}).fetch("Exclude", []) system("bundle exec rubocop --parallel --config #{options[:rubocop_todo_config_file]} --only #{todo.name} #{files.join(' ')}") puts("*" * 100) if ["n"] > 1 puts end end |
#regen_backlog ⇒ Object
83 84 85 86 |
# File 'lib/nucop/cli.rb', line 83 def regen_backlog regenerate_rubocop_todos update_enforced_cops end |
#rubocop(files = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nucop/cli.rb', line 66 def rubocop(files = nil) print_cops_being_run([:only]) config_file = [:"exclude-backlog"] ? RUBOCOP_DEFAULT_CONFIG_FILE : [:rubocop_todo_config_file] junit_report_path = [:"junit_report"] = junit_report_path.to_s.empty? ? "" : "--format Nucop::Formatters::JUnitFormatter --out #{junit_report_path} --format progress" rubocop_requires = [ "--require rubocop-rspec", "--require rubocop-performance", "--require rubocop-rails" ] system("bundle exec rubocop --parallel #{rubocop_requires.join(' ')} #{junit_report_options} --force-exclusion --config #{config_file} #{pass_through_option(options, 'auto-correct')} #{pass_through_flag(options, 'only')} #{files}") end |
#update_enforced ⇒ Object
89 90 91 |
# File 'lib/nucop/cli.rb', line 89 def update_enforced update_enforced_cops end |