-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Cop Idea: Controller Action Order #540
Comments
I'd suggest first opening a PR to add this to https://github.com/rubocop/rails-style-guide, and then adding it here if there's consensus. |
Even though (https://docs.rubocop.org/rubocop-rails/):
and (https://docs.rubocop.org/rubocop/1.20/index.html#overview):
https://docs.rubocop.org/rubocop/1.20/index.html#philosophy
Having such a cop would be nice. I'd suggest using https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cop/layout/class_structure.rb as a reference and make the cop configurable and flexible to meet other styles. |
+1 for a cop with a configurable order. |
All I need is a go from a core member that the cop would be merged, and I'll make a PR😊 |
I'm in favour of it as long as:
|
Go! |
I often see a method called |
Huh? Can you elaborate? I've never seen a "confirm" method in a controller? I'd suggest only ignoring private methods - I hope to influence people to only use the default methods: https://www.youtube.com/watch?v=HctYHe-YjnE |
Not just private methods, it should ignore any that aren't part of the standard 7, and should allow non-standard methods to exist before, after, or intermingled with the standard 7. |
I think that should be treated as a separate cop from the action ordering. |
Yeah, whether or not a controller "should" have non-restful actions, a large percentage of them do. This cop should not consider them at all. |
Let's see if I can convince the masters of the style guide rubocop/rails-style-guide#290 |
Commit 0ef065a introduced the Rails/ActionOrder cop to enforce the order of RESTful action methods in controllers. These actions also appear in routes configuration through the `resource` and `resources` methods (docs linked below). The cop should enforce the order for these actions as well. https://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Resources.html#method-i-resources Refs rubocop#540
Commit 0ef065a introduced the Rails/ActionOrder cop to enforce the order of RESTful action methods in controllers. These actions also appear in routes configuration through the `resource` and `resources` methods (docs linked below). The cop should enforce the order for these actions as well. https://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Resources.html#method-i-resources Refs rubocop#540
The default order of controller actions in rails scaffolds are:
index show new edit create update destroy
I often see controllers where this order is not followed. For consistency's sake, I'd like to have a cop to enforce this ordering of the public methods in my controllers.
The text was updated successfully, but these errors were encountered: