From 4ce50258ceeaa4585a1c1dc52e9b13a16c206236 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Fri, 8 Sep 2023 07:35:40 +0900 Subject: [PATCH] Change `FactoryBot/AssociationStyle`, `FactoryBot/AttributeDefinedStatically`, `FactoryBot/CreateList` and `FactoryBot/FactoryClassName` to work with minitest style directory Fix: https://github.com/rubocop/rubocop-factory_bot/issues/53 --- CHANGELOG.md | 1 + config/default.yml | 56 +++++++++------ docs/modules/ROOT/pages/cops_factorybot.adoc | 72 ++++++++++++-------- docs/modules/ROOT/pages/usage.adoc | 7 +- 4 files changed, 82 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b18102f5..9954eb1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/config/default.yml b/config/default.yml index 7337df7e..ba0dc931 100644 --- a/config/default.yml +++ b/config/default.yml @@ -2,9 +2,10 @@ 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 @@ -12,11 +13,8 @@ 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: "<>" EnforcedStyle: implicit SupportedStyles: - explicit @@ -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: "<>" 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 @@ -53,9 +52,8 @@ 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 @@ -63,12 +61,17 @@ FactoryBot/CreateList: ExplicitOnly: false SafeAutoCorrect: false VersionAdded: '1.25' - VersionChanged: '2.23' + VersionChanged: "<>" 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 @@ -76,17 +79,18 @@ 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: "<>" 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 @@ -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 diff --git a/docs/modules/ROOT/pages/cops_factorybot.adoc b/docs/modules/ROOT/pages/cops_factorybot.adoc index 54bf6ec7..cce5509d 100644 --- a/docs/modules/ROOT/pages/cops_factorybot.adoc +++ b/docs/modules/ROOT/pages/cops_factorybot.adoc @@ -9,7 +9,7 @@ | No | Yes (Unsafe) | 2.23 -| - +| <> |=== Use a consistent style to define associations. @@ -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` @@ -112,7 +108,7 @@ end | Yes | Yes | 1.28 -| 2.0 +| <> |=== Always declare attribute values as blocks. @@ -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 @@ -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` @@ -261,7 +251,7 @@ build :user | Yes | Yes (Unsafe) | 1.25 -| 2.23 +| <> |=== Checks for create_list usage. @@ -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 @@ -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 @@ -410,7 +410,7 @@ end | Yes | Yes | 1.37 -| 2.0 +| <> |=== Use string value when setting the class attribute explicitly. @@ -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 @@ -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` @@ -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 @@ -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 diff --git a/docs/modules/ROOT/pages/usage.adoc b/docs/modules/ROOT/pages/usage.adoc index cb09198f..244a8a0b 100644 --- a/docs/modules/ROOT/pages/usage.adoc +++ b/docs/modules/ROOT/pages/usage.adoc @@ -38,7 +38,7 @@ 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: @@ -46,11 +46,10 @@ By default, `rubocop-factory_bot` only inspects code within below: ---- FactoryBot: Include: - - "**/*_spec.rb" - - "**/spec/**/*" - - "**/test/**/*" - "**/spec/factories.rb" - "**/spec/factories/**/*.rb" + - "**/test/factories.rb" + - "**/test/factories/**/*.rb" - "**/features/support/factories/**/*.rb" ----