From b45c9ca9b6571108242c1dfc3d3e160f56baf025 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Aug 2016 23:41:00 +0200 Subject: [PATCH] revises most Lint/EndAlignment offenses Some case expressions remain, need to think about those ones. --- .../lib/active_model/validations/clusivity.rb | 10 +++++----- .../associations/collection_association.rb | 10 +++++----- .../lib/active_record/attribute_methods.rb | 6 +++--- .../attribute_methods/serialization.rb | 10 +++++----- activerecord/lib/active_record/core.rb | 11 ++++++----- .../lib/active_record/railties/databases.rake | 14 +++++++------- .../lib/active_record/relation/finder_methods.rb | 14 +++++++------- .../lib/active_record/tasks/database_tasks.rb | 6 +++--- activerecord/test/cases/column_alias_test.rb | 6 +++--- activerecord/test/cases/migration/columns_test.rb | 7 ++++--- railties/lib/rails/commands/plugin.rb | 7 ++++--- railties/lib/rails/info.rb | 6 +++--- railties/lib/rails/test_unit/testing.rake | 6 +++--- 13 files changed, 58 insertions(+), 55 deletions(-) diff --git a/activemodel/lib/active_model/validations/clusivity.rb b/activemodel/lib/active_model/validations/clusivity.rb index a869dba672..18f1056e2b 100644 --- a/activemodel/lib/active_model/validations/clusivity.rb +++ b/activemodel/lib/active_model/validations/clusivity.rb @@ -17,11 +17,11 @@ module ActiveModel def include?(record, value) members = if delimiter.respond_to?(:call) delimiter.call(record) - elsif delimiter.respond_to?(:to_sym) - record.send(delimiter) - else - delimiter - end + elsif delimiter.respond_to?(:to_sym) + record.send(delimiter) + else + delimiter + end members.send(inclusion_method(members), value) end diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 6e5877f6f5..ab267f6897 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -221,11 +221,11 @@ module ActiveRecord dependent = if dependent dependent - elsif options[:dependent] == :destroy - :delete_all - else - options[:dependent] - end + elsif options[:dependent] == :destroy + :delete_all + else + options[:dependent] + end delete_or_nullify_all_records(dependent).tap do reset diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 367e7fba84..ba26a11b39 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -162,9 +162,9 @@ module ActiveRecord def attribute_names @attribute_names ||= if !abstract_class? && table_exists? attribute_types.keys - else - [] - end + else + [] + end end # Returns true if the given attribute exists, otherwise false. diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index 8fb29fb358..c70178cd2c 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -51,11 +51,11 @@ module ActiveRecord # using the #as_json hook. coder = if class_name_or_coder == ::JSON Coders::JSON - elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) } - class_name_or_coder - else - Coders::YAMLColumn.new(class_name_or_coder) - end + elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) } + class_name_or_coder + else + Coders::YAMLColumn.new(class_name_or_coder) + end decorate_attribute_type(attr_name, :serialize) do |type| Type::Serialized.new(type, coder) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 19a2720913..5b21e01dcc 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -498,14 +498,15 @@ module ActiveRecord # We check defined?(@attributes) not to issue warnings if the object is # allocated but not initialized. inspection = if defined?(@attributes) && @attributes - self.class.column_names.collect { |name| + self.class.column_names.collect do |name| if has_attribute?(name) "#{name}: #{attribute_for_inspect(name)}" end - }.compact.join(", ") - else - "not initialized" - end + end.compact.join(", ") + else + "not initialized" + end + "#<#{self.class} #{inspection}>" end diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index a2bcf54377..1d52f77622 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -205,16 +205,16 @@ db_namespace = namespace :db do fixtures_dir = if ENV["FIXTURES_DIR"] File.join base_dir, ENV["FIXTURES_DIR"] - else - base_dir - end + else + base_dir + end fixture_files = if ENV["FIXTURES"] ENV["FIXTURES"].split(",") - else - # The use of String#[] here is to support namespaced fixtures - Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] } - end + else + # The use of String#[] here is to support namespaced fixtures. + Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] } + end ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files) end diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 6349701dba..7bf84c2f15 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -544,12 +544,12 @@ module ActiveRecord def find_nth_with_limit(index, limit) # TODO: once the offset argument is removed from find_nth, - # find_nth_with_limit_and_offset can be merged into this method + # find_nth_with_limit_and_offset can be merged into this method. relation = if order_values.empty? && primary_key order(arel_attribute(primary_key).asc) - else - self - end + else + self + end relation = relation.offset(index) unless index.zero? relation.limit(limit).to_a @@ -561,9 +561,9 @@ module ActiveRecord else relation = if order_values.empty? && primary_key order(arel_attribute(primary_key).asc) - else - self - end + else + self + end relation.to_a[-index] # TODO: can be made more performant on large result sets by diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index c0764fc4ab..a19913f2a8 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -78,9 +78,9 @@ module ActiveRecord def fixtures_path @fixtures_path ||= if ENV["FIXTURES_PATH"] File.join(root, ENV["FIXTURES_PATH"]) - else - File.join(root, "test", "fixtures") - end + else + File.join(root, "test", "fixtures") + end end def root diff --git a/activerecord/test/cases/column_alias_test.rb b/activerecord/test/cases/column_alias_test.rb index ae64c99f33..9893ba9580 100644 --- a/activerecord/test/cases/column_alias_test.rb +++ b/activerecord/test/cases/column_alias_test.rb @@ -6,9 +6,9 @@ class TestColumnAlias < ActiveRecord::TestCase QUERY = if "Oracle" == ActiveRecord::Base.connection.adapter_name "SELECT id AS pk FROM topics WHERE ROWNUM < 2" - else - "SELECT id AS pk FROM topics" - end + else + "SELECT id AS pk FROM topics" + end def test_column_alias records = Topic.connection.select_all(QUERY) diff --git a/activerecord/test/cases/migration/columns_test.rb b/activerecord/test/cases/migration/columns_test.rb index baf0a0eb9f..70d40ed87a 100644 --- a/activerecord/test/cases/migration/columns_test.rb +++ b/activerecord/test/cases/migration/columns_test.rb @@ -75,9 +75,10 @@ module ActiveRecord def test_rename_nonexistent_column exception = if current_adapter?(:PostgreSQLAdapter, :OracleAdapter) ActiveRecord::StatementInvalid - else - ActiveRecord::ActiveRecordError - end + else + ActiveRecord::ActiveRecordError + end + assert_raise(exception) do rename_column "test_models", "nonexistent", "should_fail" end diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 6404748fca..56413aa7b0 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -6,9 +6,10 @@ else customrc = ARGV.index{ |x| x.include?("--rc=") } railsrc = if customrc File.expand_path(ARGV.delete_at(customrc).gsub(/--rc=/, "")) - else - File.join(File.expand_path("~"), ".railsrc") - end + else + File.join(File.expand_path("~"), ".railsrc") + end + if File.exist?(railsrc) extra_args_string = File.read(railsrc) extra_args = extra_args_string.split(/\n+/).flat_map(&:split) diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index d69cbbc001..5d4acd6f6b 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -43,9 +43,9 @@ module Rails table << %(#{CGI.escapeHTML(name.to_s)}) formatted_value = if value.kind_of?(Array) "" - else - CGI.escapeHTML(value.to_s) - end + else + CGI.escapeHTML(value.to_s) + end table << %(#{formatted_value}) end table << "" diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 91ff7f4be7..4c157c1262 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -9,9 +9,9 @@ task :test do $: << "test" pattern = if ENV.key?("TEST") ENV["TEST"] - else - "test" - end + else + "test" + end Minitest.rake_run([pattern]) end