hound-tools 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.hound.yml +6 -0
  4. data/.hound/defaults.yml +265 -0
  5. data/.hound/overrides.yml +19 -0
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +8 -0
  8. data/.rubocop_merged_for_hound.yml +41 -0
  9. data/.rubocop_todo.yml +11 -0
  10. data/.travis.yml +12 -0
  11. data/Gemfile +12 -0
  12. data/Guardfile +40 -0
  13. data/LICENSE.txt +22 -0
  14. data/README.md +98 -0
  15. data/Rakefile +22 -0
  16. data/bin/hound-tools +5 -0
  17. data/hound-tools.gemspec +26 -0
  18. data/lib/hound/tools.rb +7 -0
  19. data/lib/hound/tools/cli.rb +74 -0
  20. data/lib/hound/tools/hound_defaults.rb +30 -0
  21. data/lib/hound/tools/hound_overrides.rb +26 -0
  22. data/lib/hound/tools/hound_yml.rb +31 -0
  23. data/lib/hound/tools/merged_yml.rb +40 -0
  24. data/lib/hound/tools/rubocop_yml.rb +24 -0
  25. data/lib/hound/tools/runner.rb +71 -0
  26. data/lib/hound/tools/template.rb +38 -0
  27. data/lib/hound/tools/templates/_.hound.yml +6 -0
  28. data/lib/hound/tools/templates/_.hound/defaults.yml +265 -0
  29. data/lib/hound/tools/templates/_.hound/overrides.yml +19 -0
  30. data/lib/hound/tools/templates/_.rubocop.yml +8 -0
  31. data/lib/hound/tools/version.rb +5 -0
  32. data/spec/lib/hound/tools/cli_spec.rb +90 -0
  33. data/spec/lib/hound/tools/hound_defaults_spec.rb +52 -0
  34. data/spec/lib/hound/tools/hound_overrides_spec.rb +52 -0
  35. data/spec/lib/hound/tools/hound_yml_spec.rb +77 -0
  36. data/spec/lib/hound/tools/merged_yml_spec.rb +53 -0
  37. data/spec/lib/hound/tools/rubocop_yml_spec.rb +68 -0
  38. data/spec/lib/hound/tools/template_spec.rb +43 -0
  39. data/spec/spec_helper.rb +47 -0
  40. metadata +147 -0
