Skip to content
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

Apply autocorrection by RuboCop to files generated by bin/rails generate #50506

Merged
merged 5 commits into from Jan 1, 2024

Conversation

koic
Copy link
Contributor

@koic koic commented Dec 31, 2023

Motivation / Background

RuboCop has now been included by default (#50456). By adding the following tip to the default configuration, user can apply RuboCop's autocorrection to code generated by bin/rails generate (e.g., migration file):

https://github.com/rubocop/rubocop-rails#rails-configuration-tip

This means that the generated files will be formatted according to user's .rubocop.yml custom configuration.

Detail

Since bin/rails generate and bin/rubocop are used only in the development environment, the target files are limited to only config/environments/development.rb.

Additional information

This feature was introduced in Rails 6.1 by #38870.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the railties label Dec 31, 2023
@dhh
Copy link
Member

dhh commented Dec 31, 2023

Love the concept, but would like if we could package up the code needed to accomplish this. There's a little too much logic code to have in the config file.

…rate`

## Motivation / Background

RuboCop has now been included by default (rails#50456).
By adding the following tip to the default configuration, user can apply RuboCop's autocorrection to
code generated by `bin/rails generate` (e.g., migration file):

https://github.com/rubocop/rubocop-rails#rails-configuration-tip

This means that the generated files will be formatted according to user's .rubocop.yml custom configuration.

## Detail

Since `bin/rails generate` and `bin/rubocop` are used only in the development environment,
the target files are limited to only `config/environments/development.rb`.

## Additional information

This feature was introduced in Rails 6.1 by rails#38870.
@koic koic force-pushed the add_after_generate_to_development_template branch from 85c1ca9 to 5409a89 Compare December 31, 2023 18:36
@koic
Copy link
Contributor Author

koic commented Dec 31, 2023

Sure! I have packaged it as config.generators.apply_autocorrect_after_generate!. Of course, there might be a better name for it.

dhh and others added 4 commits January 1, 2024 01:26
* main:
  Add brakeman as development dependency
  Fix skipped rubocop test typo (rails#50519)
  Update the puma startup message
  docs: remove unneeded whitespace from start of code blocks
  Add changelog entry for rails#50512
  Add step to keep screenshots of failed system tests
  Fix name casing
  ✂️ cut trailing whitespace
  Switch to headless chrome by default (rails#50512)
  Fix generator output paths
  New default files
  Errant debug puts
  Add changelog entry for rails#50505 [ci skip] (rails#50513)
  Default to creating GitHub CI files (rails#50508)
  Remove unnecessary require
  Fix railspect not validating alphabetical order
@dhh dhh merged commit 581074c into rails:main Jan 1, 2024
1 check failed
@koic koic deleted the add_after_generate_to_development_template branch January 1, 2024 20:35
dhh added a commit to skipkayhil/rails that referenced this pull request Jan 2, 2024
* main:
  Add a default yield :head to layouts/application.html.erb (rails#50527)
  Switch to new enum syntax in example code [ci-skip]
  Utilize new enum syntax
  Apply autocorrection by RuboCop to files generated by `bin/rails generate` (rails#50506)
  Add brakeman as development dependency
  Fix skipped rubocop test typo (rails#50519)
  Update the puma startup message
  docs: remove unneeded whitespace from start of code blocks
  Add changelog entry for rails#50512
  Remove unnecessary require
  Fix railspect not validating alphabetical order
@andyw8
Copy link
Contributor

andyw8 commented Apr 28, 2024

@koic It may be necessary to use ruby bin/rubocop for Windows compatibility, see the comment here.

@andyw8
Copy link
Contributor

andyw8 commented May 1, 2024

#51618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants