mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
Address todos generated by rubocop for files in the lib/generators directory (#299)
* Address todos generated by rubocop for files in the lib/generators directory. This partially addresses #293. Since rubocop generated quite a few todos, the commits addressing them are split up into a few different PRs that cover different files. * Fix underscore seperator in model_generator.rb, and change memoized instance variable name to @_source_root in lib/generators/factory_bot.rb * get rid of memoized _source_root variable * get rid of extraneous rubocop rules
This commit is contained in:
parent
879b47f70d
commit
7907b085fd
3 changed files with 14 additions and 73 deletions
59
.rubocop.yml
59
.rubocop.yml
|
@ -27,65 +27,6 @@ Layout/IndentHeredoc:
|
|||
- 'features/step_definitions/rails_steps.rb'
|
||||
- 'lib/generators/factory_bot/model/model_generator.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: Width, IgnoredPatterns.
|
||||
Layout/IndentationWidth:
|
||||
Exclude:
|
||||
- 'lib/generators/factory_bot/model/model_generator.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: CountComments, ExcludedMethods.
|
||||
Metrics/BlockLength:
|
||||
Max: 40
|
||||
|
||||
# Offense count: 1
|
||||
Naming/MemoizedInstanceVariableName:
|
||||
Exclude:
|
||||
- 'lib/generators/factory_bot.rb'
|
||||
|
||||
# Offense count: 9
|
||||
Style/Documentation:
|
||||
Exclude:
|
||||
- 'spec/**/*'
|
||||
- 'test/**/*'
|
||||
- 'lib/generators/factory_bot/model/model_generator.rb'
|
||||
|
||||
# Offense count: 84
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
||||
# SupportedStyles: single_quotes, double_quotes
|
||||
Style/StringLiterals:
|
||||
EnforcedStyle: "double_quotes"
|
||||
Exclude:
|
||||
- 'lib/generators/factory_bot.rb'
|
||||
- 'lib/generators/factory_bot/model/model_generator.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: single_quotes, double_quotes
|
||||
Style/StringLiteralsInInterpolation:
|
||||
Exclude:
|
||||
- 'lib/generators/factory_bot/model/model_generator.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyleForMultiline.
|
||||
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
|
||||
Style/TrailingCommaInArguments:
|
||||
Exclude:
|
||||
- 'spec/factory_bot_rails/definition_file_paths_spec.rb'
|
||||
- 'lib/generators/factory_bot/model/model_generator.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: WordRegex.
|
||||
# SupportedStyles: percent, brackets
|
||||
Style/WordArray:
|
||||
EnforcedStyle: percent
|
||||
MinSize: 3
|
||||
|
||||
# Offense count: 11
|
||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||
# URISchemes: http, https
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'rails/generators/named_base'
|
||||
require "rails/generators/named_base"
|
||||
|
||||
module FactoryBot
|
||||
module Generators
|
||||
class Base < Rails::Generators::NamedBase #:nodoc:
|
||||
def self.source_root
|
||||
@_factory_bot_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'factory_bot', generator_name, 'templates'))
|
||||
File.expand_path(File.join(File.dirname(__FILE__), "factory_bot", generator_name, "templates"))
|
||||
end
|
||||
|
||||
def explicit_class_option
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'generators/factory_bot'
|
||||
require 'factory_bot_rails'
|
||||
require "generators/factory_bot"
|
||||
require "factory_bot_rails"
|
||||
|
||||
module FactoryBot
|
||||
module Generators
|
||||
|
@ -8,21 +8,21 @@ module FactoryBot
|
|||
:attributes,
|
||||
type: :array,
|
||||
default: [],
|
||||
banner: "field:type field:type"
|
||||
banner: "field:type field:type",
|
||||
)
|
||||
|
||||
class_option(
|
||||
:dir,
|
||||
type: :string,
|
||||
default: "test/factories",
|
||||
desc: "The directory or file root where factories belong"
|
||||
desc: "The directory or file root where factories belong",
|
||||
)
|
||||
|
||||
class_option(
|
||||
:suffix,
|
||||
type: :string,
|
||||
default: nil,
|
||||
desc: "Suffix to add factory file"
|
||||
desc: "Suffix to add factory file",
|
||||
)
|
||||
|
||||
def create_fixture_file
|
||||
|
@ -43,7 +43,7 @@ module FactoryBot
|
|||
insert_into_file(
|
||||
factories_file,
|
||||
factory_definition,
|
||||
after: "FactoryBot.define do\n"
|
||||
after: "FactoryBot.define do\n",
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -53,19 +53,19 @@ module FactoryBot
|
|||
end
|
||||
|
||||
def factory_definition
|
||||
<<-RUBY
|
||||
<<-RUBY
|
||||
factory :#{singular_table_name}#{explicit_class_option} do
|
||||
#{factory_attributes.gsub(/^/, " ")}
|
||||
#{factory_attributes.gsub(/^/, ' ')}
|
||||
end
|
||||
RUBY
|
||||
RUBY
|
||||
end
|
||||
|
||||
def single_file_factory_definition
|
||||
<<-RUBY
|
||||
<<-RUBY
|
||||
FactoryBot.define do
|
||||
#{factory_definition.chomp}
|
||||
end
|
||||
RUBY
|
||||
RUBY
|
||||
end
|
||||
|
||||
def factory_attributes
|
||||
|
@ -78,7 +78,7 @@ RUBY
|
|||
if factory_bot_options[:filename_proc].present?
|
||||
factory_bot_options[:filename_proc].call(table_name)
|
||||
else
|
||||
[table_name, filename_suffix].compact.join('_')
|
||||
[table_name, filename_suffix].compact.join("_")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue