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'
|
- 'features/step_definitions/rails_steps.rb'
|
||||||
- 'lib/generators/factory_bot/model/model_generator.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
|
# Offense count: 11
|
||||||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
||||||
# URISchemes: http, https
|
# URISchemes: http, https
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
require 'rails/generators/named_base'
|
require "rails/generators/named_base"
|
||||||
|
|
||||||
module FactoryBot
|
module FactoryBot
|
||||||
module Generators
|
module Generators
|
||||||
class Base < Rails::Generators::NamedBase #:nodoc:
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
||||||
def self.source_root
|
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
|
end
|
||||||
|
|
||||||
def explicit_class_option
|
def explicit_class_option
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'generators/factory_bot'
|
require "generators/factory_bot"
|
||||||
require 'factory_bot_rails'
|
require "factory_bot_rails"
|
||||||
|
|
||||||
module FactoryBot
|
module FactoryBot
|
||||||
module Generators
|
module Generators
|
||||||
|
@ -8,21 +8,21 @@ module FactoryBot
|
||||||
:attributes,
|
:attributes,
|
||||||
type: :array,
|
type: :array,
|
||||||
default: [],
|
default: [],
|
||||||
banner: "field:type field:type"
|
banner: "field:type field:type",
|
||||||
)
|
)
|
||||||
|
|
||||||
class_option(
|
class_option(
|
||||||
:dir,
|
:dir,
|
||||||
type: :string,
|
type: :string,
|
||||||
default: "test/factories",
|
default: "test/factories",
|
||||||
desc: "The directory or file root where factories belong"
|
desc: "The directory or file root where factories belong",
|
||||||
)
|
)
|
||||||
|
|
||||||
class_option(
|
class_option(
|
||||||
:suffix,
|
:suffix,
|
||||||
type: :string,
|
type: :string,
|
||||||
default: nil,
|
default: nil,
|
||||||
desc: "Suffix to add factory file"
|
desc: "Suffix to add factory file",
|
||||||
)
|
)
|
||||||
|
|
||||||
def create_fixture_file
|
def create_fixture_file
|
||||||
|
@ -43,7 +43,7 @@ module FactoryBot
|
||||||
insert_into_file(
|
insert_into_file(
|
||||||
factories_file,
|
factories_file,
|
||||||
factory_definition,
|
factory_definition,
|
||||||
after: "FactoryBot.define do\n"
|
after: "FactoryBot.define do\n",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ module FactoryBot
|
||||||
def factory_definition
|
def factory_definition
|
||||||
<<-RUBY
|
<<-RUBY
|
||||||
factory :#{singular_table_name}#{explicit_class_option} do
|
factory :#{singular_table_name}#{explicit_class_option} do
|
||||||
#{factory_attributes.gsub(/^/, " ")}
|
#{factory_attributes.gsub(/^/, ' ')}
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
@ -78,7 +78,7 @@ RUBY
|
||||||
if factory_bot_options[:filename_proc].present?
|
if factory_bot_options[:filename_proc].present?
|
||||||
factory_bot_options[:filename_proc].call(table_name)
|
factory_bot_options[:filename_proc].call(table_name)
|
||||||
else
|
else
|
||||||
[table_name, filename_suffix].compact.join('_')
|
[table_name, filename_suffix].compact.join("_")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue