Skip to content

Commit 3536dbf

Browse files
committed
initial commit
0 parents  commit 3536dbf

26 files changed

+1055
-0
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
*.bundle
11+
*.so
12+
*.o
13+
*.a
14+
mkmf.log

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--color
2+
--require spec_helper
3+
--format documentation

Gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec
4+
5+
group :development do
6+
gem 'rspec', '~> 3.1'
7+
gem 'guard-rspec'
8+
end

Guardfile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# A sample Guardfile
2+
# More info at https://github.com/guard/guard#readme
3+
4+
## Uncomment and set this to only include directories you want to watch
5+
# directories %(app lib config test spec feature)
6+
7+
## Uncomment to clear the screen before every task
8+
# clearing :on
9+
10+
11+
12+
# Note: The cmd option is now required due to the increasing number of ways
13+
# rspec may be run, below are examples of the most common uses.
14+
# * bundler: 'bundle exec rspec'
15+
# * bundler binstubs: 'bin/rspec'
16+
# * spring: 'bin/rspec' (This will use spring if running and you have
17+
# installed the spring binstubs per the docs)
18+
# * zeus: 'zeus rspec' (requires the server to be started separately)
19+
# * 'just' rspec: 'rspec'
20+
21+
guard :rspec, cmd: "bundle exec rspec" do
22+
require "ostruct"
23+
24+
# Generic Ruby apps
25+
rspec = OpenStruct.new
26+
rspec.spec = ->(m) { "spec/#{m}_spec.rb" }
27+
rspec.spec_dir = "spec"
28+
rspec.spec_helper = "spec/spec_helper.rb"
29+
30+
watch(%r{^spec/.+_spec\.rb$})
31+
watch(%r{^lib/(.+)\.rb$}) { |m| rspec.spec.("lib/#{m[1]}") }
32+
watch(rspec.spec_helper) { rspec.spec_dir }
33+
34+
hound = OpenStruct.new
35+
hound.libspec = ->(m) { "spec/lib/hound/tools/#{m}_spec.rb" }
36+
hound.libspecs = ->(m) { m.map {|name| hound.libspec.(name) } }
37+
hound.template_r = ->(m) { /^#{Regexp.quote("lib/hound/tools/templates/_#{m}")}$/ }
38+
39+
watch('lib/hound/tools/template.rb') { hound.libspecs.(%w(cli hound_yml hound_defaults)) }
40+
watch(hound.template_r.('.hound.yml')) { hound.libspecs.(%w(cli hound_yml)) }
41+
watch(hound.template_r.('.rubocop.hound_defaults.yml')) { hound.libspecs.(%w(cli hound_defaults)) }
42+
end

LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Cezary Baginski
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Hound::Tools
2+
3+
Tools and configuration to locally simulate HoundCi checks
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
group :development do
11+
gem 'hound-tools', require: false
12+
end
13+
```
14+
15+
Run this to setup your config files so that Hound will produce the same results
16+
as running Rubocop locally:
17+
18+
```bash
19+
$ hound-tools init
20+
```
21+
22+
23+
## Usage
24+
25+
You can locally simulate a HoundCi check using:
26+
27+
```bash
28+
$ hound-tools
29+
```
30+
31+
32+
## Contributing
33+
34+
1. Fork it ( https://github.com/[my-github-username]/hound-tools/fork )
35+
2. Create your feature branch (`git checkout -b my-new-feature`)
36+
3. Commit your changes (`git commit -am 'Add some feature'`)
37+
4. Push to the branch (`git push origin my-new-feature`)
38+
5. Create a new Pull Request

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

bin/hound-tools

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'hound/tools/cli'
4+
5+
Hound::Tools::Cli.start

hound-tools.gemspec

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'hound/tools/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "hound-tools"
8+
spec.version = Hound::Tools::VERSION
9+
spec.authors = ["Cezary Baginski"]
10+
spec.email = ["[email protected]"]
11+
spec.summary = %q{Tools for configuring and using HoundCI}
12+
spec.description = %q{Matches your project config to give the same errors as HoundCi}
13+
spec.homepage = ""
14+
spec.license = "MIT"
15+
16+
spec.files = `git ls-files -z`.split("\x0")
17+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19+
spec.require_paths = ["lib"]
20+
21+
spec.add_dependency "rubocop", "0.25.0"
22+
spec.add_dependency "thor"
23+
24+
spec.add_development_dependency "bundler", "~> 1.7"
25+
spec.add_development_dependency "rake", "~> 10.0"
26+
end

lib/hound/tools.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "hound/tools/version"
2+
3+
module Hound
4+
module Tools
5+
# Your code goes here...
6+
end
7+
end

lib/hound/tools/cli.rb

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

lib/hound/tools/hound_defaults.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'yaml'
2+
3+
require "hound/tools/template"
4+
5+
module Hound
6+
module Tools
7+
class HoundDefaults
8+
include Template
9+
10+
def initialize
11+
super('.rubocop.hound_defaults.yml')
12+
end
13+
14+
private
15+
16+
def _validate(content)
17+
config = YAML.load(content)
18+
literals = config['StringLiterals']
19+
fail InvalidTemplate, "No StringLiterals section" unless literals
20+
21+
quote_style = literals['EnforcedStyle']
22+
fail InvalidTemplate, "No EnforcedStyle section" unless quote_style
23+
fail InvalidTemplate, "No double_quotes value" unless quote_style == 'double_quotes'
24+
end
25+
end
26+
end
27+
end

lib/hound/tools/hound_yml.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'yaml'
2+
3+
require "hound/tools/template"
4+
5+
module Hound
6+
module Tools
7+
class HoundYml
8+
include Template
9+
10+
def initialize
11+
super('.hound.yml')
12+
end
13+
14+
private
15+
16+
def _validate(data)
17+
config = YAML.load(data)
18+
ruby = config['ruby']
19+
fail InvalidTemplate, "No 'ruby' section" unless ruby
20+
fail InvalidTemplate, "Expected 'ruby' section to be a hash, got #{ruby.inspect}" unless ruby.is_a?(Hash)
21+
fail InvalidTemplate, "No 'config_file' section" unless ruby.key?('config_file')
22+
end
23+
end
24+
end
25+
end

lib/hound/tools/rubocop_yml.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'yaml'
2+
require "hound/tools/template"
3+
4+
module Hound
5+
module Tools
6+
class RubocopYml
7+
include Template
8+
9+
def initialize
10+
super '.rubocop.yml'
11+
end
12+
13+
private
14+
15+
def _validate(data)
16+
config = YAML.load(data)
17+
inherited = config['inherit_from']
18+
fail InvalidTemplate, "No 'inherit_from' section" unless inherited
19+
file = '.rubocop.hound_defaults.yml'
20+
fail InvalidTemplate, "'#{file}' not inherited" unless inherited.include?(file)
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)