Skip to content

Commit

Permalink
Merge pull request #55 from rubocop/ydah/fix/53
Browse files Browse the repository at this point in the history
Change `FactoryBot/AssociationStyle`, `FactoryBot/AttributeDefinedStatically`, `FactoryBot/CreateList` and `FactoryBot/FactoryClassName` to work with minitest style directory
  • Loading branch information
ydah authored Sep 8, 2023
2 parents ec937ec + 4ce5025 commit 13e3d14
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- 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])
- Fix a false positive for `FactoryBot/AssociationStyle` when `EnforcedStyle: Explicit` and using trait within trait. ([@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
56 changes: 35 additions & 21 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 @@ -53,40 +52,45 @@ FactoryBot/CreateList:
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- spec/factories.rb
- spec/factories/**/*.rb
- features/support/factories/**/*.rb
- "**/test/**/*"
- "**/features/support/factories/**/*.rb"
EnforcedStyle: create_list
SupportedStyles:
- create_list
- n_times
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 @@ -99,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
72 changes: 43 additions & 29 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 @@ -342,7 +332,7 @@ create_list :user, 3
| Name | Default value | Configurable values

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

| EnforcedStyle
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
7 changes: 3 additions & 4 deletions docs/modules/ROOT/pages/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ RuboCop::RakeTask.new do |task|
end
----

== Inspecting files that don't end with `_spec.rb`
== Inspecting non-default file paths

By default, `rubocop-factory_bot` only inspects code within below:

[source,yaml]
----
FactoryBot:
Include:
- "**/*_spec.rb"
- "**/spec/**/*"
- "**/test/**/*"
- "**/spec/factories.rb"
- "**/spec/factories/**/*.rb"
- "**/test/factories.rb"
- "**/test/factories/**/*.rb"
- "**/features/support/factories/**/*.rb"
----

Expand Down

0 comments on commit 13e3d14

Please sign in to comment.