Skip to content

Commit

Permalink
Change FactoryBot/AssociationStyle, `FactoryBot/AttributeDefinedSta…
Browse files Browse the repository at this point in the history
…tically`, `FactoryBot/CreateList` and `FactoryBot/FactoryClassName` to work with minitest style directory

Fix: #53
  • Loading branch information
ydah committed Sep 7, 2023
1 parent c03fe9f commit 23716aa
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix `FactoryBot/AssociationStyle` cop to ignore explicit associations with `strategy: :build`. ([@pirj])
- Change `FactoryBot/CreateList` so that it is not an offense if not repeated multiple times. ([@ydah])
- Fix a false positive for `FactoryBot/AssociationStyle` when `association` is called in trait block and column name is keyword. ([@ydah])
- Change `FactoryBot/AssociationStyle`, `FactoryBot/AttributeDefinedStatically`, `FactoryBot/CreateList` and `FactoryBot/FactoryClassName` to work with minitest style directory. ([@ydah])

## 2.23.1 (2023-05-15)

Expand Down
51 changes: 33 additions & 18 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
FactoryBot:
Enabled: true
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/spec/factories.rb"
- "**/spec/factories/**/*.rb"
- "**/test/factories.rb"
- "**/test/factories/**/*.rb"
- "**/features/support/factories/**/*.rb"
DocumentationBaseURL: https://docs.rubocop.org/rubocop-factory_bot

FactoryBot/AssociationStyle:
Description: Use a consistent style to define associations.
Enabled: pending
Safe: false
Include:
- spec/factories.rb
- spec/factories/**/*.rb
- features/support/factories/**/*.rb
VersionAdded: '2.23'
VersionChanged: "<<next>>"
EnforcedStyle: implicit
SupportedStyles:
- explicit
Expand All @@ -27,17 +25,18 @@ FactoryBot/AssociationStyle:
FactoryBot/AttributeDefinedStatically:
Description: Always declare attribute values as blocks.
Enabled: true
Include:
- spec/factories.rb
- spec/factories/**/*.rb
- features/support/factories/**/*.rb
VersionAdded: '1.28'
VersionChanged: '2.0'
VersionChanged: "<<next>>"
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/AttributeDefinedStatically

FactoryBot/ConsistentParenthesesStyle:
Description: Use a consistent style for parentheses in factory_bot calls.
Enabled: pending
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/features/support/factories/**/*.rb"
EnforcedStyle: require_parentheses
SupportedStyles:
- require_parentheses
Expand All @@ -62,30 +61,36 @@ FactoryBot/CreateList:
ExplicitOnly: false
SafeAutoCorrect: false
VersionAdded: '1.25'
VersionChanged: '2.23'
VersionChanged: "<<next>>"
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/CreateList

FactoryBot/FactoryAssociationWithStrategy:
Description: Use definition in factory association instead of hard coding a strategy.
Enabled: pending
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/features/support/factories/**/*.rb"
VersionAdded: '2.23'
VersionChanged: '2.23'
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/FactoryAssociationWithStrategy

FactoryBot/FactoryClassName:
Description: Use string value when setting the class attribute explicitly.
Enabled: true
Include:
- spec/factories.rb
- spec/factories/**/*.rb
- features/support/factories/**/*.rb
VersionAdded: '1.37'
VersionChanged: '2.0'
VersionChanged: "<<next>>"
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/FactoryClassName

FactoryBot/FactoryNameStyle:
Description: Checks for name style for argument of FactoryBot::Syntax::Methods.
Enabled: pending
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/features/support/factories/**/*.rb"
EnforcedStyle: symbol
SupportedStyles:
- symbol
Expand All @@ -98,12 +103,22 @@ FactoryBot/FactoryNameStyle:
FactoryBot/RedundantFactoryOption:
Description: Checks for redundant `factory` option.
Enabled: pending
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/features/support/factories/**/*.rb"
VersionAdded: '2.23'
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/RedundantFactoryOption

