-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add new Rails/ZeitwerkFriendlyConstant cop. #748
Conversation
This cop is extrcted from Shopify's internal Rubocop repository. Many thanks to the original authors for their work. Co-authored-by: Edouard CHIN <[email protected]> Co-authored-by: Chris Salzberg <[email protected]>
Rails comes with a |
I didn't know about that task, thanks for sharing. Looking at the code I can see one use case it doesn't provide: a gradual adoption approach using the Rubocop TODO file. Alternatively the Rails rake task could use ActiveSupport::Deprecation so that things like Deprecation Toolkit could provide a similar way to disallow new bad examples being introduced while the existing code is being switched over component by component. It is not practical to switch over a very large code base in a single change - but I can also appreciate not everybody having that problem :) |
While this is true, I'm not sure if it's of a lot of value. Zeitwerk is the default on Rails 6 and the only option on Rails 7, which means it's required to fix anything that Zeitwerk would complain about if you're upgrading to 7, or do not enable classic mode for the autoload, or else your app will just not boot. Therefore I imagine you are using this as a way to transition to using Zeitwerk. I'm still not sure I'd do it in RuboCop, but perhaps leverage zeitwerk itself to create a code loading report that you could treat as a todo file. Doing static analysis is always going to be less ideal here, IMO. Of course, since you already have an in-house cop for this, nothing is stopping you from using it if this is not accepted 😄 |
I agree with @dvandersluis's opinion and here is an interesting tweet I've seen recently: Perhaps CI check using the Zweitwerk official |
I'll close this PR because @dvandersluis opinion seems reasonable. Thank you. |
This is useful for us. We have a pretty large application, so we'd like to migrate in chunks while prohibiting people from adding broken code. |
@bdewater Thanks for this. It has already been useful to quantify the naming issues in our monolith and delegate the work to fix them. |
@koic @dvandersluis I believe this should be re-opened. In addition to the above comments, # models/foo.rb
module Foo
end
module Bar
end which has this load order bug:
|
See rubocop/rails-style-guide#323
This cop is extracted from Shopify's internal Rubocop repository. Many thanks to the original authors for their work.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.