New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize indentation for generator actions #30166

Merged
merged 1 commit into from Aug 11, 2017

Conversation

Projects
None yet
4 participants
@yhirano55
Contributor

yhirano55 commented Aug 9, 2017

Summary

I've found that indentations are broken on environment method that is generator's one of actions.

Example template

environment "config.x.a = 1"
environment "config.x.b = 2"
environment do
  <<~RUBY
    config.x.c = 3
    config.x.d = 4
    config.x.e = 5
  RUBY
end

environment "config.x.a = 1", env: "development"
environment "config.x.b = 2", env: "development"
environment nil, env: "development" do
  <<~RUBY
    config.x.c = 3
    config.x.d = 4
    config.x.e = 5
  RUBY
end

Command

$ bin/rails app:template LOCATION=./template.rb

Before

It seems that it's not supported to be used on multiple lines.

$ git diff
diff --git a/config/application.rb b/config/application.rb
index f150d0f..41ae6f8 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -8,6 +8,12 @@ Bundler.require(*Rails.groups)

 module Foobar
   class Application < Rails::Application
+    config.x.c = 3
+config.x.d = 4
+config.x.e = 5
+
+    config.x.b = 2
+    config.x.a = 1
     # Initialize configuration defaults for originally generated Rails version.
     config.load_defaults 5.1

diff --git a/config/environments/development.rb b/config/environments/development.rb
index 2c15c69..f6b467c 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -1,4 +1,10 @@
 Rails.application.configure do
+  config.x.c = 3
+config.x.d = 4
+config.x.e = 5
+
+  config.x.b = 2
+  config.x.a = 1
   # Settings specified here will take precedence over those in config/application.rb.

   # In the development environment your application's code is reloaded on

After

$ git diff
diff --git a/config/application.rb b/config/application.rb
index f150d0f..2254e12 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -8,6 +8,11 @@ Bundler.require(*Rails.groups)

 module Foobar
   class Application < Rails::Application
+    config.x.c = 3
+    config.x.d = 4
+    config.x.e = 5
+    config.x.b = 2
+    config.x.a = 1
     # Initialize configuration defaults for originally generated Rails version.
     config.load_defaults 5.1

diff --git a/config/environments/development.rb b/config/environments/development.rb
index 2c15c69..bf1d891 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -1,4 +1,9 @@
 Rails.application.configure do
+  config.x.c = 3
+  config.x.d = 4
+  config.x.e = 5
+  config.x.b = 2
+  config.x.a = 1
   # Settings specified here will take precedence over those in config/application.rb.

   # In the development environment your application's code is reloaded on

Other Information

This is my use case.

application do
  <<~RUBY
    config.encoding  = "utf-8"
    config.time_zone = "UTC"
    config.active_record.default_timezone = :utc
    config.autoload_paths   += %W(\#{config.root}/lib)
    config.eager_load_paths += %W(\#{config.root}/lib)
  RUBY
end
@rails-bot

This comment has been minimized.

rails-bot commented Aug 9, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@yhirano55 yhirano55 changed the title from Fix environment method of generator actions to Optimize indentation for generator actions Aug 11, 2017

@rafaelfranca rafaelfranca merged commit 8bf0967 into rails:master Aug 11, 2017

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

rafaelfranca added a commit that referenced this pull request Aug 11, 2017

Merge pull request #30166 from yhirano55/fix_generator_method_environ…
…ment

Optimize indentation for generator actions

@yhirano55 yhirano55 deleted the yhirano55:fix_generator_method_environment branch Apr 6, 2018

ricardotk002 added a commit to ricardotk002/webpacker that referenced this pull request Apr 30, 2018

Replace #optimize_indentation calls with String#indent
In rails#1445 I introduced the
method `#optimize_indentation`, but this was added in Rails 5.2
(rails/rails#30166) and Webpacker should
support Rails 4+.

In order to have the same benefit, I'm replacing the calls to the
method `#optimize_indentation` with `String#indent`, which is what the
original method uses.

ricardotk002 added a commit to ricardotk002/webpacker that referenced this pull request Apr 30, 2018

Replace #optimize_indentation calls with String#indent
In rails#1445 I introduced the
method `#optimize_indentation`, but this was added in Rails 5.2
(rails/rails#30166) and Webpacker should
support Rails 4+.

In order to have the same benefit, I'm replacing the calls to the
method `#optimize_indentation` with the method it uses from behind:
`String#indent`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment