Skip to content

Commit 82d7ac5

Browse files
committed
Fix more offenses.
1 parent 1f5a9d6 commit 82d7ac5

File tree

6 files changed

+48
-62
lines changed

6 files changed

+48
-62
lines changed

.rubocop_todo.yml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-01-19 22:54:29 +0100 using RuboCop version 0.36.0.
3+
# on 2016-01-19 23:11:26 +0100 using RuboCop version 0.36.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -43,12 +43,6 @@ Lint/DuplicateMethods:
4343
Lint/EndAlignment:
4444
Enabled: false
4545

46-
# Offense count: 2
47-
Lint/HandleExceptions:
48-
Exclude:
49-
- 'Rakefile'
50-
- 'lib/annotate.rb'
51-
5246
# Offense count: 6
5347
Lint/IneffectiveAccessModifier:
5448
Exclude:
@@ -90,15 +84,7 @@ Lint/UselessAccessModifier:
9084
- 'lib/annotate/annotate_routes.rb'
9185
- 'spec/integration/common_validation.rb'
9286

93-
# Offense count: 7
94-
Lint/UselessAssignment:
95-
Exclude:
96-
- 'Rakefile'
97-
- 'lib/annotate/annotate_models.rb'
98-
- 'spec/integration/common_validation.rb'
99-
- 'spec/integration/integration_spec.rb'
100-
101-
# Offense count: 17
87+
# Offense count: 18
10288
Metrics/AbcSize:
10389
Max: 157
10490

@@ -249,13 +235,12 @@ Style/CommentIndentation:
249235
Exclude:
250236
- 'lib/annotate/annotate_routes.rb'
251237

252-
# Offense count: 3
238+
# Offense count: 2
253239
# Cop supports --auto-correct.
254240
# Configuration parameters: SingleLineConditionsOnly.
255241
Style/ConditionalAssignment:
256242
Exclude:
257243
- 'lib/annotate/annotate_models.rb'
258-
- 'spec/integration/common_validation.rb'
259244

260245
# Offense count: 2
261246
# Cop supports --auto-correct.
@@ -366,7 +351,7 @@ Style/GuardClause:
366351
- 'lib/annotate/annotate_models.rb'
367352
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
368353

369-
# Offense count: 142
354+
# Offense count: 135
370355
# Cop supports --auto-correct.
371356
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
372357
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
@@ -378,12 +363,11 @@ Style/IfInsideElse:
378363
Exclude:
379364
- 'lib/annotate/annotate_routes.rb'
380365

381-
# Offense count: 6
366+
# Offense count: 5
382367
# Cop supports --auto-correct.
383368
# Configuration parameters: MaxLineLength.
384369
Style/IfUnlessModifier:
385370
Exclude:
386-
- 'Rakefile'
387371
- 'lib/annotate.rb'
388372
- 'lib/annotate/annotate_models.rb'
389373

@@ -473,7 +457,7 @@ Style/MutableConstant:
473457
- 'spec/integration/rails_2.3_with_bundler/config/environment.rb'
474458
- 'spec/spec_helper.rb'
475459

476-
# Offense count: 7
460+
# Offense count: 6
477461
# Cop supports --auto-correct.
478462
Style/NegatedIf:
479463
Exclude:
@@ -634,7 +618,7 @@ Style/SpaceAfterComma:
634618
Exclude:
635619
- 'lib/annotate/annotate_models.rb'
636620

637-
# Offense count: 50
621+
# Offense count: 44
638622
# Cop supports --auto-correct.
639623
Style/SpaceAfterControlKeyword:
640624
Exclude:
@@ -719,7 +703,7 @@ Style/SpaceInsideStringInterpolation:
719703
Style/SpecialGlobalVars:
720704
EnforcedStyle: use_perl_names
721705

722-
# Offense count: 373
706+
# Offense count: 363
723707
# Cop supports --auto-correct.
724708
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
725709
# SupportedStyles: single_quotes, double_quotes
@@ -785,13 +769,12 @@ Style/TrailingCommaInLiteral:
785769
- 'lib/annotate/annotate_models.rb'
786770
- 'spec/annotate/annotate_models_spec.rb'
787771

