Skip to content

Commit

Permalink
Address todos generated by rubocop for files in the lib/generators di…
Browse files Browse the repository at this point in the history
…rectory (#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
  • Loading branch information
petestreet authored and composerinteralia committed Sep 29, 2018
1 parent 879b47f commit 7907b08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 73 deletions.
59 changes: 0 additions & 59 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/generators/factory_bot/model/model_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'generators/factory_bot'
require 'factory_bot_rails'
require "generators/factory_bot"
require "factory_bot_rails"

module FactoryBot
module Generators
Expand All @@ -8,21 +8,21 @@ class ModelGenerator < Base
: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
Expand All @@ -43,7 +43,7 @@ def insert_factory_into_existing_file
insert_into_file(
factories_file,
factory_definition,
after: "FactoryBot.define do\n"
after: "FactoryBot.define do\n",
)
end

Expand All @@ -53,19 +53,19 @@ def create_factory_file
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
Expand All @@ -78,7 +78,7 @@ def filename
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

Expand Down

0 comments on commit 7907b08

Please sign in to comment.