|
| 1 | +require 'thor' |
| 2 | +require 'yaml' |
| 3 | + |
| 4 | +require 'hound/tools/hound_yml' |
| 5 | +require 'hound/tools/hound_defaults' |
| 6 | +require 'hound/tools/rubocop_yml' |
| 7 | + |
| 8 | +require 'hound/tools/runner' |
| 9 | + |
| 10 | +module Hound |
| 11 | + module Tools |
| 12 | + class Cli < Thor |
| 13 | + INSTRUCTIONS = <<-EOS |
| 14 | + **** WARNING!!! **** |
| 15 | +
|
| 16 | + 1. All Rubocop offenses are initially ignored! (see .rubocop_todo.yml |
| 17 | + to uncomment them) |
| 18 | +
|
| 19 | + 2. Fixing all offenses at once is discouraged unless: |
| 20 | + - you are the only person actively working on the project (or starting out) |
| 21 | + - you have accepted ALL the pull requests FIRST |
| 22 | + - you have merged ALL the local and remote branches and you are NOT |
| 23 | + currently maintaining multiple branches |
| 24 | +
|
| 25 | + Instructions: |
| 26 | + ============= |
| 27 | +
|
| 28 | + 1. edit .rubocop_todo.yml to uncomment offenses you want to fix now |
| 29 | +
|
| 30 | + 2. edit .rubocop.yml to exclude project specific files (e.g. Rakefile, |
| 31 | + etc.) and add overrides (meaning - rules/cops you want different from |
| 32 | + Hound's defaults) |
| 33 | +
|
| 34 | + 3. Run `bundle exec hound-tool` to see what HoundCi would report on |
| 35 | + your files (which almost give you the same results as running `bundle |
| 36 | + exec rubocop` now - if not, file an issue). |
| 37 | +
|
| 38 | + HINT: for quickly fixing most offenses, you can uncomment those in |
| 39 | + `.rubocop_todo.yml` which include 'auto-correct' and simply run `bundle exec rubocop -a` |
| 40 | +
|
| 41 | + HINT: check the rubocop README for tips on setting up rubocop with |
| 42 | + Rake, Guard and other tools |
| 43 | +
|
| 44 | + Contributing |
| 45 | + ============ |
| 46 | +
|
| 47 | + Feel free to file issues at: https://github.com/e2/hound-tools |
| 48 | +
|
| 49 | + EOS |
| 50 | + |
| 51 | + desc :init, "Initializes a project to match default HoundCi config" |
| 52 | + def init |
| 53 | + HoundYml.new.generate |
| 54 | + HoundDefaults.new.generate |
| 55 | + RubocopYml.new.generate |
| 56 | + |
| 57 | + unless Kernel.system("bundle show hound-tools > #{IO::NULL}") |
| 58 | + $stderr.puts <<-EOS |
| 59 | + Add hound-tools to your Gemfile like so: |
| 60 | +
|
| 61 | + gem 'hound-tools', require: false |
| 62 | +
|
| 63 | + EOS |
| 64 | + end |
| 65 | + |
| 66 | + # TODO: help setup Rakefile? |
| 67 | + |
| 68 | + Kernel.system('bundle exec rubocop --auto-gen') |
| 69 | + $stdout.puts INSTRUCTIONS |
| 70 | + end |
| 71 | + |
| 72 | + default_task :check |
| 73 | + desc :check, "Simulates a HoundCi check locally" |
| 74 | + def check |
| 75 | + options = { |
| 76 | + hound_yml_file: ".hound.yml", |
| 77 | + hound_ci_style_file: ".rubocop.hound_defaults.yml", |
| 78 | + debug: false, |
| 79 | + glob_pattern: "**/*.rb" |
| 80 | + } |
| 81 | + |
| 82 | + Runner.new(options).run |
| 83 | + end |
| 84 | + end |
| 85 | + end |
| 86 | +end |
0 commit comments