788-
# Offense count: 4
772+
# Offense count: 3
789773
# Cop supports --auto-correct.
790774
Style/TrailingWhitespace:
791775
Exclude:
792776
- 'lib/annotate.rb'
793777
- 'spec/annotate/annotate_models_spec.rb'
794-
- 'spec/integration/integration_spec.rb'
795778
- 'spec/integration/rails_2.3_with_bundler/db/schema.rb'
796779

797780
# Offense count: 2

Rakefile

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
def exit_exception(e)
2+
$stderr.puts e.message
3+
exit e.status_code
4+
end
5+
16
# Note : this causes annoying psych warnings under Ruby 1.9.2-p180; to fix, upgrade to 1.9.3
27
begin
38
require 'bundler'
49
Bundler.setup(:default, :development)
510
rescue Bundler::BundlerError => e
6-
$stderr.puts e.message
7-
$stderr.puts "Run `bundle install` to install missing gems"
8-
exit e.status_code
11+
$stderr.puts 'Run `bundle install` to install missing gems'
12+
exit_exception(e)
913
end
1014

1115
using_dsl = false
@@ -14,18 +18,16 @@ begin
1418
using_dsl = true
1519
rescue Exception => e
1620
# We might just be on an old version of Rake...
21+
exit_exception(e)
1722
end
1823
require 'rake'
19-
if(using_dsl)
20-
include Rake::DSL
21-
end
24+
include Rake::DSL if using_dsl
2225

23-
require "./lib/annotate"
24-
25-
require "mg"
26+
require './lib/annotate'
27+
require 'mg'
2628
begin
2729
MG.new("annotate.gemspec")
28-
rescue Exception => e
30+
rescue Exception
2931
STDERR.puts("WARNING: Couldn't read gemspec. As such, a number of tasks may be unavailable to you until you run 'rake gem:gemspec' to correct the issue.")
3032
# Gemspec is probably in a broken state, so let's give ourselves a chance to
3133
# build a new one...
@@ -88,7 +90,7 @@ namespace :jeweler do
8890
FileUtils.rm_f("pkg")
8991
end
9092
end
91-
task :clobber => :'jeweler:clobber'
93+
task clobber: :'jeweler:clobber'
9294

9395
require "rspec/core/rake_task" # RSpec 2.0
9496
RSpec::Core::RakeTask.new(:spec) do |t|
@@ -111,7 +113,7 @@ namespace :gemsets do
111113
end
112114
end
113115
end
114-
task :clobber => :'gemsets:empty'
116+
task clobber: :'gemsets:empty'
115117

116118
namespace :integration do
117119
desc "Remove any cruft generated by manual debugging runs which is .gitignore'd."
@@ -120,19 +122,19 @@ namespace :integration do
120122
end
121123

122124
desc "Reset any changed files, and remove any untracked files in spec/integration/*/, plus run integration:clean."
123-
task :clobber => [:integration_environment, :'integration:clean'] do
125+
task clobber: [:integration_environment, :'integration:clean'] do
124126
Annotate::Integration.reset_dirty_files
125127
Annotate::Integration.clear_untracked_files
126128
end
127129

128-
task :symlink => [:integration_environment] do
130+
task symlink: [:integration_environment] do
129131
require 'digest/md5'
130132