FactoryBot/SyntaxMethods:
Description: Use shorthands from `FactoryBot::Syntax::Methods` in your specs.
Enabled: pending
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/features/support/factories/**/*.rb"
SafeAutoCorrect: false
VersionAdded: '2.7'
Reference: https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/SyntaxMethods
70 changes: 42 additions & 28 deletions docs/modules/ROOT/pages/cops_factorybot.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| No
| Yes (Unsafe)
| 2.23
| -
| <<next>>
|===

Use a consistent style to define associations.
Expand Down Expand Up @@ -86,10 +86,6 @@ end
|===
| Name | Default value | Configurable values

| Include
| `spec/factories.rb`, `+spec/factories/**/*.rb+`, `+features/support/factories/**/*.rb+`
| Array

| EnforcedStyle
| `implicit`
| `explicit`, `implicit`
Expand All @@ -112,7 +108,7 @@ end
| Yes
| Yes
| 1.28
| 2.0
| <<next>>
|===

Always declare attribute values as blocks.
Expand Down Expand Up @@ -140,16 +136,6 @@ count 1
count { 1 }
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| Include
| `spec/factories.rb`, `+spec/factories/**/*.rb+`, `+features/support/factories/**/*.rb+`
| Array
|===

=== References

* https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/AttributeDefinedStatically
Expand Down Expand Up @@ -239,6 +225,10 @@ build :user
|===
| Name | Default value | Configurable values

| Include
| `+**/*_spec.rb+`, `+**/spec/**/*+`, `+**/test/**/*+`, `+**/features/support/factories/**/*.rb+`
| Array

| EnforcedStyle
| `require_parentheses`
| `require_parentheses`, `omit_parentheses`
Expand All @@ -261,7 +251,7 @@ build :user
| Yes
| Yes (Unsafe)
| 1.25
| 2.23
| <<next>>
|===

Checks for create_list usage.
Expand Down Expand Up @@ -397,6 +387,16 @@ factory :foo do
end
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| Include
| `+**/*_spec.rb+`, `+**/spec/**/*+`, `+**/test/**/*+`, `+**/features/support/factories/**/*.rb+`
| Array
|===

=== References

* https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/FactoryAssociationWithStrategy
Expand All @@ -410,7 +410,7 @@ end
| Yes
| Yes
| 1.37
| 2.0
| <<next>>
|===

Use string value when setting the class attribute explicitly.
Expand All @@ -433,16 +433,6 @@ factory :foo, class: 'Foo' do
end
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| Include
| `spec/factories.rb`, `+spec/factories/**/*.rb+`, `+features/support/factories/**/*.rb+`
| Array
|===

=== References

* https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/FactoryClassName
Expand Down Expand Up @@ -522,6 +512,10 @@ create(:user)
|===
| Name | Default value | Configurable values

| Include
| `+**/*_spec.rb+`, `+**/spec/**/*+`, `+**/test/**/*+`, `+**/features/support/factories/**/*.rb+`
| Array

| EnforcedStyle
| `symbol`
| `symbol`, `string`
Expand Down Expand Up @@ -560,6 +554,16 @@ association :user, factory: :user
association :user
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| Include
| `+**/*_spec.rb+`, `+**/spec/**/*+`, `+**/test/**/*+`, `+**/features/support/factories/**/*.rb+`
| Array
|===

=== References

* https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/RedundantFactoryOption
Expand Down Expand Up @@ -623,6 +627,16 @@ build(:bar)
attributes_for(:bar)
----

=== Configurable attributes

|===
| Name | Default value | Configurable values

| Include
| `+**/*_spec.rb+`, `+**/spec/**/*+`, `+**/test/**/*+`, `+**/features/support/factories/**/*.rb+`
| Array
|===

=== References

* https://www.rubydoc.info/gems/rubocop-factory_bot/RuboCop/Cop/FactoryBot/SyntaxMethods

0 comments on commit 23716aa

Please sign in to comment.