@@ -0,0 +1,38 @@
1
+ module Hound
2
+ module Tools
3
+ module Template
4
+ class InvalidTemplate < RuntimeError
5
+ end
6
+
7
+ attr_reader :filename
8
+
9
+ def initialize(filename)
10
+ @filename = filename
11
+ end
12
+
13
+ def generate
14
+ _validate(IO.read(@filename))
15
+ $stdout.puts "#{@filename} (seems ok - skipped)"
16
+ true
17
+ rescue Errno::ENOENT
18
+ Pathname.new(@filename).dirname.mkpath
19
+ IO.write(@filename, _template_for(@filename))
20
+ $stdout.puts "#{@filename} created"
21
+ rescue InvalidTemplate => e
22
+ $stderr.puts "Error: #{@filename} is invalid! (#{e.message})"
23
+ end
24
+
25
+ private
26
+
27
+ def _template_for(file)
28
+ template_dir = Pathname.new(__FILE__).expand_path.dirname + 'templates'
29
+ path = template_dir + file.sub(/^\./, '_.')
30
+ path.read
31
+ end
32
+
33
+ def _validate(_data)
34
+ fail NotImplementedError
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop_merged_for_hound.yml
4
+
5
+ coffee_script:
6
+ enabled: true
@@ -0,0 +1,265 @@
1
+ #
2
+ # NOTE: * DO NOT EDIT THIS FILE! *
3
+ #
4
+ # This file should match the config/style_guides/ruby.yml from the
5
+ # thoughtbot/hound project
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - db/schema.rb
10
+
11
+ AccessorMethodName:
12
+ Enabled: false
13
+
14
+ ActionFilter:
15
+ Enabled: false
16
+
17
+ Alias:
18
+ Enabled: false
19
+
20
+ ArrayJoin:
21
+ Enabled: false
22
+
23
+ AsciiComments:
24
+ Enabled: false
25
+
26
+ AsciiIdentifiers:
27
+ Enabled: false
28
+
29
+ Attr:
30
+ Enabled: false
31
+
32
+ BlockNesting:
33
+ Enabled: false
34
+
35
+ CaseEquality:
36
+ Enabled: false
37
+
38
+ CharacterLiteral:
39
+ Enabled: false
40
+
41
+ ClassAndModuleChildren:
42
+ Enabled: false
43
+
44
+ ClassLength:
45
+ Enabled: false
46
+
47
+ ClassVars:
48
+ Enabled: false
49
+
50
+ CollectionMethods:
51
+ PreferredMethods:
52
+ find: detect
53
+ reduce: inject
54
+ collect: map
55
+ find_all: select
56
+
57
+ ColonMethodCall:
58
+ Enabled: false
59
+
60
+ CommentAnnotation:
61
+ Enabled: false
62
+
63
+ CyclomaticComplexity:
64
+ Enabled: false
65
+
66
+ Delegate:
67
+ Enabled: false
68
+
69
+ DeprecatedHashMethods:
70
+ Enabled: false
71
+
72
+ Documentation:
73
+ Enabled: false
74
+
75
+ DotPosition:
76
+ EnforcedStyle: trailing
77
+
78
+ DoubleNegation:
79
+ Enabled: false
80
+
81
+ EachWithObject:
82
+ Enabled: false
83
+
84
+ EmptyLiteral:
85
+ Enabled: false
86
+
87
+ Encoding:
88
+ Enabled: false
89
+
90
+ EvenOdd:
91
+ Enabled: false
92
+
93
+ FileName:
94
+ Enabled: false
95
+
96
+ FlipFlop:
97
+ Enabled: false
98
+
99
+ FormatString:
100
+ Enabled: false
101
+
102
+ GlobalVars:
103
+ Enabled: false
104
+
105
+ GuardClause:
106
+ Enabled: false
107
+
108
+ IfUnlessModifier:
109
+ Enabled: false
110
+
111
+ IfWithSemicolon:
112
+ Enabled: false
113
+
114
+ InlineComment:
115
+ Enabled: false
116
+
117
+ Lambda:
118
+ Enabled: false
119
+
120
+ LambdaCall:
121
+ Enabled: false
122
+
123
+ LineEndConcatenation:
124
+ Enabled: false
125
+
126
+ LineLength:
127
+ Max: 80
128
+
129
+ MethodLength:
130
+ Enabled: false
131
+
132
+ ModuleFunction:
133
+ Enabled: false
134
+
135
+ NegatedIf:
136
+ Enabled: false
137
+
138
+ NegatedWhile:
139
+ Enabled: false
140
+
141
+ Next:
142
+ Enabled: false
143
+
144
+ NilComparison:
145
+ Enabled: false
146
+
147
+ Not:
148
+ Enabled: false
149
+
150
+ NumericLiterals:
151
+ Enabled: false
152
+
153
+ OneLineConditional:
154
+ Enabled: false
155
+
156
+ OpMethod:
157
+ Enabled: false
158
+
159
+ ParameterLists:
160
+ Enabled: false
161
+
162
+ PercentLiteralDelimiters:
163
+ Enabled: false
164
+
165
+ PerlBackrefs:
166
+ Enabled: false
167
+
168
+ PredicateName:
169
+ NamePrefixBlacklist:
170
+ - is_
171
+
172
+ Proc:
173
+ Enabled: false
174
+
175
+ RaiseArgs:
176
+ Enabled: false
177
+
178
+ RegexpLiteral:
179
+ Enabled: false
180
+
181
+ SelfAssignment:
182
+ Enabled: false
183
+
184
+ SingleLineBlockParams:
185
+ Enabled: false
186
+
187
+ SingleLineMethods:
188
+ Enabled: false
189
+
190
+ SignalException:
191
+ Enabled: false
192
+
193
+ SpecialGlobalVars:
194
+ Enabled: false
195
+
196
+ StringLiterals:
197
+ EnforcedStyle: double_quotes
198
+
199
+ VariableInterpolation:
200
+ Enabled: false
201
+
202
+ TrailingComma:
203
+ Enabled: false
204
+
205
+ TrivialAccessors:
206
+ Enabled: false
207
+
208
+ VariableInterpolation:
209
+ Enabled: false
210
+
211
+ WhenThen:
212
+ Enabled: false
213
+
214
+ WhileUntilModifier:
215
+ Enabled: false
216
+
217
+ WordArray:
218
+ Enabled: false
219
+
220
+ # Lint
221
+
222
+ AmbiguousOperator:
223
+ Enabled: false
224
+
225
+ AmbiguousRegexpLiteral:
226
+ Enabled: false
227
+
228
+ AssignmentInCondition:
229
+ Enabled: false
230
+
231
+ ConditionPosition:
232
+ Enabled: false
233
+
234
+ DeprecatedClassMethods:
235
+ Enabled: false
236
+
237
+ ElseLayout:
238
+ Enabled: false
239
+
240
+ HandleExceptions:
241
+ Enabled: false
242
+
243
+ InvalidCharacterLiteral:
244
+ Enabled: false
245
+
246
+ LiteralInCondition:
247
+ Enabled: false
248
+
249
+ LiteralInInterpolation:
250
+ Enabled: false
251
+
252
+ Loop:
253
+ Enabled: false
254
+
255
+ ParenthesesAsGroupedExpression:
256
+ Enabled: false
257
+
258
+ RequireParentheses:
259
+ Enabled: false
260
+
261
+ UnderscorePrefixedVariableName:
262
+ Enabled: false
263
+
264
+ Void:
265
+ Enabled: false
@@ -0,0 +1,19 @@
1
+ # NOTE: DO NOT put a 'inheried_from' in this file, because Hound with silently
2
+ # ignore it
3
+ #
4
+ # Files you want to exclude
5
+ AllCops:
6
+ # Rails cops (so we don't need to run with -R option)
7
+ RunRailsCops: true
8
+ Exclude:
9
+ - db/schema.rb
10
+ - Gemfile
11
+ - Rakefile
12
+
13
+ # TODO: put your overrides here:
14
+
15
+ # StringLiterals:
16
+ # EnforcedStyle: single_quotes
17
+ #
18
+ # LineLength:
19
+ # Max: 200
@@ -0,0 +1,8 @@
1
+ inherit_from:
2
+ - .hound/defaults.yml
3
+ - .hound/overrides.yml
4
+ - .rubocop_todo.yml
5
+
6
+ # Rails cops (so we don't need to run with -R option)
7
+ AllCops:
8
+ RunRailsCops: true
@@ -0,0 +1,5 @@
1
+ module Hound
2
+ module Tools
3
+ VERSION = '0.0.4'
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ require 'hound/tools/cli'
2
+
3
+ module Hound
4
+ RSpec.describe Tools::Cli do
5
+ let(:hound_yml) { instance_double(Tools::HoundYml, generate: nil) }
6
+ let(:default_yml) { instance_double(Tools::HoundDefaults, generate: nil) }
7
+ let(:overrides_yml) { instance_double(Tools::HoundOverrides, generate: nil, filename: 'foo') }
8
+ let(:rubocop_yml) { instance_double(Tools::RubocopYml, generate: nil) }
9
+ let(:merged_yml) { instance_double(Tools::MergedYml, generate: nil) }
10
+
11
+ let(:bundler_result) { true }
12
+
13
+ before do
14
+ allow(Tools::HoundYml).to receive(:new).and_return(hound_yml)
15
+ allow(Tools::HoundDefaults).to receive(:new).and_return(default_yml)
16
+ allow(Tools::HoundOverrides).to receive(:new).and_return(overrides_yml)
17
+ allow(Tools::RubocopYml).to receive(:new).and_return(rubocop_yml)
18
+ allow(Tools::MergedYml).to receive(:new).and_return(merged_yml)
19
+
20
+ allow(Kernel).to receive(:system).
21
+ with("bundle show hound-tools > #{IO::NULL}").
22
+ and_return(bundler_result)
23
+
24
+ allow(Kernel).to receive(:system).with('bundle exec rubocop --auto-gen')
25
+
26
+ allow($stderr).to receive(:puts)
27
+ allow($stdout).to receive(:puts)
28
+ end
29
+
30
+ describe '#init' do
31
+ before { subject.init }
32
+
33
+ it 'generates a .hound.yml' do
34
+ expect(hound_yml).to have_received(:generate)
35
+ end
36
+
37
+ it 'generates a default Hound yml' do
38
+ expect(default_yml).to have_received(:generate)
39
+ end
40
+
41
+ it 'generates a default .rubocop.yml' do
42
+ expect(rubocop_yml).to have_received(:generate)
43
+ end
44
+
45
+ it 'generates an overrides yml' do
46
+ expect(overrides_yml).to have_received(:generate)
47
+ end
48
+
49
+ it 'merges the yml files for Hound' do
50
+ expect(merged_yml).to have_received(:generate)
51
+ end
52
+
53
+ context 'without hound-tools in the Gemfile' do
54
+ let(:bundler_result) { false }
55
+ it 'shows message about adding hound-tools to Gemfile' do
56
+ expect($stderr).to have_received(:puts).with(/Add hound-tools to your Gemfile/)
57
+ end
58
+ end
59
+
60
+ context 'with hound-tools in the Gemfile' do
61
+ it 'does not show message about adding hound-tools to Gemfile' do
62
+ expect($stderr).to_not have_received(:puts)
63
+ end
64
+ end
65
+
66
+ it 'runs rubocop --auto-gen' do
67
+ expect(Kernel).to have_received(:system).
68
+ with('bundle exec rubocop --auto-gen')
69
+ end
70
+ end
71
+
72
+ describe '#check' do
73
+ let(:runner) { instance_double(Hound::Tools::Runner) }
74
+
75
+ before do
76
+ allow(Hound::Tools::Runner).to receive(:new).and_return(runner)
77
+ allow(runner).to receive(:run)
78
+ subject.check
79
+ end
80
+
81
+ it 'merges the yml files for Hound' do
82
+ expect(merged_yml).to have_received(:generate)
83
+ end
84
+
85
+ it 'runs the check' do
86
+ expect(runner).to have_received(:run)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,52 @@
1
+ require 'hound/tools/hound_defaults'
2
+
3
+ require_relative 'template_spec'
4
+
5
+ RSpec.describe Hound::Tools::HoundDefaults do
6
+ filename = '.hound/defaults.yml'
7
+
8
+ it_behaves_like 'a template', filename
9
+
10
+ describe '#generate' do
11
+ before do
12
+ allow(IO).to receive(:read).
13
+ with(/lib\/hound\/tools\/templates\/_#{filename}$/).and_call_original
14
+ allow($stderr).to receive(:puts)
15
+ allow($stdout).to receive(:puts)
16
+ allow(FileUtils).to receive(:mkpath).with('.hound')
17
+ end
18
+
19
+ context "with no #{filename}" do
20
+ before do
21
+ allow(IO).to receive(:read).with(filename).and_raise(Errno::ENOENT)
22
+ allow(IO).to receive(:write).with(filename, anything)
23
+ end
24
+
25
+ it "creates a valid #{filename} file" do
26
+ expect(IO).to receive(:write).with(filename, anything) do |_file, data|
27
+ expect(data).to be
28
+ config = YAML::load(data)
29
+ expect(config).to be
30
+ expect(config).to include('StringLiterals' => { 'EnforcedStyle' => 'double_quotes' })
31
+ end
32
+
33
+ subject.generate
34
+ end
35
+ end
36
+
37
+ context "with existing invalid #{filename}" do
38
+ let(:contents) { 'foo: :bar' }
39
+ before { allow(IO).to receive(:read).with(filename).and_return(contents) }
40
+
41
+ it 'returns false' do
42
+ expect(subject.generate).to be_falsey
43
+ end
44
+
45
+ it 'displays the file already exists' do
46
+ msg = "Error: #{filename} is invalid! (No StringLiterals section)"
47
+ expect($stderr).to receive(:puts).with(msg)
48
+ subject.generate
49
+ end
50
+ end
51
+ end
52
+ end