131133
integration_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'integration'))
132-
fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures'))
134+
# fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'fixtures'))
133135
target_dir = File.expand_path(ENV['TARGET']) if(ENV['TARGET'])
134-
raise "Must specify TARGET=x, where x is an integration test scenario!" unless(target_dir && Dir.exist?(target_dir))
135-
raise "TARGET directory must be within spec/integration/!" unless(target_dir.start_with?(integration_dir))
136+
raise "Must specify TARGET=x, where x is an integration test scenario!" unless target_dir && Dir.exist?(target_dir)
137+
raise "TARGET directory must be within spec/integration/!" unless target_dir.start_with?(integration_dir)
136138
candidates = {}
137139
FileList[
138140
"#{target_dir}/.rvmrc",
@@ -156,7 +158,7 @@ namespace :integration do
156158
candidates[digest] << fname
157159
end
158160
fixtures = {}
159-
FileList["spec/fixtures/**/*"].each do |fname|
161+
FileList['spec/fixtures/**/*'].each do |fname|
160162
fixtures[Digest::MD5.hexdigest(File.read(fname))] = File.expand_path(fname)
161163
end
162164

@@ -190,15 +192,15 @@ namespace :yard do
190192
FileUtils.rm_f("doc")
191193
end
192194
end
193-
task :clobber => :'yard:clobber'
195+
task clobber: :'yard:clobber'
194196

195197
namespace :rubinius do
196198
task :clobber do
197199
FileList["**/*.rbc"].each { |fname| FileUtils.rm_f(fname) }
198200
FileList[".rbx/**/*"].each { |fname| FileUtils.rm_f(fname) }
199201
end
200202
end
201-
task :clobber => :'rubinius:clobber'
203+
task clobber: :'rubinius:clobber'
202204

203205
# want other tests/tasks run by default? Add them to the list
204-
task :default => [:spec]
206+
task default: [:spec]

lib/annotate.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,23 @@ def self.eager_load(options)
158158
def self.bootstrap_rake
159159
begin
160160
require 'rake/dsl_definition'
161-
rescue Exception
161+
rescue Exception => e
162162
# We might just be on an old version of Rake...
163+
puts e.message
164+
exit e.status_code
163165
end
164166
require 'rake'
165167

166168
load './Rakefile' if File.exist?('./Rakefile')
167169
Rake::Task[:environment].invoke rescue nil
168-
if !defined?(Rails)
170+
unless defined?(Rails)
169171
# Not in a Rails project, so time to load up the parts of
170172
# ActiveSupport we need.
171173
require 'active_support'
172174
require 'active_support/core_ext/class/subclasses'
173175
require 'active_support/core_ext/string/inflections'
174176
end
177+
175178
self.load_tasks
176179
Rake::Task[:set_annotation_options].invoke
177180
end

lib/annotate/annotate_models.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ def classified_sort(cols)
628628
associations = []
629629
id = nil
630630

631-
cols = cols.each do |c|
632-
if c.name.eql?("id")
631+
cols.each do |c|
632+
if c.name.eql?('id')
633633
id = c
634-
elsif (c.name.eql?("created_at") || c.name.eql?("updated_at"))
634+
elsif (c.name.eql?('created_at') || c.name.eql?('updated_at'))
635635
timestamps << c
636-
elsif c.name[-3,3].eql?("_id")
636+
elsif c.name[-3,3].eql?('_id')
637637
associations << c
638638
else
639639
rest_cols << c

spec/integration/common_validation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def self.check_task_fixture(test_rig, annotation, place_before=true)
5757

5858
def self.apply_annotation(test_rig, fname, annotation, place_before=true)
5959
corpus = File.read(File.join(test_rig, fname))
60-
if(place_before)
61-
corpus = annotation + "\n" + corpus
60+
if place_before
61+
annotation + "\n" + corpus
6262
else
63-
corpus = corpus + "\n" + annotation
63+
corpus + "\n" + annotation
6464
end
6565
end
6666
end

spec/integration/integration_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
ENV['BUNDLE_GEMFILE'] = './Gemfile'
1717

1818
describe "annotate inside Rails, using #{CURRENT_RUBY}" do
19-
20-
here = File.expand_path('..', __FILE__)
2119
chosen_scenario = nil
22-
if(!ENV['SCENARIO'].blank?)
20+
if !ENV['SCENARIO'].blank?
2321
chosen_scenario = File.expand_path(ENV['SCENARIO'])
2422
raise "Can't find specified scenario '#{chosen_scenario}'!" unless(File.directory?(chosen_scenario))
2523
end
2624
Annotate::Integration::SCENARIOS.each do |test_rig, base_dir, test_name|
2725
next if(chosen_scenario && chosen_scenario != test_rig)
2826
it "works under #{test_name}" do
29-
if(!USING_RVM)
30-
skip "Must have RVM installed."
27+
if !USING_RVM
28+
skip 'Must have RVM installed.'
3129
next
3230
end
3331

3432
# Don't proceed if the working copy is dirty!
3533
expect(Annotate::Integration.is_clean?(test_rig)).to eq(true)
3634

37-
skip "temporarily ignored until Travis can run them"
35+
skip 'temporarily ignored until Travis can run them'
3836

3937
Bundler.with_clean_env do
4038
dir base_dir do

0 commit comments

Comments
 (0)