-
Notifications
You must be signed in to change notification settings - Fork 16
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 RuboCop cop to enforce no strict loading model or association config #69
Add RuboCop cop to enforce no strict loading model or association config #69
Conversation
* Add ByDefaultForModels to ensure models do not set self.strict_loading_by_default. * Add ForAssociations to ensure model associations do not set :strict_loading option. The purpose of this cop is to make sure to highlight any places where we explicitly set strict loading, as opposed to relyong on global settings. The idea will be to capture all the offenses in a .rubocop_todo.yml so we can burn down and fix all the cases over time.
4e4c855
to
2c2ad8a
Compare
@@ -8,7 +8,7 @@ jobs: | |||
strategy: | |||
fail-fast: false | |||
matrix: | |||
ruby: [3.0, 3.1, 3.2] | |||
ruby: ['3.0', 3.1, 3.2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: This fixes a known issue with GitHub Actions.
0f03e68
to
766f0db
Compare
766f0db
to
2f6406c
Compare
b52b739
to
85bf96c
Compare
expect_offense(<<~RUBY) | ||
class MyModel < ApplicationRecord | ||
has_many :posts, # preserve this comment | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not set `:strict_loading` in ActiveRecord associations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: This was a bit annoying that I couldn't figure out how to make it also highlight the actual option on the next line. However, I feel it's probably "close enough" that anyone could figure out that the problem is associated with this specific has_many
call.
For this cop to work the auto-correct is not strictly required; and I should note the autocorrect does work in this case, the problem is mostly wrt what parts are highlighted, which is a secondary concern.
Should we register these cops in |
85bf96c
to
0e4c372
Compare
comment: I saw somewhere that you can define |
0e4c372
to
5b8549f
Compare
comment: For now I've defined |
5b8549f
to
83f65df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain lgtm
ba41a48
to
ce87479
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain LGTM && platform LGTM - thanks for the README update!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain LGTM!
Summary
Description
This branch adds two cops to ensure models and associations don't have strict loading configuration.